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

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

GUIからの呼び出し用の QueryPathGenerator? コンストラクタ追加

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