140 | | |
141 | | public Path[] getPaths_old(RDFSchemaAnalyzer rdfsa, boolean countLink, String startClass, String endClass){ |
142 | | List<List<ClassLink>> paths = null; |
143 | | paths = searchPathsbyVisitingNodes(rdfsa, countLink, startClass, endClass); |
144 | | NavigableSet<Path> sortedpath = new TreeSet<Path>(); |
145 | | ListIterator<List<ClassLink>> pit = paths.listIterator(); |
146 | | int j = 0; |
147 | | while ( pit.hasNext() ){ |
148 | | Path path = new Path(); |
149 | | path.setStartClass(startClass); |
150 | | List<ClassLink> crrpath = pit.next(); |
151 | | path.setClassLinks(crrpath); |
152 | | ListIterator<ClassLink> cit = crrpath.listIterator(); |
153 | | int min = Integer.MAX_VALUE; |
154 | | while ( cit.hasNext() ){ |
155 | | ClassLink cl = cit.next(); |
156 | | if ( cl.getNumOfLinks() < min ){ |
157 | | min = cl.getNumOfLinks(); |
158 | | } |
159 | | } |
160 | | path.setWidth(min); |
161 | | sortedpath.add(path); |
162 | | j++; |
163 | | } |
164 | | Path[] patharray = new Path[paths.size()]; |
165 | | Iterator<Path> pait = sortedpath.descendingIterator(); |
166 | | int i = 0; |
167 | | while ( pait.hasNext() ){ |
168 | | patharray[i] = pait.next(); |
169 | | i++; |
170 | | } |
171 | | return patharray; |
172 | | } |
| 148 | // tmp |
| 149 | if ( i >= 1 ){ |
| 150 | int wn = nodeweight.get(crrnode); |
| 151 | int in = edgeweight.get(crrpath.get(crrpath.size()-2)).get(crrnode); |
| 152 | int out = edgeweight.get(nextnode).get(crrnode); |
| 153 | if ( wn > in + out ){ |
| 154 | /* |
| 155 | String key1 = nextnode.toString().concat("-").concat(crrpath.get(crrpath.size()-1).toString()) |
| 156 | .concat("-").concat(crrpath.get(crrpath.size()-2).toString()); |
| 157 | String key2 = crrpath.get(crrpath.size()-2).toString().concat("-").concat(crrpath.get(crrpath.size()-1).toString()) |
| 158 | .concat("-").concat(nextnode.toString()); |
| 159 | if ( checkedpaths.containsKey(key1) ){ |
| 160 | if ( checkedpaths.get(key1) == false ){ |
| 161 | continue; |
| 162 | } |
| 163 | }else if ( checkedpaths.containsKey(key2) ){ |
| 164 | if ( checkedpaths.get(key2) == false ){ |
| 165 | continue; |
| 166 | } |
| 167 | }else{ |
| 168 | boolean chk = EndpointAccess.check3SimplePathwithJoin(nextnode, crrpath.get(crrpath.size()-1), |
| 169 | crrpath.get(crrpath.size()-2), this, sparqlEndpoint); |
| 170 | checkedpaths.put(key1, chk); |
| 171 | if ( chk == false ){ |
| 172 | continue; |
| 173 | } |
| 174 | } |
| 175 | */ |
| 176 | continue; |
| 177 | } |
| 178 | } |
254 | | private List<List<ClassLink>> searchPaths(RDFSchemaAnalyzer rdfsa, boolean countLinks){ |
255 | | List<List<ClassLink>> paths = new ArrayList<>(); |
256 | | List<LinkAndPath> lp = new LinkedList<>(); |
257 | | lp.add(new LinkAndPath(new ClassLink("",startClass,null,Direction.both,0,0,0,0,0,false,false), new LinkedList<ClassLink>(), "")); |
258 | | try{ |
259 | | for ( int i = 0; i < nsteps; i++ ){ |
260 | | ListIterator<LinkAndPath> lit = lp.listIterator(); |
261 | | List<LinkAndPath> nextlp = new LinkedList<>(); |
262 | | while ( lit.hasNext() ){ |
263 | | LinkAndPath crrlp = lit.next(); |
264 | | ClassLink[] classLinks = rdfsa.getNextClass(null, crrlp.classLink.getLinkedClassURI(), limit, countLinks); |
265 | | for ( int j = 0 ; j < classLinks.length; j++ ){ |
266 | | List<ClassLink> crrpath = new LinkedList<>(crrlp.path); |
267 | | crrpath.add(classLinks[j]); |
268 | | if ( classLinks[j].getLinkedClassURI() == null ){ continue; } |
269 | | if ( classLinks[j].getLinkedClassURI().equals(endClass) ){ |
270 | | paths.add(new LinkedList<>(crrpath)); |
271 | | continue; |
272 | | } |
273 | | if ( countLinks == true && classLinks[j].getNumOfLinks() <= th){ |
274 | | continue; |
275 | | } |
276 | | if ( i >= 2 ){ |
277 | | if ( crrlp.classLink.getPropertyURI().equals(classLinks[j].getPropertyURI()) && |
278 | | crrlp.classLink.getDirection() != classLinks[j].getDirection() && |
279 | | crrlp.originalClassURI.equals( classLinks[j].getLinkedClassURI()) ){ |
280 | | continue; |
281 | | } |
282 | | } |
283 | | nextlp.add(new LinkAndPath(classLinks[j], crrpath, crrlp.classLink.getLinkedClassURI())); |
284 | | } |
285 | | } |
286 | | lp = nextlp; |
287 | | } |
288 | | }catch(Exception e){ |
289 | | System.err.println(e); |
290 | | } |
291 | | return paths; |
292 | | } |
293 | | */ |
294 | | |
417 | | if ( nn != null ){ |
418 | | addEdge(crr, nn, classLinks[j]); |
419 | | /* |
420 | | }else{ |
421 | | nn = labelednodes.get(classLinks[j].getLinkedLiteralDatatypeURI()); |
422 | | if ( nn == null ){ |
423 | | addNode(classLinks[j].getLinkedLiteralDatatypeURI()); |
424 | | n = nodeType.size(); |
425 | | nodeType.add("literal"); |
426 | | } |
427 | | addEdge(i, n, classLinks[j]); |
428 | | /* |
429 | | ClassLink rev = new ClassLink( classLinks[j].getPropertyURI(), |
430 | | //classLinks[j].getLinkedClassURI(), |
431 | | classes[i].getClassURI(), |
432 | | classLinks[j].getLinkedLiteralDatatypeURI(), |
433 | | classLinks[j].getDirection(), classLinks[j].getNumOfLinks(), |
434 | | classLinks[j].getNumOfOriginInstances(), classLinks[j].getNumOfLinkedInstances(), |
435 | | classLinks[j].getNumOfOriginClassInstances(), classLinks[j].getNumOfLinkedClassInstances(), |
436 | | classLinks[j].isDomainClassLimitedQ(), classLinks[j].isRangeClassLimitedQ() ); |
437 | | rev.setDirection(Direction.reverse); |
438 | | addEdge(n, i, rev); |
439 | | */ |
440 | | } |
| 367 | addEdge(crr, nn, classLinks[j]); |
| 368 | updateWeight(crr, nn, classLinks[j]); |
| 413 | |
| 414 | |
| 415 | private void updateWeight(Integer node1, Integer node2, ClassLink edge){ |
| 416 | Map<Integer, Integer> weight = edgeweight.get(node1); |
| 417 | Integer crr = weight.get(node2); |
| 418 | if (crr == null ){ |
| 419 | crr = edge.getNumOfLinkedClassInstances(); |
| 420 | weight.put(node2, crr); |
| 421 | } |
| 422 | if ( crr < edge.getNumOfLinkedClassInstances() ){ |
| 423 | crr = edge.getNumOfLinkedClassInstances(); |
| 424 | weight.put(node2, crr); |
| 425 | } |
| 426 | weight = edgeweight.get(node2); |
| 427 | crr = weight.get(node1); |
| 428 | if (crr == null ){ |
| 429 | crr = edge.getNumOfOriginClassInstances(); |
| 430 | weight.put(node2, crr); |
| 431 | } |
| 432 | if ( crr < edge.getNumOfOriginClassInstances() ){ |
| 433 | crr = edge.getNumOfOriginInstances(); |
| 434 | weight.put(node1, crr); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | // old codes |
| 439 | /* |
| 440 | public Path[] getPaths_old(RDFSchemaAnalyzer rdfsa, boolean countLink, String startClass, String endClass){ |
| 441 | List<List<ClassLink>> paths = null; |
| 442 | paths = searchPathsbyVisitingNodes(rdfsa, countLink, startClass, endClass); |
| 443 | NavigableSet<Path> sortedpath = new TreeSet<Path>(); |
| 444 | ListIterator<List<ClassLink>> pit = paths.listIterator(); |
| 445 | int j = 0; |
| 446 | while ( pit.hasNext() ){ |
| 447 | Path path = new Path(); |
| 448 | path.setStartClass(startClass); |
| 449 | List<ClassLink> crrpath = pit.next(); |
| 450 | path.setClassLinks(crrpath); |
| 451 | ListIterator<ClassLink> cit = crrpath.listIterator(); |
| 452 | int min = Integer.MAX_VALUE; |
| 453 | while ( cit.hasNext() ){ |
| 454 | ClassLink cl = cit.next(); |
| 455 | if ( cl.getNumOfLinks() < min ){ |
| 456 | min = cl.getNumOfLinks(); |
| 457 | } |
| 458 | } |
| 459 | path.setWidth(min); |
| 460 | sortedpath.add(path); |
| 461 | j++; |
| 462 | } |
| 463 | Path[] patharray = new Path[paths.size()]; |
| 464 | Iterator<Path> pait = sortedpath.descendingIterator(); |
| 465 | int i = 0; |
| 466 | while ( pait.hasNext() ){ |
| 467 | patharray[i] = pait.next(); |
| 468 | i++; |
| 469 | } |
| 470 | return patharray; |
| 471 | } |
| 472 | |
| 473 | private List<List<ClassLink>> searchPaths_old(String startClass, String endClass){ |
| 474 | |
| 475 | List<List<ClassLink>> paths = new ArrayList<>(); |
| 476 | List<List<Integer>> simplePaths = new LinkedList<>(); |
| 477 | Integer snode = labelednodes.get(startClass); |
| 478 | Integer enode = labelednodes.get(endClass); |
| 479 | List<List<Integer>> lp = new LinkedList<>(); |
| 480 | List<Integer> ini = new LinkedList<Integer>(); // initial path |
| 481 | ini.add(snode); |
| 482 | lp.add(ini); |
| 483 | for (int i = 0; i < nsteps; i++ ){ |
| 484 | ListIterator<List<Integer>> lit = lp.listIterator(); |
| 485 | List<List<Integer>> nextlp = new LinkedList<>(); |
| 486 | while ( lit.hasNext() ){ |
| 487 | List<Integer> crrpath = lit.next(); |
| 488 | Integer crrnode = crrpath.get(crrpath.size()-1); |
| 489 | Set<Integer> nexts = gadjlist.get(crrnode).keySet(); |
| 490 | Iterator<Integer> nit = nexts.iterator(); |
| 491 | while( nit.hasNext() ){ |
| 492 | Integer nextnode = nit.next(); |
| 493 | if ( crrpath.contains(nextnode) ){ continue; } |
| 494 | List<Integer> nextpath = new LinkedList<Integer>(crrpath); // copy |
| 495 | nextpath.add(nextnode); |
| 496 | if ( nextnode.equals(enode) ){ |
| 497 | simplePaths.add(nextpath); |
| 498 | continue; |
| 499 | } |
| 500 | nextlp.add(nextpath); |
| 501 | } |
| 502 | } |
| 503 | lp = nextlp; |
| 504 | } |
| 505 | |
| 506 | ListIterator<List<Integer>> pit = simplePaths.listIterator(); |
| 507 | while( pit.hasNext()){ |
| 508 | List<Integer> spath = pit.next(); |
| 509 | List<List<ClassLink>> convertedPaths = convertSimplePathToPaths(spath); |
| 510 | paths.addAll(convertedPaths); |
| 511 | } |
| 512 | return paths; |
| 513 | } |
| 514 | */ |
| 515 | /* |
| 516 | private List<List<ClassLink>> searchPaths(RDFSchemaAnalyzer rdfsa, boolean countLinks){ |
| 517 | List<List<ClassLink>> paths = new ArrayList<>(); |
| 518 | List<LinkAndPath> lp = new LinkedList<>(); |
| 519 | lp.add(new LinkAndPath(new ClassLink("",startClass,null,Direction.both,0,0,0,0,0,false,false), new LinkedList<ClassLink>(), "")); |
| 520 | try{ |
| 521 | for ( int i = 0; i < nsteps; i++ ){ |
| 522 | ListIterator<LinkAndPath> lit = lp.listIterator(); |
| 523 | List<LinkAndPath> nextlp = new LinkedList<>(); |
| 524 | while ( lit.hasNext() ){ |
| 525 | LinkAndPath crrlp = lit.next(); |
| 526 | ClassLink[] classLinks = rdfsa.getNextClass(null, crrlp.classLink.getLinkedClassURI(), limit, countLinks); |
| 527 | for ( int j = 0 ; j < classLinks.length; j++ ){ |
| 528 | List<ClassLink> crrpath = new LinkedList<>(crrlp.path); |
| 529 | crrpath.add(classLinks[j]); |
| 530 | if ( classLinks[j].getLinkedClassURI() == null ){ continue; } |
| 531 | if ( classLinks[j].getLinkedClassURI().equals(endClass) ){ |
| 532 | paths.add(new LinkedList<>(crrpath)); |
| 533 | continue; |
| 534 | } |
| 535 | if ( countLinks == true && classLinks[j].getNumOfLinks() <= th){ |
| 536 | continue; |
| 537 | } |
| 538 | if ( i >= 2 ){ |
| 539 | if ( crrlp.classLink.getPropertyURI().equals(classLinks[j].getPropertyURI()) && |
| 540 | crrlp.classLink.getDirection() != classLinks[j].getDirection() && |
| 541 | crrlp.originalClassURI.equals( classLinks[j].getLinkedClassURI()) ){ |
| 542 | continue; |
| 543 | } |
| 544 | } |
| 545 | nextlp.add(new LinkAndPath(classLinks[j], crrpath, crrlp.classLink.getLinkedClassURI())); |
| 546 | } |
| 547 | } |
| 548 | lp = nextlp; |
| 549 | } |
| 550 | }catch(Exception e){ |
| 551 | System.err.println(e); |
| 552 | } |
| 553 | return paths; |
| 554 | } |
| 555 | */ |
| 556 | |