net.sf.myra.datamining.data
Class ClassHierarchy

java.lang.Object
  extended by net.sf.myra.datamining.data.ClassHierarchy
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ClassHierarchy
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class represents a class hierarchy.

Version:
$Revision$ $Date:: $
Author:
Fernando Esteban Barril Otero
See Also:
Serialized Form

Field Summary
static java.lang.String RELATION
          Relationship separator between nodes of the hierarchy.
 
Constructor Summary
ClassHierarchy()
           
 
Method Summary
 Node add(java.lang.String label)
          Adds a new node to the class hierarchy.
 Node add(java.lang.String label, java.lang.String parent)
          Adds a new node to the class hierarchy as a child of the specified parent node.
 ClassHierarchy clone()
           
 boolean contains(java.lang.String label)
          Tests if the hierarchy contains a node with the specified label.
 Node find(java.lang.String label)
          Returns the node instance with the specified label.
 java.util.Collection<Node> flat()
          Returns the collection of all nodes labels.
 java.util.Collection<Node> getLeaves()
          Rerturns the collection of leaves of this class hierarchy.
 int getLevel(java.lang.String label)
          Returns the hierarchical level of the specified node.
 int getLevels()
          Returns the number of levels of the class hierarchy.
 Node getRoot()
           
 int getSize()
          Returns the number of nodes.
 boolean isEmpty()
          Tests if the hierarchy has no nodes.
 boolean isTree()
          Returns true if the class hierarchy is tree structured.
 java.lang.String leaf(java.util.Collection<java.lang.String> labels)
          Returns the label corresponding to the leaf node of the specified collection of class labels.
 java.lang.String leaf(java.lang.String... labels)
          Returns the label corresponding to the leaf node of the specified array of class labels.
 java.util.Collection<java.lang.String> leaves(java.util.Collection<java.lang.String> labels)
          Returns the leaves label of the specified collection of class labels.
 java.util.Collection<java.lang.String> leaves(java.lang.String... labels)
          Returns the leaves labels of the specified array of class labels.
 void link(Node parent, Node child)
          Links the specified parent-child nodes.
 void link(java.lang.String parent, java.lang.String child)
          Links the specified parent-child nodes.
 void remove(Node node)
          Removes the specified node from the class hierarchy.
 void remove(java.lang.String node)
          Removes the specified node from the class hierarchy.
 boolean shrink()
          Swaps the root node for its single child node.
 net.sf.myra.framework.Graph<net.sf.myra.framework.Info.Void> toGraph()
          Returns a Graph representation of the class hierarchy.
 java.lang.String toString()
           
 boolean unique()
          Checks if the class hierarchy has unique class label (i.e.
 void weigh()
          Computes the weights of all nodes of the hierarchy.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RELATION

public static final java.lang.String RELATION
Relationship separator between nodes of the hierarchy.

See Also:
Constant Field Values
Constructor Detail

ClassHierarchy

public ClassHierarchy()
Method Detail

isEmpty

public boolean isEmpty()
Tests if the hierarchy has no nodes.

Returns:
true if the hierarchy has no nodes; false otherwise.

getRoot

public Node getRoot()
Returns:
the root

add

public Node add(java.lang.String label)
Adds a new node to the class hierarchy.

Parameters:
label - the label of the node to be added.
Returns:
the node that was added to the class hierarchy.

add

public Node add(java.lang.String label,
                java.lang.String parent)
Adds a new node to the class hierarchy as a child of the specified parent node.

Parameters:
label - the label of the node to be added.
parent - the label of the parent node.
Returns:
the node that was added to the class hierarchy.

contains

public boolean contains(java.lang.String label)
Tests if the hierarchy contains a node with the specified label.

Parameters:
label - the node label.
Returns:
true is the hierarchy contains a node with the specified label; false otherwise.

getLevels

public int getLevels()
Returns the number of levels of the class hierarchy. Note that level information is only available for tree structures.

Returns:
the number of levels of the class hierarchy.

getLevel

public int getLevel(java.lang.String label)
Returns the hierarchical level of the specified node. Note that level information is only available for tree structures.

Parameters:
label - the label of the node.
Returns:
the hierarchical level of the specified node.

link

public void link(java.lang.String parent,
                 java.lang.String child)
Links the specified parent-child nodes.

Parameters:
parent - the label of the parent node.
child - the label of the child node.

link

public void link(Node parent,
                 Node child)
Links the specified parent-child nodes.

Parameters:
parent - the parent node.
child - the child node.

remove

public void remove(java.lang.String node)
Removes the specified node from the class hierarchy. The node must be a leaft in order to be removed.

Parameters:
node - the label of the node to be removed.

remove

public void remove(Node node)
Removes the specified node from the class hierarchy. The node must be a leaft in order to be removed.

Parameters:
node - the node to be removed.

find

public Node find(java.lang.String label)
Returns the node instance with the specified label.

Parameters:
label - the label of the node.
Returns:
the node instance with the specified label.

getSize

public int getSize()
Returns the number of nodes.

Returns:
the number of nodes.

flat

public java.util.Collection<Node> flat()
Returns the collection of all nodes labels.

Returns:
the collection of all nodes labels.

shrink

public boolean shrink()
Swaps the root node for its single child node.

Returns:
true if the swap was performed; false otherwise.

weigh

public void weigh()
Computes the weights of all nodes of the hierarchy.


leaf

public java.lang.String leaf(java.util.Collection<java.lang.String> labels)
Returns the label corresponding to the leaf node of the specified collection of class labels. Note that the label does not necessarily corresponds to leaf labels of the class hierarchy.

Parameters:
labels - the collection of labels.
Returns:
the label corresponding to the leaf node of the specified collection of class labels.

leaf

public java.lang.String leaf(java.lang.String... labels)
Returns the label corresponding to the leaf node of the specified array of class labels. Note that the label does not necessarily corresponds to leaf labels of the class hierarchy.

Parameters:
labels - the array of labels.
Returns:
the label corresponding to the leaf node of the specified collection of class labels.

getLeaves

public java.util.Collection<Node> getLeaves()
Rerturns the collection of leaves of this class hierarchy.

Returns:
the collection of leaves of this class hierarchy.

leaves

public java.util.Collection<java.lang.String> leaves(java.util.Collection<java.lang.String> labels)
Returns the leaves label of the specified collection of class labels. Note that the labels do not necessarily corresponds to leaf labels of the class hierarchy.

Parameters:
labels - the collection of labels.
Returns:
the leaves label of the specified collection of class labels.

leaves

public java.util.Collection<java.lang.String> leaves(java.lang.String... labels)
Returns the leaves labels of the specified array of class labels. Note that the labels do not necessarily corresponds to leaf labels of the class hierarchy.

Parameters:
labels - the array of labels.
Returns:
the leaves label of the specified array of class labels.

unique

public boolean unique()
Checks if the class hierarchy has unique class label (i.e. each class label does not include the ancestor labels).

Returns:
true if the class hierarchy contains unique class labels; false otherwise.

isTree

public boolean isTree()
Returns true if the class hierarchy is tree structured.

Returns:
true if the class hierarchy is tree structured; false otherwise.

toGraph

public net.sf.myra.framework.Graph<net.sf.myra.framework.Info.Void> toGraph()
Returns a Graph representation of the class hierarchy.

Returns:
a Graph representation of the class hierarchy.

clone

public ClassHierarchy clone()
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2013. All Rights Reserved.