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 | |