| 1 | /* |
|---|
| 2 | * To change this template, choose Tools | Templates |
|---|
| 3 | * and open the template in the editor. |
|---|
| 4 | */ |
|---|
| 5 | package org.biohackathon.SPARQLBuilder.OWL; |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * |
|---|
| 9 | * @author atsuko |
|---|
| 10 | */ |
|---|
| 11 | import java.util.*; |
|---|
| 12 | |
|---|
| 13 | public class OWLClassGraph extends LabeledMultiDigraph{ |
|---|
| 14 | //String startClass; |
|---|
| 15 | //String endClass; |
|---|
| 16 | int nsteps = 4; |
|---|
| 17 | int limit = 100; |
|---|
| 18 | int th = 1; |
|---|
| 19 | List<String> nodeType; |
|---|
| 20 | ArrayList<HashSet<Integer>> connectionTable; |
|---|
| 21 | |
|---|
| 22 | public class LinkAndPath{ |
|---|
| 23 | String originalClassURI; // originalClasssURI -classLink.propertyURI-> classLink.linkedClassURL |
|---|
| 24 | ClassLink classLink; |
|---|
| 25 | List<ClassLink> path; |
|---|
| 26 | Set<String> classURIs; // apearing class URIs in the path |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | public LinkAndPath(ClassLink classLink, List<ClassLink> path){ |
|---|
| 30 | this.classLink = classLink; |
|---|
| 31 | this.path = path; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | public LinkAndPath(ClassLink classLink, List<ClassLink> path, String originalClassURI){ |
|---|
| 35 | this.classLink = classLink; |
|---|
| 36 | this.path = path; |
|---|
| 37 | this.originalClassURI = originalClassURI; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | public LinkAndPath(ClassLink classLink, List<ClassLink> path, String originalClassURI, Set<String> classURIs){ |
|---|
| 41 | this.classLink = classLink; |
|---|
| 42 | this.path = path; |
|---|
| 43 | this.originalClassURI = originalClassURI; |
|---|
| 44 | this.classURIs = classURIs; |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /* |
|---|
| 49 | public OWLClassGraph(String startClass, String endClass){ |
|---|
| 50 | super(); |
|---|
| 51 | |
|---|
| 52 | // start & end |
|---|
| 53 | this.startClass = startClass; |
|---|
| 54 | this.endClass = endClass; |
|---|
| 55 | |
|---|
| 56 | // parameters |
|---|
| 57 | nsteps = 3; |
|---|
| 58 | limit = 1000; |
|---|
| 59 | th = 5; |
|---|
| 60 | } |
|---|
| 61 | */ |
|---|
| 62 | |
|---|
| 63 | /* |
|---|
| 64 | public OWLClassGraph(String startClass, String endClass, int th){ |
|---|
| 65 | super(); |
|---|
| 66 | |
|---|
| 67 | // start & end |
|---|
| 68 | this.startClass = startClass; |
|---|
| 69 | this.endClass = endClass; |
|---|
| 70 | // th of instances |
|---|
| 71 | this.th = th; |
|---|
| 72 | |
|---|
| 73 | // parameters |
|---|
| 74 | nsteps = 3; |
|---|
| 75 | limit = 1000; |
|---|
| 76 | } |
|---|
| 77 | */ |
|---|
| 78 | |
|---|
| 79 | public OWLClassGraph(){ |
|---|
| 80 | super(); |
|---|
| 81 | nodeType = new LinkedList<String>(); |
|---|
| 82 | //setClassGraph(rdfsa); |
|---|
| 83 | //connectionTable = createConnectionTable(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | public OWLClassGraph(RDFSchemaAnalyzer rdfsa){ |
|---|
| 88 | super(); |
|---|
| 89 | nodeType = new LinkedList<String>(); |
|---|
| 90 | //setClassGraph(rdfsa); |
|---|
| 91 | //connectionTable = createConnectionTable(); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | public int getNumberOfEdge(String url){ |
|---|
| 95 | Integer node = labelednodes.get(url); |
|---|
| 96 | if (node == null){ |
|---|
| 97 | return 0; |
|---|
| 98 | } |
|---|
| 99 | return adjlist.get(node).size(); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | public Path[] getPaths(String startClass, String endClass){ |
|---|
| 103 | List<List<ClassLink>> paths = searchPaths(startClass, endClass); |
|---|
| 104 | |
|---|
| 105 | NavigableSet<Path> sortedpath = new TreeSet<Path>(); |
|---|
| 106 | ListIterator<List<ClassLink>> pit = paths.listIterator(); |
|---|
| 107 | int j = 0; |
|---|
| 108 | while ( pit.hasNext() ){ |
|---|
| 109 | Path path = new Path(); |
|---|
| 110 | path.setStartClass(startClass); |
|---|
| 111 | List<ClassLink> crrpath = pit.next(); |
|---|
| 112 | path.setClassLinks(crrpath); |
|---|
| 113 | ListIterator<ClassLink> cit = crrpath.listIterator(); |
|---|
| 114 | int min = Integer.MAX_VALUE; |
|---|
| 115 | while ( cit.hasNext() ){ |
|---|
| 116 | ClassLink cl = cit.next(); |
|---|
| 117 | if ( cl.getNumOfLinks() < min ){ |
|---|
| 118 | min = cl.getNumOfLinks(); |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | // using length of path |
|---|
| 122 | int rankwidth = (int) ( ( min * nsteps )/ crrpath.size() ); |
|---|
| 123 | path.setWidth(rankwidth); |
|---|
| 124 | sortedpath.add(path); |
|---|
| 125 | j++; |
|---|
| 126 | } |
|---|
| 127 | Path[] patharray = new Path[paths.size()]; |
|---|
| 128 | Iterator<Path> pait = sortedpath.descendingIterator(); |
|---|
| 129 | int i = 0; |
|---|
| 130 | while ( pait.hasNext() ){ |
|---|
| 131 | patharray[i] = pait.next(); |
|---|
| 132 | i++; |
|---|
| 133 | } |
|---|
| 134 | return patharray; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public HashSet<Integer> getConnectionList(Integer node){ |
|---|
| 138 | return connectionTable.get(node); |
|---|
| 139 | } |
|---|
| 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 | } |
|---|
| 173 | |
|---|
| 174 | private List<List<ClassLink>> searchPaths(String startClass, String endClass){ |
|---|
| 175 | |
|---|
| 176 | List<List<ClassLink>> paths = new ArrayList<>(); |
|---|
| 177 | List<List<Integer>> simplePaths = new LinkedList<>(); |
|---|
| 178 | Integer snode = labelednodes.get(startClass); |
|---|
| 179 | Integer enode = labelednodes.get(endClass); |
|---|
| 180 | List<List<Integer>> lp = new LinkedList<>(); |
|---|
| 181 | List<Integer> ini = new LinkedList<Integer>(); // initial path |
|---|
| 182 | ini.add(snode); |
|---|
| 183 | lp.add(ini); |
|---|
| 184 | for (int i = 0; i < nsteps; i++ ){ |
|---|
| 185 | ListIterator<List<Integer>> lit = lp.listIterator(); |
|---|
| 186 | List<List<Integer>> nextlp = new LinkedList<>(); |
|---|
| 187 | while ( lit.hasNext() ){ |
|---|
| 188 | List<Integer> crrpath = lit.next(); |
|---|
| 189 | Integer crrnode = crrpath.get(crrpath.size()-1); |
|---|
| 190 | Set<Integer> nexts = gadjlist.get(crrnode).keySet(); |
|---|
| 191 | Iterator<Integer> nit = nexts.iterator(); |
|---|
| 192 | while( nit.hasNext() ){ |
|---|
| 193 | Integer nextnode = nit.next(); |
|---|
| 194 | if ( crrpath.contains(nextnode) ){ continue; } |
|---|
| 195 | List<Integer> nextpath = new LinkedList<Integer>(crrpath); // copy |
|---|
| 196 | nextpath.add(nextnode); |
|---|
| 197 | if ( nextnode.equals(enode) ){ |
|---|
| 198 | simplePaths.add(nextpath); |
|---|
| 199 | continue; |
|---|
| 200 | } |
|---|
| 201 | nextlp.add(nextpath); |
|---|
| 202 | } |
|---|
| 203 | } |
|---|
| 204 | lp = nextlp; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | ListIterator<List<Integer>> pit = simplePaths.listIterator(); |
|---|
| 208 | while( pit.hasNext()){ |
|---|
| 209 | List<Integer> spath = pit.next(); |
|---|
| 210 | List<List<ClassLink>> convertedPaths = convertSimplePathToPaths(spath); |
|---|
| 211 | paths.addAll(convertedPaths); |
|---|
| 212 | } |
|---|
| 213 | return paths; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | private List<List<ClassLink>> convertSimplePathToPaths(List<Integer> simplePath){ |
|---|
| 217 | List<List<ClassLink>> paths = new LinkedList<List<ClassLink>>(); |
|---|
| 218 | //List<List<LabeledEdge>> multiedges = new LinkedList<List<LabeledEdge>>(); |
|---|
| 219 | ListIterator<Integer> spit = simplePath.listIterator(); |
|---|
| 220 | Integer start = spit.next(); |
|---|
| 221 | Integer end = spit.next(); |
|---|
| 222 | List<LabeledEdge> edges = gadjlist.get(start).get(end); |
|---|
| 223 | ListIterator<LabeledEdge> eit = edges.listIterator(); |
|---|
| 224 | while ( eit.hasNext() ){ |
|---|
| 225 | List<ClassLink> cl = new LinkedList<ClassLink>(); |
|---|
| 226 | cl.add((ClassLink)eit.next().getLabel()); |
|---|
| 227 | paths.add(cl); |
|---|
| 228 | } |
|---|
| 229 | start = end; |
|---|
| 230 | while( spit.hasNext() ){ |
|---|
| 231 | end = spit.next(); |
|---|
| 232 | // start-end |
|---|
| 233 | edges = gadjlist.get(start).get(end); |
|---|
| 234 | List<List<ClassLink>> tmppaths = new LinkedList<List<ClassLink>>(); |
|---|
| 235 | // current path |
|---|
| 236 | ListIterator<List<ClassLink>> pit = paths.listIterator(); |
|---|
| 237 | while ( pit.hasNext() ){ |
|---|
| 238 | List<ClassLink> basepath = pit.next(); |
|---|
| 239 | eit = edges.listIterator(); |
|---|
| 240 | while ( eit.hasNext() ){ |
|---|
| 241 | ClassLink cl = (ClassLink) eit.next().label; |
|---|
| 242 | List<ClassLink> addedpath = new LinkedList<ClassLink>(basepath); |
|---|
| 243 | addedpath.add(cl); |
|---|
| 244 | tmppaths.add(addedpath); |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | paths = tmppaths; |
|---|
| 248 | start = end; |
|---|
| 249 | } |
|---|
| 250 | return paths; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | /* |
|---|
| 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 | |
|---|
| 295 | private List<List<ClassLink>> searchPathsbyVisitingNodes(RDFSchemaAnalyzer rdfsa, boolean countLinks, |
|---|
| 296 | String startClass, String endClass){ |
|---|
| 297 | List<List<ClassLink>> paths = new ArrayList<>(); |
|---|
| 298 | List<LinkAndPath> lp = new LinkedList<>(); |
|---|
| 299 | Set<String> urls = new HashSet<String>(); |
|---|
| 300 | urls.add(startClass); |
|---|
| 301 | lp.add(new LinkAndPath(new ClassLink("",startClass,null,Direction.both,0,0,0,0,0,false,false), |
|---|
| 302 | new LinkedList<ClassLink>(), startClass, urls)); |
|---|
| 303 | try{ |
|---|
| 304 | for ( int i = 0; i < nsteps; i++ ){ |
|---|
| 305 | ListIterator<LinkAndPath> lit = lp.listIterator(); |
|---|
| 306 | List<LinkAndPath> nextlp = new LinkedList<>(); |
|---|
| 307 | while ( lit.hasNext() ){ |
|---|
| 308 | LinkAndPath crrlp = lit.next(); |
|---|
| 309 | ClassLink[] classLinks = rdfsa.getNextClass(null, crrlp.classLink.getLinkedClassURI(), limit, countLinks); |
|---|
| 310 | // limit |
|---|
| 311 | for ( int j = 0 ; j < classLinks.length; j++ ){ |
|---|
| 312 | if (crrlp.classURIs.contains(classLinks[j].getLinkedClassURI()) ){ |
|---|
| 313 | continue; // visited |
|---|
| 314 | } |
|---|
| 315 | List<ClassLink> crrpath = new LinkedList<>(crrlp.path); |
|---|
| 316 | crrpath.add(classLinks[j]); |
|---|
| 317 | Set<String> crrurls = new HashSet<String>(crrlp.classURIs); |
|---|
| 318 | crrurls.add(classLinks[j].getLinkedClassURI()); |
|---|
| 319 | if ( classLinks[j].getLinkedClassURI() == null ){ continue; } |
|---|
| 320 | if ( classLinks[j].getNumOfLinks() <= th){ |
|---|
| 321 | continue; |
|---|
| 322 | } |
|---|
| 323 | if ( classLinks[j].getLinkedClassURI().equals(endClass) ){ |
|---|
| 324 | paths.add(new LinkedList<>(crrpath)); |
|---|
| 325 | continue; |
|---|
| 326 | } |
|---|
| 327 | //crrlp.classURIs.add() |
|---|
| 328 | nextlp.add(new LinkAndPath(classLinks[j], crrpath, crrlp.classLink.getLinkedClassURI(),crrurls)); |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | lp = nextlp; |
|---|
| 332 | } |
|---|
| 333 | }catch(Exception e){ |
|---|
| 334 | System.err.println(e); |
|---|
| 335 | } |
|---|
| 336 | return paths; |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | private void setClassGraph(RDFSchemaAnalyzer rdfsa){ |
|---|
| 340 | // setNodes |
|---|
| 341 | SClass[] classes = null; |
|---|
| 342 | try{ |
|---|
| 343 | classes = rdfsa.getOWLClasses(null, null, null, true); |
|---|
| 344 | }catch(Exception e){ |
|---|
| 345 | System.err.println(e); return; |
|---|
| 346 | } |
|---|
| 347 | for (int i = 0 ; i < classes.length; i++){ |
|---|
| 348 | addNode(classes[i].getClassURI()); |
|---|
| 349 | nodeType.add("class"); |
|---|
| 350 | } |
|---|
| 351 | // setEdges |
|---|
| 352 | for (int i = 0 ; i < classes.length; i++ ){ |
|---|
| 353 | try{ |
|---|
| 354 | ClassLink[] classLinks = rdfsa.getNextClass(null, classes[i].getClassURI(), limit, true); |
|---|
| 355 | for (int j = 0 ; j < classLinks.length; j++){ |
|---|
| 356 | Integer n = labelednodes.get(classLinks[j].getLinkedClassURI()); |
|---|
| 357 | if ( n != null ){ |
|---|
| 358 | addEdge(i, n, classLinks[j]); |
|---|
| 359 | }else{ |
|---|
| 360 | n = labelednodes.get(classLinks[j].getLinkedLiteralDatatypeURI()); |
|---|
| 361 | if ( n == null ){ |
|---|
| 362 | addNode(classLinks[j].getLinkedLiteralDatatypeURI()); |
|---|
| 363 | n = nodeType.size(); |
|---|
| 364 | nodeType.add("literal"); |
|---|
| 365 | } |
|---|
| 366 | addEdge(i, n, classLinks[j]); |
|---|
| 367 | /* |
|---|
| 368 | ClassLink rev = new ClassLink( classLinks[j].getPropertyURI(), |
|---|
| 369 | //classLinks[j].getLinkedClassURI(), |
|---|
| 370 | classes[i].getClassURI(), |
|---|
| 371 | classLinks[j].getLinkedLiteralDatatypeURI(), |
|---|
| 372 | classLinks[j].getDirection(), classLinks[j].getNumOfLinks(), |
|---|
| 373 | classLinks[j].getNumOfOriginInstances(), classLinks[j].getNumOfLinkedInstances(), |
|---|
| 374 | classLinks[j].getNumOfOriginClassInstances(), classLinks[j].getNumOfLinkedClassInstances(), |
|---|
| 375 | classLinks[j].isDomainClassLimitedQ(), classLinks[j].isRangeClassLimitedQ() ); |
|---|
| 376 | rev.setDirection(Direction.reverse); |
|---|
| 377 | addEdge(n, i, rev); |
|---|
| 378 | */ |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | }catch(Exception e){ |
|---|
| 382 | System.err.println(e); |
|---|
| 383 | } |
|---|
| 384 | } |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | public void setPartClassGraph(RDFSchemaAnalyzer rdfsa, String startClass){ |
|---|
| 388 | // setNodes |
|---|
| 389 | SClass[] classes = null; |
|---|
| 390 | try{ |
|---|
| 391 | classes = rdfsa.getOWLClasses(null, null, null, true); |
|---|
| 392 | }catch(Exception e){ |
|---|
| 393 | System.err.println(e); return; |
|---|
| 394 | } |
|---|
| 395 | for (int i = 0 ; i < classes.length; i++){ |
|---|
| 396 | addNode(classes[i].getClassURI()); |
|---|
| 397 | nodeType.add("class"); |
|---|
| 398 | } |
|---|
| 399 | int nedge = 0; |
|---|
| 400 | Integer snode = labelednodes.get(startClass); |
|---|
| 401 | Set<Integer> nodes = new HashSet<Integer>(); |
|---|
| 402 | nodes.add(snode); |
|---|
| 403 | Set<Integer> visited = new HashSet<Integer>(); |
|---|
| 404 | for (int i = 0 ; i < nsteps; i++ ){ |
|---|
| 405 | Iterator<Integer> nit = nodes.iterator(); |
|---|
| 406 | Set<Integer> nextnodes = new HashSet<Integer>(); |
|---|
| 407 | while ( nit.hasNext() ){ |
|---|
| 408 | Integer crr = nit.next(); |
|---|
| 409 | visited.add(crr); |
|---|
| 410 | try{ |
|---|
| 411 | ClassLink[] classLinks = rdfsa.getNextClass(null, labels.get(crr), limit, true); |
|---|
| 412 | for (int j = 0 ; j < classLinks.length; j++){ |
|---|
| 413 | Integer nn = labelednodes.get(classLinks[j].getLinkedClassURI()); |
|---|
| 414 | if ( !visited.contains(nn) ){ |
|---|
| 415 | nextnodes.add(nn); |
|---|
| 416 | } |
|---|
| 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 | } |
|---|
| 441 | } |
|---|
| 442 | }catch(Exception e){ |
|---|
| 443 | e.printStackTrace(); |
|---|
| 444 | } |
|---|
| 445 | } |
|---|
| 446 | nodes = nextnodes; |
|---|
| 447 | } |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | private ArrayList<HashSet<Integer>> createConnectionTable(){ |
|---|
| 451 | ArrayList<HashSet<Integer>> ct = new ArrayList<HashSet<Integer>>(); |
|---|
| 452 | for (int i = 0; i < labels.size(); i++ ){ // each node |
|---|
| 453 | HashSet<Integer> cl = createConnectionList(i); |
|---|
| 454 | ct.add(cl); |
|---|
| 455 | } |
|---|
| 456 | return ct; |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | private HashSet<Integer> createConnectionList(Integer node){ |
|---|
| 460 | HashSet<Integer> cl = new HashSet<Integer>(); |
|---|
| 461 | HashSet<Integer> crrnodes = new HashSet<Integer>(); |
|---|
| 462 | crrnodes.add(node); |
|---|
| 463 | cl.add(node); |
|---|
| 464 | for ( int i = 0 ; i < nsteps; i++ ){ |
|---|
| 465 | Set<Integer> nextnodes = new HashSet<Integer>(); |
|---|
| 466 | Iterator<Integer> cit = crrnodes.iterator(); |
|---|
| 467 | while ( cit.hasNext() ){ |
|---|
| 468 | Integer crr = cit.next(); |
|---|
| 469 | Set<Integer> nexts = gadjlist.get(crr).keySet(); |
|---|
| 470 | Iterator<Integer> nit = nexts.iterator(); |
|---|
| 471 | while ( nit.hasNext() ){ |
|---|
| 472 | Integer next = nit.next(); |
|---|
| 473 | if ( !cl.contains(next) ){ |
|---|
| 474 | nextnodes.add(next); |
|---|
| 475 | cl.add(next); |
|---|
| 476 | } |
|---|
| 477 | } |
|---|
| 478 | } |
|---|
| 479 | crrnodes.clear(); |
|---|
| 480 | crrnodes.addAll(nextnodes); |
|---|
| 481 | } |
|---|
| 482 | return cl; |
|---|
| 483 | } |
|---|
| 484 | } |
|---|