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

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

実験用main追加

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