public class Taxonomy<T> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected TaxonomyNode<T> |
bottomNode |
protected short |
depth |
static Logger |
log |
protected Map<T,TaxonomyNode<T>> |
nodes |
static boolean |
TOP_DOWN |
protected TaxonomyNode<T> |
topNode |
protected int |
totalBranching |
| Constructor and Description |
|---|
Taxonomy() |
Taxonomy(Collection<T> elements,
T top,
T bottom) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEquivalentNode(T t,
TaxonomyNode<T> node) |
void |
addEquivalents(T t,
Collection<T> eqs)
Add a collection of elements equivalent to an element already in the
taxonomy.
|
TaxonomyNode<T> |
addNode(Collection<T> equivalents,
Collection<T> sups,
Collection<T> subs,
boolean hidden)
Add a node with known supers and subs.
|
TaxonomyNode<T> |
addNode(T t,
boolean hidden) |
void |
addSuper(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,
Collection<T> sups)
Add a collection of supers to an element
|
void |
assertValid() |
List<T> |
computeLCA(List<T> list)
Given a list of concepts, find all the Least Common Ancestors (LCA).
|
boolean |
contains(T t) |
Iterator<Map.Entry<Set<T>,Object>> |
datumEquivalentsPair(Object key)
Iterate over nodes in taxonomy (no specific order)returning pair of
equivalence set and datum associated with
key for each. |
Iterator<Object> |
depthFirstDatumOnly(T t,
Object key)
Iterate down taxonomy in a depth first traversal, beginning with class
c, returning only datum associated with key for each. |
Set<T> |
getAllEquivalents(T t)
Returns all the classes that are equivalent to class c.
|
TaxonomyNode<T> |
getBottom() |
Set<T> |
getClasses() |
Object |
getDatum(T t,
Object key)
Get datum on taxonomy elements associated with
key |
Set<T> |
getEquivalents(T t)
Returns all the classes that are equivalent to class c.
|
Set<T> |
getFlattenedSubs(T t,
boolean direct)
As in
getSubs(Object, boolean) except the return value is the
union of nested sets |
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) |
Collection<TaxonomyNode<T>> |
getNodes() |
Set<Set<T>> |
getSubs(T t)
Returns all the (named) subclasses of class c.
|
Set<Set<T>> |
getSubs(T t,
boolean direct)
Returns the (named) subclasses of class c.
|
Set<Set<T>> |
getSupers(T t)
Returns all the superclasses (implicitly or explicitly defined) of class
c.
|
Set<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) |
Object |
putDatum(T t,
Object key,
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
|
Object |
removeDatum(T t,
Object key) |
void |
resetSupers(T t,
Collection<T> supers)
Clear existing supers for an element and set to a new collection
|
List<T> |
topologocialSort(boolean includeEquivalents)
Sort the nodes in the taxonomy using topological ordering starting from
top to bottom.
|
List<T> |
topologocialSort(boolean includeEquivalents,
Comparator<? super T> comparator)
Sort the nodes in the taxonomy using topological ordering starting from
top to bottom.
|
public static final Logger log
public static final boolean TOP_DOWN
protected TaxonomyNode<T> bottomNode
protected Map<T,TaxonomyNode<T>> nodes
protected TaxonomyNode<T> topNode
protected short depth
protected int totalBranching
public Taxonomy()
public Taxonomy(Collection<T> elements, T top, T bottom)
public void addEquivalentNode(T t, TaxonomyNode<T> node)
public void addEquivalents(T t, Collection<T> eqs)
public TaxonomyNode<T> addNode(Collection<T> equivalents, Collection<T> sups, Collection<T> subs, boolean hidden)
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 notpublic TaxonomyNode<T> addNode(T t, boolean hidden)
public void addSuper(Collection<T> subs, T sup)
public void addSupers(T sub, Collection<T> sups)
public void assertValid()
public List<T> computeLCA(List<T> list)
public boolean contains(T t)
public Iterator<Map.Entry<Set<T>,Object>> datumEquivalentsPair(Object key)
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)key - key associated with datum returnedpublic Iterator<Object> depthFirstDatumOnly(T t, Object key)
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).t - starting location in taxonomykey - key associated with datum returnedpublic Set<T> getAllEquivalents(T t)
t - class whose equivalent classes are foundpublic TaxonomyNode<T> getBottom()
public Object getDatum(T t, Object key)
keyt - identifies the taxonomy elementkey - identifies the specific datumnull if none is associated with key)public Set<T> getEquivalents(T t)
t - class whose equivalent classes are foundpublic Set<T> getFlattenedSubs(T t, boolean direct)
getSubs(Object, boolean) except the return value is the
union of nested setspublic Set<T> getFlattenedSupers(T t, boolean direct)
getSupers(Object, boolean) except the return value is the
union of nested setspublic TaxonomyNode<T> getNode(T t)
public Collection<TaxonomyNode<T>> getNodes()
public Set<Set<T>> getSubs(T t)
t - class whose subclasses are returnedpublic Set<Set<T>> getSubs(T t, boolean direct)
t - Class whose subclasses are founddirect - If true return only direct subclasses elese return all the
subclassespublic Set<Set<T>> getSupers(T t)
t - class whose superclasses are returnedpublic Set<Set<T>> getSupers(T t, boolean direct)
t - Class whose subclasses are founddirect - If true return all the superclasses else return only direct
superclassespublic TaxonomyNode<T> getTop()
public Bool isEquivalent(T x, T y)
x - Name of the first classy - Name of the second classpublic Bool isSubNodeOf(T x, T y)
x - Name of the nodey - Name of the ancestor odepublic void merge(TaxonomyNode<T> node1, TaxonomyNode<T> node2)
public Object putDatum(T t, Object key, Object value)
key on a taxonomy elementt - identifies the taxonomy elementkey - identifies the datumvalue - the datumnull if not setpublic void remove(T t)
public void removeCycles(TaxonomyNode<T> node)
public void resetSupers(T t, Collection<T> supers)
public List<T> topologocialSort(boolean includeEquivalents)
includeEquivalents - If false the equivalents in a node will be ignored and only
the name of the node will be added to the resultpublic List<T> topologocialSort(boolean includeEquivalents, Comparator<? super T> comparator)
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 nodes at same level,
null if no special ordering is neededCopyright © 2019. All rights reserved.