Package org.aksw.jenax.util.traversal
Class NaiveLCAFinder
java.lang.Object
org.aksw.jenax.util.traversal.NaiveLCAFinder
Note: The class and method names are aligned with jgrapht's NaiveLCAFinder. The difference is that
this class supports specification of a custom successor function for nodes.
(And this class only depends on jena's Graph)
Naive least common ancestor implementation. Does not perform any indexing or caching.
For a given pair of nodes for which to find the lca their respective sets of ancestors are
alternately expanded with their parents until there is an overlap or there are no more
unseen parents to expand.
Example Usage:
Example Usage:
Graph graph = model.getGraph(); GraphSuccessorFunction gsf = GraphSuccessorFunction.create(RDFS.subClassOf.asNode(), true); LeastCommonAncestor alg = new LeastCommonAncestor(graph, gsf); Setlcas = alg.getLeastCommonAncestor(XSD.nonNegativeInteger.asNode(), XSD.decimal.asNode());
- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.jena.graph.Graphprotected GraphSuccessorFunction -
Constructor Summary
ConstructorsConstructorDescriptionNaiveLCAFinder(org.apache.jena.graph.Graph graph) Find LCAs of rdfs:subClassOf as a reasonable defaultNaiveLCAFinder(org.apache.jena.graph.Graph graph, GraphSuccessorFunction successorFn) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> intcalcOverlap(Iterator<? extends T> it, Collection<T> seen, Collection<? extends T> col, Collection<T> out) Iterate items in 'it' and add each seen item to 'seen'.static <T> Set<T>computeLCA(T a, T b, Function<? super T, ? extends Stream<? extends T>> getParents) Generic core of the algorithmorg.apache.jena.graph.NodegetLCA(org.apache.jena.graph.Node a, org.apache.jena.graph.Node b) Returns the only LCA of a and b if it exists, null otherwise.Set<org.apache.jena.graph.Node>getLCASet(org.apache.jena.graph.Node a, org.apache.jena.graph.Node b) Get the least common ancestor (lca) of two given nodes w.r.t.static void
-
Field Details
-
graph
protected org.apache.jena.graph.Graph graph -
successorFn
-
-
Constructor Details
-
NaiveLCAFinder
public NaiveLCAFinder(org.apache.jena.graph.Graph graph) Find LCAs of rdfs:subClassOf as a reasonable default -
NaiveLCAFinder
-
-
Method Details
-
getLCASet
public Set<org.apache.jena.graph.Node> getLCASet(org.apache.jena.graph.Node a, org.apache.jena.graph.Node b) Get the least common ancestor (lca) of two given nodes w.r.t. a model and a hierarchy property.- Parameters:
a-b-- Returns:
-
getLCA
public org.apache.jena.graph.Node getLCA(org.apache.jena.graph.Node a, org.apache.jena.graph.Node b) Returns the only LCA of a and b if it exists, null otherwise. IllegalArgumentException if there are multiple lcas. -
computeLCA
public static <T> Set<T> computeLCA(T a, T b, Function<? super T, ? extends Stream<? extends T>> getParents) Generic core of the algorithm -
calcOverlap
public static <T> int calcOverlap(Iterator<? extends T> it, Collection<T> seen, Collection<? extends T> col, Collection<T> out) Iterate items in 'it' and add each seen item to 'seen'. For any item that is contained 'col' and that item also to 'out'. Return the number of items added to 'out'. -
main
-