Package openllet.core.taxonomy
Interface Taxonomy<T>
-
- Type Parameters:
T
- type of taxon
- All Superinterfaces:
openllet.shared.tools.Logging
- All Known Implementing Classes:
TaxonomyImpl
public interface Taxonomy<T> extends openllet.shared.tools.Logging
Definition of taxonomies- Since:
- 2.6.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
addEquivalentNode(T t, TaxonomyNode<T> node)
default void
addEquivalents(T t, java.util.Collection<T> eqs)
Add a collection of elements equivalent to an element already in the taxonomy.default TaxonomyNode<T>
addNode(java.util.Collection<T> equivalents, java.util.Collection<T> sups, java.util.Collection<T> subs, boolean hidden)
Add a node with known supers and subs.default TaxonomyNode<T>
addNode(T t, boolean hidden)
default void
addSuper(T sub, T sup)
Add a sub/super relationdefault void
addSupers(T sub, java.util.Collection<T> sups)
Add a collection of supers to an elementdefault void
assertValid()
default java.util.List<T>
computeLCA(java.util.List<T> list)
Given a list of concepts, find all the Least Common Ancestors (LCA).default boolean
contains(T t)
java.util.Iterator<java.util.Map.Entry<java.util.Set<T>,java.lang.Object>>
datumEquivalentsPair(TaxonomyUtils.TaxonomyKey key)
Iterate over getNodes() in taxonomy (no specific order)returning pair of equivalence set and datum associated withkey
for each.java.util.Iterator<java.lang.Object>
depthFirstDatumOnly(T t, TaxonomyUtils.TaxonomyKey key)
Iterate down taxonomy in a _depth first traversal, beginning with classc
, returning only datum associated with_key
for each.default java.util.Set<T>
getAllEquivalents(T t)
Returns all the classes that are equivalent to class c.TaxonomyNode<T>
getBottomNode()
default java.util.Set<T>
getClasses()
default java.lang.Object
getDatum(T t, TaxonomyUtils.TaxonomyKey key)
Get datum on taxonomy elements associated with_key
short
getDepth()
default java.util.Set<T>
getEquivalents(T t)
Returns all the classes that are equivalent to class c.java.util.Set<T>
getFlattenedSubs(T t, boolean direct)
As ingetSubs(Object, boolean)
except the return value is the union of nested setsjava.util.Set<T>
getFlattenedSupers(T t, boolean direct)
As ingetSupers(Object, boolean)
except the return value is the union of nested setsdefault TaxonomyNode<T>
getNode(T t)
java.util.Map<T,TaxonomyNode<T>>
getNodes()
default java.util.Set<java.util.Set<T>>
getSubs(T t)
Returns all the (named) subclasses of class c.java.util.Set<java.util.Set<T>>
getSubs(T t, boolean direct)
Returns the (named) subclasses of class c.default java.util.Set<java.util.Set<T>>
getSupers(T t)
Returns all the superclasses (implicitly or explicitly defined) of class c.java.util.Set<java.util.Set<T>>
getSupers(T t, boolean direct)
Returns the (named) superclasses of class c.default TaxonomyNode<T>
getTop()
TaxonomyNode<T>
getTopNode()
int
getTotalBranching()
default Bool
isEquivalent(T x, T y)
Checks if x is equivalent to ydefault Bool
isSubNodeOf(T x, T y)
Checks if x has an ancestor y.void
merge(TaxonomyNode<T> node1, TaxonomyNode<T> node2)
default java.lang.Object
putDatum(T t, TaxonomyUtils.TaxonomyKey key, java.lang.Object value)
Set a datum value associated withkey
on a taxonomy elementdefault void
remove(T t)
Remove an element from the taxonomy.void
removeCycles(TaxonomyNode<T> node)
Walk through the super getNodes() of the given _node and when a cycle is detected merge all the getNodes() in that pathdefault java.lang.Object
removeDatum(T t, TaxonomyUtils.TaxonomyKey key)
default void
resetSupers(T t, java.util.Collection<T> supers)
Clear existing supers for an element and set to a new collectionvoid
setBottomNode(TaxonomyNode<T> bottomNode)
void
setDepth(short depth)
void
setNodes(java.util.Map<T,TaxonomyNode<T>> nodes)
void
setTopNode(TaxonomyNode<T> topNode)
void
setTotalBranching(int totalBranching)
java.util.stream.Stream<java.util.Set<T>>
supers(T t, boolean direct)
default java.util.List<T>
topologocialSort(boolean includeEquivalents)
Sort the getNodes() in the taxonomy using topological ordering starting from top to bottom.default java.util.List<T>
topologocialSort(boolean includeEquivalents, java.util.Comparator<? super T> comparator)
Sort the getNodes() in the taxonomy using topological ordering starting from top to bottom.
-
-
-
Method Detail
-
getBottomNode
TaxonomyNode<T> getBottomNode()
-
setBottomNode
void setBottomNode(TaxonomyNode<T> bottomNode)
-
getTopNode
TaxonomyNode<T> getTopNode()
-
setTopNode
void setTopNode(TaxonomyNode<T> topNode)
-
getDepth
short getDepth()
-
setDepth
void setDepth(short depth)
-
getTotalBranching
int getTotalBranching()
-
setTotalBranching
void setTotalBranching(int totalBranching)
-
getNodes
java.util.Map<T,TaxonomyNode<T>> getNodes()
-
setNodes
void setNodes(java.util.Map<T,TaxonomyNode<T>> nodes)
-
addEquivalentNode
default void addEquivalentNode(T t, TaxonomyNode<T> node)
-
addEquivalents
default void addEquivalents(T t, java.util.Collection<T> eqs)
Add a collection of elements equivalent to an element already in the taxonomy.- Parameters:
t
-eqs
-
-
addNode
default TaxonomyNode<T> addNode(java.util.Collection<T> equivalents, java.util.Collection<T> sups, java.util.Collection<T> subs, boolean hidden)
Add a node with known supers and subs. Any direct relations between subs and supers are removed.- Parameters:
equivalents
- a non-empty set of equivalent elements defining the node (one of which becomes the label)sups
- collection of supers, all of which must already exist in the taxonomysubs
- collection of subs, all of which must already exist in the taxonomyhidden
- indicates hidden or not- Returns:
- the new node
-
addNode
default TaxonomyNode<T> addNode(T t, boolean hidden)
-
addSupers
default void addSupers(T sub, java.util.Collection<T> sups)
Add a collection of supers to an element- Parameters:
sub
-sups
-
-
assertValid
default void assertValid()
-
computeLCA
default java.util.List<T> computeLCA(java.util.List<T> list)
Given a list of concepts, find all the Least Common Ancestors (LCA). Note that a taxonomy is DAG not a tree so we do not have a unique LCA but a set of LCA.FIXME : does not work when one of the elements is an ancestor of the rest
TODO :
what to do with equivalent classes?
TODO :
improve efficiency
- Parameters:
list
-- Returns:
- the Least Common Ancestors
-
contains
default boolean contains(T t)
-
datumEquivalentsPair
java.util.Iterator<java.util.Map.Entry<java.util.Set<T>,java.lang.Object>> datumEquivalentsPair(TaxonomyUtils.TaxonomyKey key)
Iterate over getNodes() in taxonomy (no specific order)returning pair of equivalence set and datum associated withkey
for each. Useful, e.g., to collect equivalence sets matching some condition on the datum (as in all classes which have a particular instances)- Parameters:
key
- key associated with datum returned- Returns:
- iterator over equivalence set, datum pairs
-
depthFirstDatumOnly
java.util.Iterator<java.lang.Object> depthFirstDatumOnly(T t, TaxonomyUtils.TaxonomyKey key)
Iterate down taxonomy in a _depth first traversal, beginning with classc
, returning only datum associated with_key
for each. Useful, e.g., to collect datum values in a transitive closure (as in all instances of a class).- Parameters:
t
- starting location in taxonomykey
- _key associated with datum returned- Returns:
- datum iterator
-
getAllEquivalents
default java.util.Set<T> getAllEquivalents(T t)
Returns all the classes that are equivalent to class c. Class c itself is included in the result.- Parameters:
t
- class whose equivalent classes are found- Returns:
- A set of ATerm objects
-
getClasses
default java.util.Set<T> getClasses()
-
getDatum
default java.lang.Object getDatum(T t, TaxonomyUtils.TaxonomyKey key)
Get datum on taxonomy elements associated with_key
- Parameters:
t
- identifies the taxonomy elementkey
- identifies the specific datum- Returns:
- the datum (or
null
if none is associated with_key
)
-
getEquivalents
default java.util.Set<T> getEquivalents(T t)
Returns all the classes that are equivalent to class c. Class c itself is NOT included in the result.- Parameters:
t
- class whose equivalent classes are found- Returns:
- A set of ATerm objects
-
getFlattenedSubs
java.util.Set<T> getFlattenedSubs(T t, boolean direct)
As ingetSubs(Object, boolean)
except the return value is the union of nested sets- Parameters:
t
-direct
-- Returns:
- a union of subs
-
getFlattenedSupers
java.util.Set<T> getFlattenedSupers(T t, boolean direct)
As ingetSupers(Object, boolean)
except the return value is the union of nested sets- Parameters:
t
-direct
-- Returns:
- a union of supers
-
getNode
default TaxonomyNode<T> getNode(T t)
-
getSubs
default java.util.Set<java.util.Set<T>> getSubs(T t)
Returns all the (named) subclasses of class c. The class c itself is not included in the list but all the other classes that are equivalent to c are put into the list. Also note that the returned list will always have at least one element, that is the BOTTOM concept. By definition BOTTOM concept is subclass of every concept. This function is equivalent to calling getSubClasses(c, true).- Parameters:
t
- class whose subclasses are returned- Returns:
- A set of sets, where each set in the collection represents an equivalence class. The elements of the inner class are ATermAppl objects.
-
getSubs
java.util.Set<java.util.Set<T>> getSubs(T t, boolean direct)
Returns the (named) subclasses of class c. Depending on the second parameter the resulting list will include either all subclasses or only the direct subclasses. A class d is a direct subclass of c iff- d is subclass of c
- there is no other class x different from c and d such that x is subclass of c and d is subclass of x
- Parameters:
t
- Class whose subclasses are founddirect
- If true return only direct subclasses elese return all the subclasses- Returns:
- A set of sets, where each set in the collection represents an equivalence class. The elements of the inner class are ATermAppl objects.
-
getSupers
default java.util.Set<java.util.Set<T>> getSupers(T t)
Returns all the superclasses (implicitly or explicitly defined) of class c. The class c itself is not included in the list. but all the other classes that are sameAs c are put into the list. Also note that the returned list will always have at least one element, that is TOP concept. By definition TOP concept is superclass of every concept. This function is equivalent to calling getSuperClasses(c, true).- Parameters:
t
- class whose superclasses are returned- Returns:
- A set of sets, where each set in the collection represents an equivalence class. The elements of the inner class are ATermAppl objects.
-
getSupers
java.util.Set<java.util.Set<T>> getSupers(T t, boolean direct)
Returns the (named) superclasses of class c. Depending on the second parameter the resulting list will include either all or only the direct superclasses. A class d is a direct superclass of c iff- d is superclass of c
- there is no other class x such that x is superclass of c and d is superclass of x
- Parameters:
t
- Class whose subclasses are founddirect
- If true return all the superclasses else return only direct superclasses- Returns:
- A set of sets, where each set in the collection represents an equivalence class. The elements of the inner class are ATermAppl objects.
-
getTop
default TaxonomyNode<T> getTop()
-
isEquivalent
default Bool isEquivalent(T x, T y)
Checks if x is equivalent to y- Parameters:
x
- Name of the first classy
- Name of the second class- Returns:
- true if x is equivalent to y
-
isSubNodeOf
default Bool isSubNodeOf(T x, T y)
Checks if x has an ancestor y.- Parameters:
x
- Name of the _nodey
- Name of the ancestor ode- Returns:
- true if x has an ancestor y
-
merge
void merge(TaxonomyNode<T> node1, TaxonomyNode<T> node2)
-
putDatum
default java.lang.Object putDatum(T t, TaxonomyUtils.TaxonomyKey key, java.lang.Object value)
Set a datum value associated withkey
on a taxonomy element- Parameters:
t
- identifies the taxonomy elementkey
- identifies the datumvalue
- the datum- Returns:
- previous _value of datum or
null
if not set
-
remove
default void remove(T t)
Remove an element from the taxonomy.- Parameters:
t
-
-
removeCycles
void removeCycles(TaxonomyNode<T> node)
Walk through the super getNodes() of the given _node and when a cycle is detected merge all the getNodes() in that path- Parameters:
node
-
-
removeDatum
default java.lang.Object removeDatum(T t, TaxonomyUtils.TaxonomyKey key)
-
resetSupers
default void resetSupers(T t, java.util.Collection<T> supers)
Clear existing supers for an element and set to a new collection- Parameters:
t
-supers
-
-
topologocialSort
default java.util.List<T> topologocialSort(boolean includeEquivalents)
Sort the getNodes() in the taxonomy using topological ordering starting from top to bottom.- Parameters:
includeEquivalents
- If false the equivalents in a _node will be ignored and only the name of the _node will be added to the result- Returns:
- List of _node names sorted in topological ordering
-
topologocialSort
default java.util.List<T> topologocialSort(boolean includeEquivalents, java.util.Comparator<? super T> comparator)
Sort the getNodes() in the taxonomy using topological ordering starting from top to bottom.- Parameters:
includeEquivalents
- If false the equivalents in a node will be ignored and only the name of the _node will be added to the resultcomparator
- comparator to use sort the getNodes() at same level,null
if no special ordering is needed- Returns:
- List of node names sorted in topological ordering
-
-