org.mindswap.pellet.taxonomy
Class Taxonomy<T>

java.lang.Object
  extended by org.mindswap.pellet.taxonomy.Taxonomy<T>

public class Taxonomy<T>
extends java.lang.Object

Author:
Evren Sirin

Field Summary
static java.util.logging.Logger log
           
static boolean TOP_DOWN
           
 
Constructor Summary
Taxonomy()
           
Taxonomy(java.util.Collection<T> elements, T top, T bottom)
           
 
Method Summary
 void addEquivalentNode(T t, TaxonomyNode<T> node)
           
 void addEquivalents(T t, java.util.Collection<T> eqs)
          Add a collection of elements equivalent to an element already in the taxonomy.
 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.
 TaxonomyNode<T> addNode(T t, boolean hidden)
           
 void addSuper(java.util.Collection<T> subs, T sup)
          Add a collection of elements as subs to an element
 void addSuper(T sub, T sup)
          Add a sub/super relation
 void addSupers(T sub, java.util.Collection<T> sups)
          Add a collection of supers to an element
 void assertValid()
           
 java.util.List<T> computeLCA(java.util.List<T> list)
          Given a list of concepts, find all the Least Common Ancestors (LCA).
 boolean contains(T t)
           
 java.util.Iterator<java.util.Map.Entry<java.util.Set<T>,java.lang.Object>> datumEquivalentsPair(java.lang.Object key)
          Iterate over nodes in taxonomy (no specific order)returning pair of equivalence set and datum associated with key for each.
 java.util.Iterator<java.lang.Object> depthFirstDatumOnly(T t, java.lang.Object key)
          Iterate down taxonomy in a depth first traversal, beginning with class c, returning only datum associated with key for each.
 java.util.Set<T> getAllEquivalents(T t)
          Returns all the classes that are equivalent to class c.
 TaxonomyNode<T> getBottom()
           
 java.util.Set<T> getClasses()
           
 java.lang.Object getDatum(T t, java.lang.Object key)
          Get datum on taxonomy elements associated with key
 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 in getSubs(Object, boolean) except the return value is the union of nested sets
 java.util.Set<T> getFlattenedSupers(T t, boolean direct)
          As in getSupers(Object, boolean) except the return value is the union of nested sets
 TaxonomyNode<T> getNode(T t)
           
 java.util.Collection<TaxonomyNode<T>> getNodes()
           
 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.
 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.
 TaxonomyNode<T> getTop()
           
 Bool isEquivalent(T x, T y)
          Checks if x is equivalent to y
 Bool isSubNodeOf(T x, T y)
          Checks if x has an ancestor y.
 void merge(TaxonomyNode<T> node1, TaxonomyNode<T> node2)
           
 java.lang.Object putDatum(T t, java.lang.Object key, java.lang.Object value)
          Set a datum value associated with key on a taxonomy element
 void remove(T t)
          Remove an element from the taxonomy.
 void removeCycles(TaxonomyNode<T> node)
          Walk through the super nodes of the given node and when a cycle is detected merge all the nodes in that path
 java.lang.Object removeDatum(T t, java.lang.Object key)
           
 void resetSupers(T t, java.util.Collection<T> supers)
          Clear existing supers for an element and set to a new collection
 java.util.List<T> topologocialSort(boolean includeEquivalents)
          Sort the nodes in the taxonomy using topological ordering starting from top to bottom.
 java.util.List<T> topologocialSort(boolean includeEquivalents, java.util.Comparator<? super T> comparator)
          Sort the nodes in the taxonomy using topological ordering starting from top to bottom.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final java.util.logging.Logger log

TOP_DOWN

public static final boolean TOP_DOWN
See Also:
Constant Field Values
Constructor Detail

Taxonomy

public Taxonomy()

Taxonomy

public Taxonomy(java.util.Collection<T> elements,
                T top,
                T bottom)
Method Detail

addEquivalentNode

public void addEquivalentNode(T t,
                              TaxonomyNode<T> node)

addEquivalents

public void addEquivalents(T t,
                           java.util.Collection<T> eqs)
Add a collection of elements equivalent to an element already in the taxonomy.


addNode

public 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

addNode

public TaxonomyNode<T> addNode(T t,
                               boolean hidden)

addSuper

public void addSuper(java.util.Collection<T> subs,
                     T sup)
Add a collection of elements as subs to an element


addSuper

public void addSuper(T sub,
                     T sup)
Add a sub/super relation


addSupers

public void addSupers(T sub,
                      java.util.Collection<T> sups)
Add a collection of supers to an element


assertValid

public void assertValid()

computeLCA

public 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.


contains

public boolean contains(T t)

datumEquivalentsPair

public java.util.Iterator<java.util.Map.Entry<java.util.Set<T>,java.lang.Object>> datumEquivalentsPair(java.lang.Object key)
Iterate over nodes 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

public java.util.Iterator<java.lang.Object> depthFirstDatumOnly(T t,
                                                                java.lang.Object 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

public 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

getBottom

public TaxonomyNode<T> getBottom()

getClasses

public java.util.Set<T> getClasses()

getDatum

public java.lang.Object getDatum(T t,
                                 java.lang.Object 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

public 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

public java.util.Set<T> getFlattenedSubs(T t,
                                         boolean direct)
As in getSubs(Object, boolean) except the return value is the union of nested sets


getFlattenedSupers

public java.util.Set<T> getFlattenedSupers(T t,
                                           boolean direct)
As in getSupers(Object, boolean) except the return value is the union of nested sets


getNode

public TaxonomyNode<T> getNode(T t)

getNodes

public java.util.Collection<TaxonomyNode<T>> getNodes()

getSubs

public 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

public 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

public 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

public 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.

getTop

public TaxonomyNode<T> getTop()

isEquivalent

public 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

public 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

merge

public void merge(TaxonomyNode<T> node1,
                  TaxonomyNode<T> node2)

putDatum

public java.lang.Object putDatum(T t,
                                 java.lang.Object 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

public void remove(T t)
Remove an element from the taxonomy.


removeCycles

public void removeCycles(TaxonomyNode<T> node)
Walk through the super nodes of the given node and when a cycle is detected merge all the nodes in that path


removeDatum

public java.lang.Object removeDatum(T t,
                                    java.lang.Object key)

resetSupers

public void resetSupers(T t,
                        java.util.Collection<T> supers)
Clear existing supers for an element and set to a new collection


topologocialSort

public java.util.List<T> topologocialSort(boolean includeEquivalents)
Sort the nodes 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

public java.util.List<T> topologocialSort(boolean includeEquivalents,
                                          java.util.Comparator<? super T> comparator)
Sort the nodes 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 nodes at same level, null if no special ordering is needed
Returns:
List of node names sorted in topological ordering


Copyright © 2004 Evren Sirin. All Rights Reserved.