/** * CACHED ! Be careful modification of RelTypes requires cache clearing * * @param a * @param b * @param weightingScheme * @return the shortest path between the two classes considering the given * weighting scheme. * @throws SLIB_Ex_Critic */ public double getShortestPath(URI a, URI b, GWS weightingScheme) throws SLIB_Ex_Critic { if (cache.shortestPath.get(a) == null || cache.shortestPath.get(a).get(b) == null) { if (cache.shortestPath.get(a) == null) { cache.shortestPath.put(a, new ConcurrentHashMap<URI, Double>()); } WalkConstraint wc = WalkConstraintUtils.copy(ancGetter.getWalkConstraint()); wc.addWalkconstraints(descGetter.getWalkConstraint()); Dijkstra dijkstra = new Dijkstra(graph, wc, weightingScheme); double sp = dijkstra.shortestPath(a, b); cache.shortestPath.get(a).put(b, sp); } return cache.shortestPath.get(a).get(b); }
/** * Get the parents of a class, that is to say its direct ancestors. * * <br/><b>Important</b>:<br/> * * The direct parent of a class are all classes x linked to the given class * c to a an edge x RDFS.SUBLASSOF c. The result is not cached by the * engine. To ensure result coherency the underlying requires to be * transitively reduced, refer to the class documentation for more * information. * * @param v the focus vertex * @return the set of parents of the given vertex */ public Set<URI> getParents(URI v) { throwErrorIfNotClass(v); Set<URI> parents = graph.getV(v, ancGetter.getWalkConstraint()); return parents; }
Set<URI> roots = new ValidatorDAG().getDAGRoots(graph, ancGetter.getWalkConstraint()); DFS dfs = new DFS(graph, roots, WalkConstraintUtils.getInverse(ancGetter.getWalkConstraint(), (false))); List<URI> topoOrdering = dfs.getTraversalOrder(); for (E e : graph.getE(c, ancGetter.getWalkConstraint())) {
/** * CACHED * * @param a * @param weightingScheme * @return a map containing the weight of the shortest path linking a the * given vertex. * * @throws SLIB_Ex_Critic */ public synchronized Map<URI, Double> getAllShortestPath(URI a, GWS weightingScheme) throws SLIB_Ex_Critic { if (cache.shortestPath.get(a) == null) { WalkConstraint wc = WalkConstraintUtils.copy(ancGetter.getWalkConstraint()); wc.addWalkconstraints(descGetter.getWalkConstraint()); Dijkstra dijkstra = new Dijkstra(graph, wc, weightingScheme); ConcurrentHashMap<URI, Double> minDists_cA = dijkstra.shortestPath(a); cache.shortestPath.put(a, minDists_cA); } return cache.shortestPath.get(a); }
/** * NOT_CACHED * * @param a * @param b * @param weightingScheme * @return the URI associated to the Most Specific Ancestor. * @throws SLIB_Ex_Critic */ public URI getMSA(URI a, URI b, GWS weightingScheme) throws SLIB_Ex_Critic { Dijkstra dijkstra = new Dijkstra(graph, ancGetter.getWalkConstraint(), weightingScheme); URI msa_pk = SimDagEdgeUtils.getMSA_pekar_staab(getRoot(), getAllShortestPath(a, weightingScheme), getAllShortestPath(b, weightingScheme), getAncestorsInc(a), getAncestorsInc(b), dijkstra); return msa_pk; }