root/SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/QueryPathGenerator.java @ 136

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

reactome でとりあえずは途中まで動くバージョン

行番号 
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
29        //String sp = "http://www.ebi.ac.uk/rdf/services/chembl/sparql";
30        //String sc = "http://rdf.ebi.ac.uk/terms/chembl#Enzyme";
31        //String ec = "http://rdf.ebi.ac.uk/terms/chembl#Activity";
32
33        String sp = "http://www.ebi.ac.uk/rdf/services/reactome/sparql";
34        //String sp = "http://www.ebi.ac.uk/rdf/services/biosamples/sparql";
35        //String sc = "http://rdf.ebi.ac.uk/terms/biosd/Sample";
36        //String ec = "http://purl.obolibrary.org/obo/NCBITaxon_7955";
37        //String sp = "http://www.ebi.ac.uk/rdf/services/biosamples/sparql";
38        //String sc = "http://rdf.ebi.ac.uk/terms/biosd/Sample";
39        //String ec = "http://purl.obolibrary.org/obo/NCBITaxon_7955";
40        //String sp = "http://lsd.dbcls.jp/sparql";
41        //String sc = "http://purl.jp/bio/10/lsd/ontology/201209#EnglishCode";
42        //String ec = "http://purl.jp/bio/10/lsd/ontology/201209#JapaneseCode";
43        //QueryPathGenerator qpg = new QueryPathGenerator(sp, "c:\\cdata");
44        QueryPathGenerator qpg1 = new QueryPathGenerator(sp, "cdata/");
45        String[] elist = qpg1.factory.getEndpointURIList();
46        qpg1.setSPARQLendpoint(sp);
47        SClass[] cl = qpg1.getClasses(null);
48        System.out.println("end");
49        /*
50        long start1 = System.currentTimeMillis();
51        Path[] path1 = qpg1.getPaths(sc, ec, false);
52        long end1 = System.currentTimeMillis();
53       
54        QueryPathGenerator qpg2 = new QueryPathGenerator(sp, "ddata/");
55        long start2 = System.currentTimeMillis();
56        Path[] path2 = qpg2.getPaths(sc, ec, false);
57        long end2 = System.currentTimeMillis();
58        System.out.println("TOTAL1:");
59        System.out.println(end1 - start1);
60        System.out.println("TOTAL2:");
61        System.out.println(end2 - start2);
62       
63        System.out.println(path1.length);
64        System.out.println(path2.length);
65                */
66    }
67   
68    public QueryPathGenerator(){
69        factory = new RDFSchemaAnalyzerFactory();
70    }
71   
72    public QueryPathGenerator(String sparqlEndpoint){
73        factory = new RDFSchemaAnalyzerFactory(CDIR);
74        setSPARQLendpoint(sparqlEndpoint);     
75    }
76
77    public QueryPathGenerator(String sparqlEndpoint, String crawlFileName){
78        factory = new RDFSchemaAnalyzerFactory(crawlFileName);
79        setSPARQLendpoint(sparqlEndpoint);
80    }
81   
82    public SClass[] getClasses(String keyword){
83        String[] keywords = null;
84        if ( keyword != null ){
85            if ( keyword.length() != 0 ){
86                keywords = new String[1];
87                keywords[0] = keyword;
88            }
89        }
90        try {
91            return analyzer.getOWLClasses(null, keywords, null, false);
92        }catch(Exception e){
93            System.err.println(e);
94            return null;
95        }
96    }
97   
98    public Path[] getPaths(String startClass, String endClass, boolean countLink){
99        if ( analyzer == null ){
100            System.err.println("ERROR. SPARQL endpoint is not decided.");
101        }
102        OWLClassGraph graph = new OWLClassGraph(startClass, endClass);
103        return graph.getPaths(analyzer, countLink);
104    }
105   
106    private void setSPARQLendpoint(String sparqlEndpoint){
107        this.sparqlEndpoint = sparqlEndpoint;
108        setAnalyzer();
109    }
110
111    private void setAnalyzer(){
112        //analyzer = new EndpointAnalyzer(sparqlEndpoint); //ForTest
113       
114        try {
115            analyzer = factory.create(sparqlEndpoint);
116        } catch (Exception e) {
117            System.err.println(e);
118        }
119    }
120}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。