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

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

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    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, "c:\\cdata");
27        SClass[] cl = qpg.getClasses(null);
28        Path[] path = qpg.getPaths(sc, ec, false);
29        System.out.println(path.length);
30    }
31   
32    public QueryPathGenerator(){
33        factory = new RDFSchemaAnalyzerFactory();
34    }
35   
36    public QueryPathGenerator(String sparqlEndpoint, String crawlFileName){
37        factory = new RDFSchemaAnalyzerFactory(crawlFileName);
38        setSPARQLendpoint(sparqlEndpoint);
39        try{
40           factory.setAcqiredRDFFiles("cdata/");
41        }catch(Exception e){
42            System.err.println(e);
43        }
44    }
45   
46    public SClass[] getClasses(String keyword){
47        String[] keywords = null;
48        if ( keyword != null ){
49            if ( keyword.length() != 0 ){
50                keywords = new String[1];
51                keywords[0] = keyword;
52            }
53        }
54        try {
55            return analyzer.getOWLClasses(null, keywords, null, false);
56        }catch(Exception e){
57            System.err.println(e);
58            return null;
59        }
60    }
61   
62    public Path[] getPaths(String startClass, String endClass, boolean countLink){
63        if ( analyzer == null ){
64            System.err.println("ERROR. SPARQL endpoint is not decided.");
65        }
66        OWLClassGraph graph = new OWLClassGraph(startClass, endClass);
67        return graph.getPaths(analyzer, countLink);
68    }
69   
70    private void setSPARQLendpoint(String sparqlEndpoint){
71        this.sparqlEndpoint = sparqlEndpoint;
72        setAnalyzer();
73    }
74
75    private void setAnalyzer(){
76        //analyzer = new EndpointAnalyzer(sparqlEndpoint); //ForTest
77       
78        try {
79            analyzer = factory.create(sparqlEndpoint);
80        } catch (Exception e) {
81            System.err.println(e);
82        }
83    }
84}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。