root/BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/QueryPathGenerator.java @ 108

リビジョン 107, 2.5 KB (コミッタ: nori, 10 年 前)

コンストラクターを復元

行番号 
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7package org.biohackathon.SPARQLBuilder.OWL;
8
9/**
10 *
11 * @author atsuko
12 */
13
14public class QueryPathGenerator {
15    private String sparqlEndpoint = null;
16    private RDFSchemaAnalyzerFactory factory = null;
17    private RDFSchemaAnalyzer analyzer = null;
18    //private OWLClassGraph graph;
19
20    public static void main(String[] args){
21        // For Test
22        String sp = "http://data.allie.dbcls.jp/sparql";
23        String sc = "http://purl.org/allie/ontology/201108#ShortForm";
24        String ec = "http://purl.org/allie/ontology/201108#LongForm";
25        QueryPathGenerator qpg = new QueryPathGenerator(sp, "c:\\cdata");
26        SClass[] cl = qpg.getClasses(null);
27        Path[] path = qpg.getPaths(sc, ec, false);
28        System.out.println(path.length);
29    }
30   
31    public QueryPathGenerator(){
32        factory = new RDFSchemaAnalyzerFactory();
33    }
34   
35    public QueryPathGenerator(String sparqlEndpoint){
36        factory = new RDFSchemaAnalyzerFactory();
37        setSPARQLendpoint(sparqlEndpoint);
38    }
39   
40    public QueryPathGenerator(String sparqlEndpoint, String crawlFileName){
41        factory = new RDFSchemaAnalyzerFactory(crawlFileName);
42        setSPARQLendpoint(sparqlEndpoint);
43    }
44
45    public SClass[] getClasses(String keyword){
46        String[] keywords = null;
47        if ( keyword != null ){
48            if ( keyword.length() != 0 ){
49                keywords = new String[1];
50                keywords[0] = keyword;
51            }
52        }
53        try {
54            return analyzer.getOWLClasses(null, keywords, null, false);
55        }catch(Exception e){
56            System.err.println(e);
57            return null;
58        }
59    }
60   
61    public Path[] getPaths(String startClass, String endClass, boolean countLink){
62        if ( analyzer == null ){
63            System.err.println("ERROR. SPARQL endpoint is not decided.");
64        }
65        OWLClassGraph graph = new OWLClassGraph(startClass, endClass);
66        return graph.getPaths(analyzer, countLink);
67    }
68   
69    private void setSPARQLendpoint(String sparqlEndpoint){
70        this.sparqlEndpoint = sparqlEndpoint;
71        setAnalyzer();
72    }
73
74    private void setAnalyzer(){
75        //analyzer = new EndpointAnalyzer(sparqlEndpoint); //ForTest
76       
77        try {
78            analyzer = factory.create(sparqlEndpoint);
79        } catch (Exception e) {
80            System.err.println(e);
81        }
82    }
83}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。