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 Detail

      • setBottomNode

        void setBottomNode​(TaxonomyNode<T> bottomNode)
      • getDepth

        short getDepth()
      • setDepth

        void setDepth​(short depth)
      • getTotalBranching

        int getTotalBranching()
      • setTotalBranching

        void setTotalBranching​(int totalBranching)
      • 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 taxonomy
        subs - collection of subs, all of which must already exist in the taxonomy
        hidden - indicates hidden or not
        Returns:
        the new node
      • addSuper

        default void addSuper​(T sub,
                              T sup)
        Add a sub/super relation
        Parameters:
        sub -
        sup -
      • 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 with key 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 class c, 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 taxonomy
        key - _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 element
        key - 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 in getSubs(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 in getSupers(Object, boolean) except the return value is the union of nested sets
        Parameters:
        t -
        direct -
        Returns:
        a union of supers
      • 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
        1. d is subclass of c
        2. there is no other class x different from c and d such that x is subclass of c and d is subclass of x
        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. The list will either include one other concept from the hierarchy or the BOTTOM concept if no other class is subsumed by c. By definition BOTTOM concept is subclass of every concept.
        Parameters:
        t - Class whose subclasses are found
        direct - 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
        1. d is superclass of c
        2. there is no other class x such that x is superclass of c and d is superclass of x
        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. The list will either include one other concept from the hierarchy or the TOP concept if no other class subsumes c. By definition TOP concept is superclass of every concept.
        Parameters:
        t - Class whose subclasses are found
        direct - 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.
      • supers

        java.util.stream.Stream<java.util.Set<T>> supers​(T t,
                                                         boolean direct)
      • isEquivalent

        default Bool isEquivalent​(T x,
                                  T y)
        Checks if x is equivalent to y
        Parameters:
        x - Name of the first class
        y - 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 _node
        y - Name of the ancestor ode
        Returns:
        true if x has an ancestor y
      • putDatum

        default java.lang.Object putDatum​(T t,
                                          TaxonomyUtils.TaxonomyKey key,
                                          java.lang.Object value)
        Set a datum value associated with key on a taxonomy element
        Parameters:
        t - identifies the taxonomy element
        key - identifies the datum
        value - 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 -
      • 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 result
        comparator - 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