チェンジセット 46 : BH13SPARQLBuilder/src/org/biohackathon
- 更新日時:
- 2014/02/17 16:11:59 (11 年 前)
- パス:
- BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL
- ファイル:
-
- 2 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/ClassLink.java
r26 r46 13 13 private Direction direction = null; 14 14 private int numOfLinks = 0; 15 15 private int numOfLinkedInstances = 0; 16 private int numOfOriginInstances = 0; 17 16 18 /** 17 19 * 繝励Ο繝代ユ繧」URI縲√Μ繝ウ繧ッ蜈茨シ亥��峨け繝ゥ繧ケ縲√Μ繝ウ繧ッ縺ョ蜷代″繧剃ク弱∴繧区ァ区�蟄� … … 24 26 * @since 28.01.2014 25 27 */ 26 public ClassLink(String propertyURI, String linkedClassURI, Direction direction, int numLinks ){28 public ClassLink(String propertyURI, String linkedClassURI, Direction direction, int numLinks, int numofOriginInstances, int numOfLinkedInstances){ 27 29 this.propertyURI = propertyURI; 28 30 this.linkedClassURI = linkedClassURI; 29 31 this.direction = direction; 30 32 this.numOfLinks = numLinks; 33 this.numOfLinkedInstances = numOfLinkedInstances; 34 this.numOfOriginInstances = numOfOriginInstances; 31 35 } 32 36 … … 88 92 this.direction = direction; 89 93 } 94 95 public final int getNumOfLinkedInstances() { 96 return numOfLinkedInstances; 97 } 98 99 public final void setNumOfLinkedInstances(int numOfLinkedInstances) { 100 this.numOfLinkedInstances = numOfLinkedInstances; 101 } 102 103 104 public final int getNumOfOriginInstances() { 105 return numOfOriginInstances; 106 } 107 108 109 public final void setNumOfOriginInstances(int numOfOriginInstances) { 110 this.numOfOriginInstances = numOfOriginInstances; 111 } 90 112 113 114 91 115 // private String[] propertyDomainClassURIs = null; 92 116 // private String[] propertyRangeClassURIs = null; 93 94 117 118 119 95 120 } -
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();