| 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 | |
|---|
| 7 | package org.biohackathon.SPARQLBuilder.OWL; |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * |
|---|
| 11 | * @author atsuko |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | public class QueryPathGenerator { |
|---|
| 15 | private String sparqlEndpoint = null; |
|---|
| 16 | private RDFSchemaAnalyzerFactory factory = null; |
|---|
| 17 | private RDFSchemaAnalyzer analyzer = null; |
|---|
| 18 | //private OWLClassGraph graph; |
|---|
| 19 | |
|---|
| 20 | public static void main(String[] args){ |
|---|
| 21 | // For Test |
|---|
| 22 | String sp = "http://data.allie.dbcls.jp/sparql"; |
|---|
| 23 | String sc = "http://purl.org/allie/ontology/201108#ShortForm"; |
|---|
| 24 | String ec = "http://purl.org/allie/ontology/201108#LongForm"; |
|---|
| 25 | QueryPathGenerator qpg = new QueryPathGenerator(sp); |
|---|
| 26 | SClass[] cl = qpg.getClasses(null); |
|---|
| 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 | factory.setAcqiredRDFFiles("/cdata"); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public SClass[] getClasses(String keyword){ |
|---|
| 42 | String[] keywords = null; |
|---|
| 43 | if ( keyword != null ){ |
|---|
| 44 | if ( keyword.length() != 0 ){ |
|---|
| 45 | keywords = new String[1]; |
|---|
| 46 | keywords[0] = keyword; |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | try { |
|---|
| 50 | return analyzer.getOWLClasses(null, keywords, null, false); |
|---|
| 51 | }catch(Exception e){ |
|---|
| 52 | System.err.println(e); |
|---|
| 53 | return null; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public Path[] getPaths(String startClass, String endClass, boolean countLink){ |
|---|
| 58 | if ( analyzer == null ){ |
|---|
| 59 | System.err.println("ERROR. SPARQL endpoint is not decided."); |
|---|
| 60 | } |
|---|
| 61 | OWLClassGraph graph = new OWLClassGraph(startClass, endClass); |
|---|
| 62 | return graph.getPaths(analyzer, countLink); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | private void setSPARQLendpoint(String sparqlEndpoint){ |
|---|
| 66 | this.sparqlEndpoint = sparqlEndpoint; |
|---|
| 67 | setAnalyzer(); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | private void setAnalyzer(){ |
|---|
| 71 | //analyzer = new EndpointAnalyzer(sparqlEndpoint); //ForTest |
|---|
| 72 | |
|---|
| 73 | try { |
|---|
| 74 | analyzer = factory.create(sparqlEndpoint); |
|---|
| 75 | } catch (Exception e) { |
|---|
| 76 | System.err.println(e); |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | } |
|---|