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

リビジョン 90, 2.3 KB (コミッタ: atsuko, 10 年 前)

Latest version of OWLClassGraph.java

行番号 
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    /*
21    public static void main(String[] args){
22        // For Test
23        String sp = "http://data.allie.dbcls.jp/sparql";
24        String sc = "http://purl.org/allie/ontology/201108#ShortForm";
25        String ec = "http://purl.org/allie/ontology/201108#LongForm";
26        QueryPathGenerator qpg = new QueryPathGenerator(sp);
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 SClass[] getClasses(String keyword){
41        String[] keywords = null;
42        if ( keyword != null ){ // KOKO
43            keywords = new String[1];
44            keywords[0] = keyword;           
45        }
46        try {
47            return analyzer.getOWLClasses(null, keywords, sparqlEndpoint, false);
48        }catch(Exception e){
49            System.err.println(e);
50            return null;
51        }
52    }
53   
54    public Path[] getPaths(String startClass, String endClass, boolean countLink){
55        if ( analyzer == null ){
56            System.err.println("ERROR. SPARQL endpoint is not decided.");
57        }
58        OWLClassGraph graph = new OWLClassGraph(startClass, endClass);
59        return graph.getPaths(analyzer, countLink);
60    }
61   
62    private void setSPARQLendpoint(String sparqlEndpoint){
63        this.sparqlEndpoint = sparqlEndpoint;
64        setAnalyzer();
65    }
66
67    private void setAnalyzer(){
68        //analyzer = new EndpointAnalyzer(sparqlEndpoint); //ForTest
69        try {
70            analyzer = factory.create(sparqlEndpoint);
71        } catch (Exception e) {
72            System.err.println(e);
73        }
74    }
75}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。