- 更新日時:
- 2015/04/08 17:05:11 (10 年 前)
- パス:
- SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder
- ファイル:
-
- 5 変更
凡例:
- 変更なし
- 追加
- 削除
-
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/EndpointAccess.java
r248 r251 16 16 */ 17 17 public class EndpointAccess { 18 static public boolean checkPath(Path path, String sparqlEndpoint){ 19 return checkPath(path.getStartClass(), path.getClassLinks(), sparqlEndpoint); 20 } 21 18 22 static public boolean checkPath(String startClass, List<ClassLink> classlinks, String sparqlEndpoint){ 19 23 // SPARQL Query construction … … 45 49 String sparqlQuery = queryStr.toString(); 46 50 Query query = QueryFactory.create(sparqlQuery, Syntax.syntaxARQ); 47 /*48 QueryEngineHTTP httpQuery = new QueryEngineHTTP(sparqlEndpoint, query);49 boolean res = httpQuery.execAsk();50 httpQuery.close();51 */52 51 QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlEndpoint, query); 53 52 boolean res = qexec.execAsk(); … … 104 103 queryStr.append("ASK { \n"); 105 104 106 queryStr.append("?n1 ").append(" rdf:type <").append(ocg.labels.get(node1)).append(">.\n");107 queryStr.append("?n2 ").append(" rdf:type <").append(ocg.labels.get(node2)).append(">.\n");108 queryStr.append("?n3 ").append(" rdf:type <").append(ocg.labels.get(node3)).append(">.\n");105 queryStr.append("?n1縲rdf:type ?c1 .\n"); 106 queryStr.append("?n2縲rdf:type ?c2 .\n"); 107 queryStr.append("?n3縲rdf:type ?c3 .\n"); 109 108 110 109 queryStr.append("{{"); … … 119 118 queryStr.append("?n3").append(" ").append("?p2").append(" ") 120 119 .append("?n2").append(" }}\n"); 121 120 121 queryStr.append("VALUES (?c1 ?c2 ?c3){ \n"); 122 queryStr.append("<").append(ocg.labels.get(node1)).append("> \n"); 123 queryStr.append("<").append(ocg.labels.get(node2)).append("> \n"); 124 queryStr.append("<").append(ocg.labels.get(node3)).append("> \n"); 125 queryStr.append("} \n"); 122 126 queryStr.append("} \n"); 123 127 … … 126 130 System.out.println(sparqlQuery); 127 131 Query query = QueryFactory.create(sparqlQuery, Syntax.syntaxARQ); 128 /*129 QueryEngineHTTP httpQuery = new QueryEngineHTTP(sparqlEndpoint, query);130 boolean res = httpQuery.execAsk();131 httpQuery.close();132 */133 132 QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlEndpoint, query); 134 133 boolean res = qexec.execAsk(); -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/OWLClassGraph.java
r250 r251 17 17 int limit = 100; 18 18 int th = 1; 19 double cth = 1.0; // 0.0(no path) - 1.0(all paths) 20 19 21 List<String> nodeType; 20 22 ArrayList<HashSet<Integer>> connectionTable; … … 24 26 List<Map<Integer, Integer>> edgeweight; 25 27 List<Integer> nodeweight; 28 Map<String, Boolean> checkedpaths; 26 29 27 30 public class LinkAndPath{ … … 56 59 } 57 60 58 public OWLClassGraph(RDFSchemaAnalyzer rdfsa){ // not used61 public OWLClassGraph(RDFSchemaAnalyzer rdfsa){ // for experiment 59 62 super(); 60 63 nodeType = new LinkedList<String>(); 64 this.askcheck = false; 65 setClassGraph(rdfsa); 61 66 } 62 67 … … 124 129 private List<List<ClassLink>> searchPaths(String startClass, String endClass){ 125 130 //int asked = 0; 126 Map<String,Boolean>checkedpaths = new HashMap<String, Boolean>();131 checkedpaths = new HashMap<String, Boolean>(); 127 132 List<List<ClassLink>> paths = new ArrayList<>(); 128 133 Integer snode = labelednodes.get(startClass); … … 163 168 nextpath.add(nextnode); 164 169 // tmp 165 if ( i >= 1 ){170 if ( i >= 1 && askcheck == true ){ 166 171 int wn = nodeweight.get(crrnode); 167 172 int in = edgeweight.get(crrpath.get(crrpath.size()-2)).get(crrnode); … … 182 187 } 183 188 }else{ 184 boolean chk = EndpointAccess.check3SimplePath withJoin(nextnode, crrpath.get(crrpath.size()-1),189 boolean chk = EndpointAccess.check3SimplePath(nextnode, crrpath.get(crrpath.size()-1), 185 190 crrpath.get(crrpath.size()-2), this, sparqlEndpoint); 186 191 checkedpaths.put(key1, chk); … … 235 240 addedpath.add(cl); 236 241 // check 237 //if ( EndpointAccess.checkPath(startClass, addedpath, sparqlEndpoint)){242 if (checkPath(startClass, addedpath)){ 238 243 tmppaths.add(addedpath); 239 //}244 } 240 245 } 241 246 } … … 246 251 } 247 252 248 /* 249 private void setClassGraph(RDFSchemaAnalyzer rdfsa){ 250 // setNodes 251 SClass[] classes = null; 252 try{ 253 classes = rdfsa.getOWLClasses(null, null, null, true); 254 }catch(Exception e){ 255 System.err.println(e); return; 256 } 257 for (int i = 0 ; i < classes.length; i++){ 258 addNode(classes[i].getClassURI()); 259 nodeType.add("class"); 260 } 261 // setEdges 262 for (int i = 0 ; i < classes.length; i++ ){ 263 try{ 264 ClassLink[] classLinks = rdfsa.getNextClass(null, classes[i].getClassURI(), limit, true); 265 for (int j = 0 ; j < classLinks.length; j++){ 266 Integer n = labelednodes.get(classLinks[j].getLinkedClassURI()); 267 if ( n != null ){ 268 addEdge(i, n, classLinks[j]); 269 }else{ 270 n = labelednodes.get(classLinks[j].getLinkedLiteralDatatypeURI()); 271 if ( n == null ){ 253 private void setClassGraph(RDFSchemaAnalyzer rdfsa){ 254 // setNodes 255 SClass[] classes = null; 256 try{ 257 classes = rdfsa.getOWLClasses(null, null, null, true); 258 }catch(Exception e){ 259 System.err.println(e); return; 260 } 261 for (int i = 0 ; i < classes.length; i++){ 262 addNode(classes[i].getClassURI()); 263 nodeType.add("class"); 264 } 265 // setEdges 266 for (int i = 0 ; i < classes.length; i++ ){ 267 try{ 268 ClassLink[] classLinks = rdfsa.getNextClass(null, classes[i].getClassURI(), limit, true); 269 for (int j = 0 ; j < classLinks.length; j++){ 270 Integer n = labelednodes.get(classLinks[j].getLinkedClassURI()); 271 if ( n != null ){ 272 addEdge(i, n, classLinks[j]); 273 }else{ 274 n = labelednodes.get(classLinks[j].getLinkedLiteralDatatypeURI()); 275 if ( n == null ){ 272 276 addNode(classLinks[j].getLinkedLiteralDatatypeURI()); 273 277 n = nodeType.size(); 274 278 nodeType.add("literal"); 275 }276 addEdge(i, n, classLinks[j]);277 }278 }279 }catch(Exception e){280 System.err.println(e);281 }282 }283 }*/279 } 280 addEdge(i, n, classLinks[j]); 281 } 282 } 283 }catch(Exception e){ 284 System.err.println(e); 285 } 286 } 287 } 284 288 285 289 public void setPartClassGraph(RDFSchemaAnalyzer rdfsa, String sparqlEndpoint, String startClass){ … … 332 336 visited.addAll(nodes); 333 337 } 334 // cut visited 338 // cut visited 335 339 Iterator<Integer> nit = visited.iterator(); 336 340 while(nit.hasNext()){ … … 405 409 } 406 410 411 private boolean checkPath(String startClass, List<ClassLink> paths){ 412 // KOKO 413 return false; 414 } 407 415 // old codes 408 416 /* -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/Path.java
r248 r251 1 1 package org.biohackathon.SPARQLBuilder.OWL; 2 2 3 import java.util. List;3 import java.util.*; 4 4 5 5 import org.json.JSONArray; … … 141 141 //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 142 142 } 143 144 public double computeCost(){ 145 int length = classLinks.size(); 146 ListIterator<ClassLink> lit = classLinks.listIterator(); 147 while( lit.hasNext() ){ 148 ClassLink cl = lit.next(); 149 // KOKO 150 151 } 152 return 1.0; 153 } 143 154 } -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/QueryPathGenerator.java
r248 r251 7 7 package org.biohackathon.SPARQLBuilder.OWL; 8 8 9 import java.io.*; 10 import java.util.*; 9 11 10 12 /** … … 21 23 22 24 private static final String CDIR = "cdata"; 23 24 /* 25 25 26 public static void main(String[] args){ 26 // For Test 27 //String sp = "http://data.allie.dbcls.jp/sparql"; 28 //String sc = "http://purl.org/allie/ontology/201108#ShortForm"; 29 //String ec = "http://purl.org/allie/ontology/201108#LongForm"; 30 31 String sp = "http://www.ebi.ac.uk/rdf/services/chembl/sparql"; 32 String sc = "http://rdf.ebi.ac.uk/terms/chembl#Enzyme"; 33 String ec = "http://rdf.ebi.ac.uk/terms/chembl#Activity"; 34 35 //String sp = "http://www.ebi.ac.uk/rdf/services/biosamples/sparql"; 36 //String sc = "http://rdf.ebi.ac.uk/terms/biosd/Sample"; 37 //String ec = "http://purl.obolibrary.org/obo/NCBITaxon_7955"; 38 //String sp = "http://www.ebi.ac.uk/rdf/services/biosamples/sparql"; 39 //String sc = "http://rdf.ebi.ac.uk/terms/biosd/Sample"; 40 //String ec = "http://purl.obolibrary.org/obo/NCBITaxon_7955"; 41 //String sp = "http://lsd.dbcls.jp/sparql"; 42 //String sc = "http://purl.jp/bio/10/lsd/ontology/201209#EnglishCode"; 43 //String ec = "http://purl.jp/bio/10/lsd/ontology/201209#JapaneseCode"; 44 //QueryPathGenerator qpg = new QueryPathGenerator(sp, "c:\\cdata"); 45 QueryPathGenerator qpg1 = new QueryPathGenerator(sp, "cdata/"); 46 //qpg1.testOWLClassGraph(); 47 //SClass[] cl = qpg.getClasses(null); 48 }*/ 27 QueryPathGenerator qpg = new QueryPathGenerator(); 28 //String[] elist = qpg.getFactory().getEndpointURIList(); 29 List<String> elist = new LinkedList<String>(); 30 File file0 = new File("eplist.txt"); 31 try{ 32 BufferedReader br = new BufferedReader(new FileReader(file0)); 33 String buf = null; 34 while( (buf = br.readLine()) != null){ 35 elist.add(buf); 36 } 37 }catch(IOException e){ 38 System.err.println(e); 39 } 40 41 ListIterator<String> eit = elist.listIterator(); 42 int i = 0; 43 while(eit.hasNext()){ 44 String ep = eit.next(); 45 qpg.setSPARQLendpoint(ep); 46 qpg.graph = new OWLClassGraph(qpg.analyzer); 47 SClass[] classes = qpg.getClasses(null); 48 File file1 = new File("path".concat(Integer.toString(i)).concat(".txt")); 49 File file2 = new File("ptable".concat(Integer.toString(i)).concat(".txt")); 50 try{ 51 BufferedWriter bw1 = new BufferedWriter(new FileWriter(file1)); 52 BufferedWriter bw2 = new BufferedWriter(new FileWriter(file2)); 53 String jsonstr = "["; 54 int m = 0; 55 for ( int j = 0 ; j < classes.length; j ++ ){ 56 SClass start = classes[j]; 57 for ( int k = j + 1 ; k < classes.length; k++ ){ 58 SClass end = classes[k]; 59 Path[] paths = qpg.getPaths(start.getClassURI(), end.getClassURI(), false); 60 for( int l = 0; l < paths.length; l++ ){ 61 if ( paths[l] == null ){ 62 continue; 63 } 64 if (m > 0 ){ 65 jsonstr += ","; 66 } 67 double cost = paths[l].computeCost(); 68 bw2.write(Double.toString(cost)); 69 bw2.write(","); 70 bw2.write(Boolean.toString(EndpointAccess.checkPath(paths[l], ep))); 71 bw2.newLine(); 72 jsonstr += paths[i].toJSONString3(classes); 73 m++; 74 } 75 } 76 } 77 jsonstr += "]"; 78 bw1.write(jsonstr); 79 bw1.newLine(); 80 81 bw1.close(); 82 bw2.close(); 83 }catch(IOException e){ 84 System.err.println(e); 85 } 86 i++; 87 } 88 } 49 89 50 90 public QueryPathGenerator(){ … … 58 98 59 99 public void setOWLClassGraph(String startClass){ 60 graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, askcheck); 100 //graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, askcheck); 101 graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, true); 61 102 } 62 63 /*64 public QueryPathGenerator(String sparqlEndpoint, String crawlFileName){65 factory = new RDFSchemaAnalyzerFactory(crawlFileName);66 setSPARQLendpoint(sparqlEndpoint);67 setOWLClassGraph();68 }69 */70 103 71 104 public SClass[] getClasses(String keyword){ … … 86 119 87 120 public Path[] getPaths(String startClass, String endClass, boolean askcheck){ 88 this.askcheck = askcheck;89 121 if ( graph == null ){ 90 122 //System.err.println("Class graph is null."); 91 123 setOWLClassGraph(startClass); 92 124 } 125 graph.askcheck = askcheck; 93 126 return graph.getPaths(startClass, endClass); 94 127 } … … 139 172 return label; 140 173 } 141 142 /* 143 private void setOWLClassGraph(){ 144 //graph = new OWLClassGraph(analyzer); 145 graph = new OWLClassGraph(); 146 }*/ 147 174 148 175 public OWLClassGraph getOWLClassGraph(){ 149 176 /*if ( graph == null ){ -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/PLServlet.java
r248 r251 83 83 SClass[] classes = qpg.getClasses(null); 84 84 Path[] paths = null; 85 if ( ask == null ){86 paths = qpg.getPaths(st, en, false);87 }else if ( ask.equalsIgnoreCase("true")){85 //if ( ask == null ){ 86 // paths = qpg.getPaths(st, en, false); 87 //}else if ( ask.equalsIgnoreCase("true")){ 88 88 paths = qpg.getPaths(st, en, true); 89 }else{90 paths = qpg.getPaths(st, en, false);91 }89 //}else{ 90 // paths = qpg.getPaths(st, en, false); 91 //} 92 92 93 93 String jsonstr = "[";