- 更新日時:
- 2014/02/17 16:11:59 (11 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilderImpl.java
r42 r46 72 72 } 73 73 */ 74 74 75 System.out.println("CLS"); 75 76 76 77 String uri = "http://purl.jp/bio/10/lsd/ontology/201209#EnglishEntry"; 77 78 78 ClassLink[] cls = builder.getNextClass(null, uri, 100, false); 79 79 ClassLink[] cls = null; 80 try{ 81 cls = builder.getNextClass(null, uri, 100, false); 82 }catch(Exception ex) { 83 ex.printStackTrace(); 84 } 85 86 System.out.println("Solutions: "); 80 87 if (cls != null) { 81 88 for (ClassLink cl : cls) { … … 87 94 } 88 95 } 96 97 98 99 89 100 /* 101 uri = "http://purl.jp/bio/10/lsd/ontology/201209#EnglishEntry"; 102 90 103 System.out.println("CLS-INS"); 91 cls = builder.getNextClassViaInstanceLink(null, clz[0].getClassURI(), 92 100); 104 cls = null; 105 try{ 106 cls = builder.getNextClassViaInstanceLink(null, uri, 100); 107 }catch(Exception ex){ 108 ex.printStackTrace(); 109 } 93 110 if (cls != null) { 94 111 for (ClassLink cl : cls) { … … 96 113 } 97 114 } 98 115 */ 116 /* 99 117 System.out.println("Instances"); 100 118 Instance[] ins = builder.getInstances(null, "\"A.C. Reed\"@en"); … … 184 202 185 203 Query query = QueryFactory.create(queryStr.toString()); 186 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, 187 query); 204 205 206 QueryExecution qexec = null; 207 try{ 208 long start = System.currentTimeMillis(); 209 qexec = QueryExecutionFactory.sparqlService(endpointURI, 210 query); 211 long end = System.currentTimeMillis(); 212 System.out.println("EXEC TIME: " + (end-start)); 213 }catch(Exception ex){ 214 ex.printStackTrace(); 215 throw ex; 216 } 188 217 189 218 ResultSet results = qexec.execSelect(); … … 327 356 // SELECT 328 357 if (countLinks) { 329 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c (COUNT(?s) AS ?numOfLinks) \n");358 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c (COUNT(?s) AS ?numOfLinks) (COUNT(DISTINCT(?s)) AS ?numOfLinkedInstances) \n"); 330 359 } else { 331 360 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c \n"); … … 390 419 } 391 420 421 System.out.println("getNextClasses SPARQL Query: "); 392 422 System.out.println(queryStr.toString()); 393 423 394 424 Query query = QueryFactory.create(queryStr.toString()); 395 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, 425 QueryExecution qexec = null; 426 try{ 427 qexec = QueryExecutionFactory.sparqlService(endpointURI, 396 428 query); 397 398 ResultSet results = qexec.execSelect(); 429 }catch(Exception ex){ 430 ex.printStackTrace(); 431 throw ex; 432 } 433 434 ResultSet results = null; 435 try{ 436 long start = System.currentTimeMillis(); 437 results = qexec.execSelect(); 438 long end = System.currentTimeMillis(); 439 System.out.println("EXEC TIME: " + (end-start)); 440 }catch(Exception ex){ 441 ex.printStackTrace(); 442 throw ex; 443 } 444 399 445 ArrayList<ClassLink> solCLs = new ArrayList<ClassLink>(); 400 446 for (; results.hasNext();) { … … 431 477 } 432 478 ClassLink cl = new ClassLink(proURI, clsURI, direction, 433 numOfLinks );479 numOfLinks, 0, 0 ); 434 480 solCLs.add(cl); 435 481 } … … 484 530 } 485 531 486 //System.out.println(queryStr.toString());532 System.out.println(queryStr.toString()); 487 533 488 534 Query query = QueryFactory.create(queryStr.toString()); … … 513 559 // System.out.println(propURI + " " + clsURI + " " + direction); 514 560 515 ClassLink cl = new ClassLink(propURI, clsURI, direction, 0 );561 ClassLink cl = new ClassLink(propURI, clsURI, direction, 0, 0, 0); 516 562 solCLs.add(cl); 517 563 } … … 714 760 queryStr.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"); 715 761 716 queryStr.append("SELECT (COUNT(?os) AS ?numOfLinks) \n");762 queryStr.append("SELECT (COUNT(?os) AS ?numOfLinks) (COUNT(DISTINCT(?is)) AS ?numOfOriginInstances) (COUNT(DISTINCT(?os)) AS ?numOfLinkedInstances) \n"); 717 763 if (graphURIs != null) { 718 764 for (String graphURI : graphURIs) { … … 778 824 classLink.setNumOfLinks(numOfLinks); 779 825 } 826 lit = sol.getLiteral("numOfLinkedInstances"); 827 if (lit != null) { 828 int numOfLinkedInstances = lit.getInt(); 829 classLink.setNumOfLinkedInstances(numOfLinkedInstances); 830 } 831 lit = sol.getLiteral("numOfOriginInstances"); 832 if (lit != null) { 833 int numOfOriginInstances = lit.getInt(); 834 classLink.setNumOfOriginInstances(numOfOriginInstances); 835 } 780 836 } 781 837 qexec.close();