チェンジセット 254 : SPARQLBuilderWWW
- 更新日時:
- 2015/09/14 11:06:16 (9 年 前)
- パス:
- SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL
- ファイル:
-
- 1 追加
- 7 変更
凡例:
- 変更なし
- 追加
- 削除
-
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/AcquiredStructureAnalyzer.java
r173 r254 33 33 } 34 34 35 35 /* 36 36 public static void main(String[] args) throws Exception{ 37 37 … … 56 56 57 57 } 58 58 */ 59 59 60 60 public AcquiredStructureAnalyzer(String endpointURI, String[] graphURIs, Model model){ -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/ClassLink.java
r221 r254 166 166 return json_str; 167 167 } 168 168 169 public String toJSONString4(QueryPathGenerator qpg) { 170 String json_str ="{"; 171 172 if( propertyURI != null ) { 173 //json_str+="\"propertyURI\":"+"\""+propertyURI+"\","; 174 json_str+="\"predicate\":"+"\""+propertyURI+"\","; 175 } 176 else{ 177 json_str+="\"predicate\":"+"\"propertyURI\","; 178 } 179 if( linkedClassURI != null ){ 180 //json_str+="\"linkedClassURI\":"+"\""+linkedClassURI+"\","; 181 json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\","; 182 } 183 else{ 184 //json_str+="\"linkedClassURI\":"+"\"linkedClassURI\","; 185 json_str+="\"linkedClass\":"+"\""+linkedClassURI+"\","; 186 } 187 if( linkedLiteralDatatypeURI != null ){ 188 json_str+="\"linkedLiteralDatatypeURI\":"+"\""+linkedLiteralDatatypeURI+"\","; 189 } 190 else{ 191 json_str+="\"linkedLiteralDatatypeURI\":"+"\"linkedLiteralDatatypeURI\","; 192 } 193 if( direction != null ){ 194 json_str+="\"direction\":"+"\""+direction.toString()+"\","; 195 } 196 else{ 197 json_str+="\"direction\":"+"\"direction\","; 198 } 199 if ( linkedClassURI != null ){ 200 String label = qpg.getClassLabel(linkedClassURI); 201 json_str+="\"label\":"+"\""+label+"\""; 202 }else if ( linkedLiteralDatatypeURI != null ){ 203 String url[] = linkedLiteralDatatypeURI.split("/"); 204 String tmplabel = url[url.length-1]; 205 String[] tmplabel2 = tmplabel.split("#"); 206 String label = tmplabel2[tmplabel2.length-1]; 207 json_str+="\"label\":"+"\""+label+"\""; 208 }else{ 209 json_str+="\"label\":"+"\""+"\"No Label\""+"\""; 210 } 211 json_str+="}"; 212 213 return json_str; 214 } 215 216 169 217 public int getNumOfLinks() { 170 218 return numOfLinks; -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/OWLClassGraph.java
r252 r254 12 12 13 13 public class OWLClassGraph extends LabeledMultiDigraph{ 14 //String startClass;15 //String endClass;16 14 int nsteps = 4; 17 15 int limit = 100; … … 23 21 String sparqlEndpoint; 24 22 Set<Integer> visited; 25 boolean askcheck;26 23 List<Map<Integer, Integer>> edgeweight; 27 24 List<Integer> nodeweight; … … 62 59 super(); 63 60 nodeType = new LinkedList<String>(); 64 this.askcheck = false;65 61 setClassGraph(rdfsa); 66 62 } 67 63 68 public OWLClassGraph(RDFSchemaAnalyzer rdfsa, String sparqlEndpoint, String startClass , boolean askcheck){ // used64 public OWLClassGraph(RDFSchemaAnalyzer rdfsa, String sparqlEndpoint, String startClass){ // used 69 65 super(); 70 66 nodeType = new LinkedList<String>(); 71 this.askcheck = askcheck;72 67 setPartClassGraph(rdfsa, sparqlEndpoint, startClass); 73 68 } … … 124 119 } 125 120 126 public HashSet<Integer> getConnectionList(Integer node){127 return connectionTable.get(node);128 }129 130 121 private List<List<ClassLink>> searchPaths(String startClass, String endClass){ 131 122 //int asked = 0; … … 168 159 List<Integer> nextpath = new LinkedList<Integer>(crrpath); // copy 169 160 nextpath.add(nextnode); 170 // tmp171 if ( i >= 1 && askcheck == true ){172 int wn = nodeweight.get(crrnode);173 int in = edgeweight.get(crrpath.get(crrpath.size()-2)).get(crrnode);174 int out = edgeweight.get(nextnode).get(crrnode);175 if ( wn > in + out ){176 /*177 String key1 = nextnode.toString().concat("-").concat(crrpath.get(crrpath.size()-1).toString())178 .concat("-").concat(crrpath.get(crrpath.size()-2).toString());179 String key2 = crrpath.get(crrpath.size()-2).toString().concat("-").concat(crrpath.get(crrpath.size()-1).toString())180 .concat("-").concat(nextnode.toString());181 if ( checkedpaths.containsKey(key1) ){182 if ( checkedpaths.get(key1) == false ){183 continue;184 }185 }else if ( checkedpaths.containsKey(key2) ){186 if ( checkedpaths.get(key2) == false ){187 continue;188 }189 }else{190 boolean chk = EndpointAccess.check3SimplePath(nextnode, crrpath.get(crrpath.size()-1),191 crrpath.get(crrpath.size()-2), this, sparqlEndpoint);192 checkedpaths.put(key1, chk);193 if ( chk == false ){194 continue;195 }196 }197 */198 continue;199 }200 }201 161 if ( nextnode.equals(enode) ){ 202 162 simplePaths.add(nextpath); … … 241 201 addedpath.add(cl); 242 202 // check 243 if (checkPath(startClass, addedpath)){203 //if (checkPath(startClass, addedpath)){ 244 204 tmppaths.add(addedpath); 245 }205 //} 246 206 } 247 207 } … … 348 308 } 349 309 } 350 } 351 352 353 private ArrayList<HashSet<Integer>> createConnectionTable(){ // not used 354 ArrayList<HashSet<Integer>> ct = new ArrayList<HashSet<Integer>>(); 355 for (int i = 0; i < labels.size(); i++ ){ // each node 356 HashSet<Integer> cl = createConnectionList(i); 357 ct.add(cl); 358 } 359 return ct; 360 } 310 } 361 311 362 private HashSet<Integer> createConnectionList(Integer node){ // not used 363 HashSet<Integer> cl = new HashSet<Integer>(); 364 HashSet<Integer> crrnodes = new HashSet<Integer>(); 365 crrnodes.add(node); 366 cl.add(node); 367 for ( int i = 0 ; i < nsteps; i++ ){ 368 Set<Integer> nextnodes = new HashSet<Integer>(); 369 Iterator<Integer> cit = crrnodes.iterator(); 370 while ( cit.hasNext() ){ 371 Integer crr = cit.next(); 372 Set<Integer> nexts = gadjlist.get(crr).keySet(); 373 Iterator<Integer> nit = nexts.iterator(); 374 while ( nit.hasNext() ){ 375 Integer next = nit.next(); 376 if ( !cl.contains(next) ){ 377 nextnodes.add(next); 378 cl.add(next); 379 } 380 } 381 } 382 crrnodes.clear(); 383 crrnodes.addAll(nextnodes); 384 } 385 return cl; 386 } 387 388 389 private void updateWeight(Integer node1, Integer node2, ClassLink edge){ 390 Map<Integer, Integer> weight = edgeweight.get(node1); 391 Integer crr = weight.get(node2); 392 if (crr == null ){ 393 crr = edge.getNumOfLinkedClassInstances(); 394 weight.put(node2, crr); 395 } 396 if ( crr < edge.getNumOfLinkedClassInstances() ){ 397 crr = edge.getNumOfLinkedClassInstances(); 398 weight.put(node2, crr); 399 } 400 weight = edgeweight.get(node2); 401 crr = weight.get(node1); 402 if (crr == null ){ 403 crr = edge.getNumOfOriginClassInstances(); 404 weight.put(node1, crr); 405 } 406 if ( crr < edge.getNumOfOriginClassInstances() ){ 407 crr = edge.getNumOfOriginInstances(); 408 weight.put(node1, crr); 409 } 410 } 411 412 private boolean checkPath(String startClass, List<ClassLink> paths){ 413 // KOKO 414 return true; 415 } 416 // old codes 417 /* 418 public Path[] getPaths_old(RDFSchemaAnalyzer rdfsa, boolean countLink, String startClass, String endClass){ 419 List<List<ClassLink>> paths = null; 420 paths = searchPathsbyVisitingNodes(rdfsa, countLink, startClass, endClass); 421 NavigableSet<Path> sortedpath = new TreeSet<Path>(); 422 ListIterator<List<ClassLink>> pit = paths.listIterator(); 423 int j = 0; 424 while ( pit.hasNext() ){ 425 Path path = new Path(); 426 path.setStartClass(startClass); 427 List<ClassLink> crrpath = pit.next(); 428 path.setClassLinks(crrpath); 429 ListIterator<ClassLink> cit = crrpath.listIterator(); 430 int min = Integer.MAX_VALUE; 431 while ( cit.hasNext() ){ 432 ClassLink cl = cit.next(); 433 if ( cl.getNumOfLinks() < min ){ 434 min = cl.getNumOfLinks(); 435 } 436 } 437 path.setWidth(min); 438 sortedpath.add(path); 439 j++; 440 } 441 Path[] patharray = new Path[paths.size()]; 442 Iterator<Path> pait = sortedpath.descendingIterator(); 443 int i = 0; 444 while ( pait.hasNext() ){ 445 patharray[i] = pait.next(); 446 i++; 447 } 448 return patharray; 449 } 450 451 private List<List<ClassLink>> searchPaths_old(String startClass, String endClass){ 452 453 List<List<ClassLink>> paths = new ArrayList<>(); 454 List<List<Integer>> simplePaths = new LinkedList<>(); 455 Integer snode = labelednodes.get(startClass); 456 Integer enode = labelednodes.get(endClass); 457 List<List<Integer>> lp = new LinkedList<>(); 458 List<Integer> ini = new LinkedList<Integer>(); // initial path 459 ini.add(snode); 460 lp.add(ini); 461 for (int i = 0; i < nsteps; i++ ){ 462 ListIterator<List<Integer>> lit = lp.listIterator(); 463 List<List<Integer>> nextlp = new LinkedList<>(); 464 while ( lit.hasNext() ){ 465 List<Integer> crrpath = lit.next(); 466 Integer crrnode = crrpath.get(crrpath.size()-1); 467 Set<Integer> nexts = gadjlist.get(crrnode).keySet(); 468 Iterator<Integer> nit = nexts.iterator(); 469 while( nit.hasNext() ){ 470 Integer nextnode = nit.next(); 471 if ( crrpath.contains(nextnode) ){ continue; } 472 List<Integer> nextpath = new LinkedList<Integer>(crrpath); // copy 473 nextpath.add(nextnode); 474 if ( nextnode.equals(enode) ){ 475 simplePaths.add(nextpath); 476 continue; 477 } 478 nextlp.add(nextpath); 479 } 480 } 481 lp = nextlp; 482 } 483 484 ListIterator<List<Integer>> pit = simplePaths.listIterator(); 485 while( pit.hasNext()){ 486 List<Integer> spath = pit.next(); 487 List<List<ClassLink>> convertedPaths = convertSimplePathToPaths(spath); 488 paths.addAll(convertedPaths); 489 } 490 return paths; 491 } 492 */ 493 /* 494 private List<List<ClassLink>> searchPaths(RDFSchemaAnalyzer rdfsa, boolean countLinks){ 495 List<List<ClassLink>> paths = new ArrayList<>(); 496 List<LinkAndPath> lp = new LinkedList<>(); 497 lp.add(new LinkAndPath(new ClassLink("",startClass,null,Direction.both,0,0,0,0,0,false,false), new LinkedList<ClassLink>(), "")); 498 try{ 499 for ( int i = 0; i < nsteps; i++ ){ 500 ListIterator<LinkAndPath> lit = lp.listIterator(); 501 List<LinkAndPath> nextlp = new LinkedList<>(); 502 while ( lit.hasNext() ){ 503 LinkAndPath crrlp = lit.next(); 504 ClassLink[] classLinks = rdfsa.getNextClass(null, crrlp.classLink.getLinkedClassURI(), limit, countLinks); 505 for ( int j = 0 ; j < classLinks.length; j++ ){ 506 List<ClassLink> crrpath = new LinkedList<>(crrlp.path); 507 crrpath.add(classLinks[j]); 508 if ( classLinks[j].getLinkedClassURI() == null ){ continue; } 509 if ( classLinks[j].getLinkedClassURI().equals(endClass) ){ 510 paths.add(new LinkedList<>(crrpath)); 511 continue; 512 } 513 if ( countLinks == true && classLinks[j].getNumOfLinks() <= th){ 514 continue; 515 } 516 if ( i >= 2 ){ 517 if ( crrlp.classLink.getPropertyURI().equals(classLinks[j].getPropertyURI()) && 518 crrlp.classLink.getDirection() != classLinks[j].getDirection() && 519 crrlp.originalClassURI.equals( classLinks[j].getLinkedClassURI()) ){ 520 continue; 521 } 522 } 523 nextlp.add(new LinkAndPath(classLinks[j], crrpath, crrlp.classLink.getLinkedClassURI())); 524 } 525 } 526 lp = nextlp; 527 } 528 }catch(Exception e){ 529 System.err.println(e); 530 } 531 return paths; 532 } 533 */ 534 312 private void updateWeight(Integer node1, Integer node2, ClassLink edge){ 313 Map<Integer, Integer> weight = edgeweight.get(node1); 314 Integer crr = weight.get(node2); 315 if (crr == null ){ 316 crr = edge.getNumOfLinkedClassInstances(); 317 weight.put(node2, crr); 318 } 319 if ( crr < edge.getNumOfLinkedClassInstances() ){ 320 crr = edge.getNumOfLinkedClassInstances(); 321 weight.put(node2, crr); 322 } 323 weight = edgeweight.get(node2); 324 crr = weight.get(node1); 325 if (crr == null ){ 326 crr = edge.getNumOfOriginClassInstances(); 327 weight.put(node1, crr); 328 } 329 if ( crr < edge.getNumOfOriginClassInstances() ){ 330 crr = edge.getNumOfOriginInstances(); 331 weight.put(node1, crr); 332 } 333 } 334 535 335 } -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/Path.java
r251 r254 78 78 // label 79 79 json_str+="\"label\":\""+QueryPathGenerator.getClassLabelfromList(startClass, classes)+"\","; 80 80 if (classLinks != null && classLinks.size() != 0) { 81 81 json_str+="\"classLinks\":["; 82 82 … … 95 95 } 96 96 97 public String toJSONString4(QueryPathGenerator qpg){ 98 String json_str=""; 99 json_str+="{\"startClass\":\""+ startClass+"\","; 100 // label 101 json_str+="\"label\":\""+qpg.getClassLabel(startClass)+"\","; 102 if (classLinks != null && classLinks.size() != 0) { 103 json_str+="\"classLinks\":["; 104 105 JSONObject[] classLinkObjs = new JSONObject[classLinks.size()]; 106 for (int i = 0; i < classLinks.size(); i++) { 107 if(i>0){json_str += "," ;} 108 json_str+= classLinks.get(i).toJSONString4(qpg); 109 } 110 json_str+="]"; 111 } 112 json_str += ","; 113 json_str +="\"score\":\""+width+"\""; 114 json_str +="}"; 115 116 return json_str; 117 } 97 118 98 119 public String getStartClass() { -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/QueryPathGenerator.java
r251 r254 20 20 private RDFSchemaAnalyzer analyzer = null; 21 21 private OWLClassGraph graph; 22 private boolean askcheck; 22 23 private Map<String, String> clabels; 23 24 24 25 private static final String CDIR = "cdata"; 25 26 private static final String ODIR = "owldata"; 27 28 /* 26 29 public static void main(String[] args){ 27 30 QueryPathGenerator qpg = new QueryPathGenerator(); … … 87 90 } 88 91 } 92 */ 89 93 90 94 public QueryPathGenerator(){ … … 98 102 99 103 public void setOWLClassGraph(String startClass){ 100 //graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, askcheck); 101 graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, true); 104 graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass); 102 105 } 103 106 … … 123 126 setOWLClassGraph(startClass); 124 127 } 125 graph.askcheck = askcheck;126 128 return graph.getPaths(startClass, endClass); 127 129 } … … 144 146 } 145 147 148 public String getClassLabel(String classURI){ 149 return clabels.get(classURI); 150 } 151 152 public void setClassLabels(SClass[] classes){ 153 clabels = new HashMap<String, String>(); 154 Map<String, String> extLabels = getClassLabelsFromExternal(); 155 156 for ( int i = 0 ; i < classes.length; i++ ){ 157 String classURI = classes[i].getClassURI(); 158 159 Label[] labels = classes[i].getLabels(); 160 String label = null; 161 for ( int j = 0 ; j < labels.length; j++ ){ 162 if ( labels[j].getLanguage() == null ){ 163 label = labels[j].getLabel(); 164 break; 165 }else if ( labels[j].getLanguage().equals("en") || labels[j].getLanguage().equals("") ){ 166 label = labels[j].getLabel(); 167 break; 168 } 169 } 170 if ( label == null ){ 171 label = extLabels.get(classURI); 172 } 173 if ( label == null ){ 174 String[] uris = classURI.split("/"); 175 String tmplabel = uris[uris.length-1]; 176 String[] tmplabel2 = tmplabel.split("#"); 177 label = tmplabel2[tmplabel2.length-1]; 178 } 179 clabels.put(classURI, label); 180 } 181 } 182 146 183 public static String getClassLabelfromList(String classURI, SClass[] classes){ 147 184 if ( classURI == null ){ … … 152 189 if ( classURI.equals(classes[i].getClassURI()) ){ 153 190 return getClassLabelfromClass(classes[i]); 154 } 191 } 155 192 } 156 193 return ""; … … 173 210 } 174 211 212 public Map<String, String> getClassLabelsFromExternal(){ 213 return OWLLabelReader.readLabels(ODIR); 214 } 215 175 216 public OWLClassGraph getOWLClassGraph(){ 176 217 /*if ( graph == null ){ -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/SimpleTree.java
r133 r254 122 122 * 123 123 */ 124 124 /* 125 125 public static void main (String[] args) { 126 126 … … 145 145 146 146 147 } 147 }*/ 148 148 149 149 } -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/StructureCrawler.java
r133 r254 15 15 16 16 // this is just for a test 17 /* 17 18 public static void main(String[] args) throws Exception{ 18 19 StructureCrawler sc = new StructureCrawler(new File("c:\\cdata")); … … 29 30 } 30 31 } 31 32 */ 32 33 33 34