weka.core
Class ClassTree

java.lang.Object
  extended byweka.core.ClassTree
All Implemented Interfaces:
ClassHierarchy, java.io.Serializable

public class ClassTree
extends java.lang.Object
implements ClassHierarchy

ClassTree provides the hierarchy of classes according to a given encoding. The hierarchy is represented as tree resembling closely the tree of the given hierarchical structure.

Author:
Arthur Zimek
See Also:
Serialized Form

Field Summary
static java.lang.String ATTRIBUTES_NULL_MESSAGE
          Message for Exception if both attributes are null.
private  ClassTree[] children
          The subtrees which are children of this node of the hierarchy.
private static java.lang.String COMMA
          Class separator in an tree encoding String or number separator in a range list.
private  java.lang.String[] leaves
          The class-names directly coverd by this node of the hierarchy.
 
Constructor Summary
ClassTree(ClassTree[] children)
          Constructs a class-tree containing the given subtrees as children.
ClassTree(java.lang.String[] classes)
          Constructs a bottom-end class-tree containing only leaves.
 
Method Summary
private  java.lang.String createKey(Instances instanceInfo)
          Provides a String as unique key for a ClassTree with respect to the given Instances.
 int depth()
          Returns the depth of this ClassTree.
 ClassHierarchy[] getChildren()
          Returns the hierarchy of classes as given by the children.
 java.util.Map getChildren(Instances instanceInfo)
          Returns the childrenHierarchies as Map.
 java.lang.String[][] getCoveredClasses()
          Returns the classes covered by this hierarchy splitted into several arrays according to their distribution into several superclasses (reflecting the distribution on several children of this hierarchy).
 java.lang.String[] getCoveredClassesFlat()
          Returns the class-names covered by this node of the hierarchy.
 Instance mergeClasses(Instance instance)
          Returns a new Instance with classes selected and merged to superclasses according to the superclasses of this ClassTree.
 Instances mergeClasses(Instances instances)
          Returns a new Instances with classes merged to superclasses according to the superclasses of this ClassTree.
 Instances selectCoveredClasses(Instances data)
          Returns the part of data covered by this hierarchy.
 void setChildren(ClassTree[] children)
          Sets the children.
 void setLeaves(java.lang.String[] classes)
          Sets the leaves.
 Instances[] splitForSuperClasses(Instances data)
          Returns an array of Instances by splitting the given Instances with respect to the current superclasses.
 java.lang.String toString()
          Returns a String-representation of this ClassTree readable by a ClassTreeParser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMMA

private static final java.lang.String COMMA
Class separator in an tree encoding String or number separator in a range list.

See Also:
Constant Field Values

ATTRIBUTES_NULL_MESSAGE

public static final java.lang.String ATTRIBUTES_NULL_MESSAGE
Message for Exception if both attributes are null.

See Also:
Constant Field Values

children

private ClassTree[] children
The subtrees which are children of this node of the hierarchy. Should remain null, if leaves is not null.


leaves

private java.lang.String[] leaves
The class-names directly coverd by this node of the hierarchy. Should remain null, if children is not null.

Constructor Detail

ClassTree

public ClassTree(java.lang.String[] classes)
Constructs a bottom-end class-tree containing only leaves.

Parameters:
classes - the classes to be contained by the new class-tree as leaves

ClassTree

public ClassTree(ClassTree[] children)
Constructs a class-tree containing the given subtrees as children. If only one subtree is given its children will be set directly.

Parameters:
children - the class-trees to be children of this class-tree
Method Detail

getChildren

public ClassHierarchy[] getChildren()
Returns the hierarchy of classes as given by the children.

Specified by:
getChildren in interface ClassHierarchy
Returns:
ClassHierarchy[] an array containing for each child the hierarchy given under this child respectively an array of length zero for a leaf
See Also:
ClassHierarchy.getChildren()

getChildren

public java.util.Map getChildren(Instances instanceInfo)
                          throws java.lang.Exception
Returns the childrenHierarchies as Map. A key of String equal to a superclass-attribute-value of instanceInfo after merging the classes is mapped to the according child-hierarchy.

Specified by:
getChildren in interface ClassHierarchy
Parameters:
instanceInfo - the instanecs providing the classes
Returns:
Map a mapping of Strings equal to a superclass-attribute-value of instanceInfo after merging the classes to the according child-hierarchy
Throws:
java.lang.Exception - due to the use of filters
See Also:
ClassHierarchy.getChildren(Instances)

getCoveredClasses

public java.lang.String[][] getCoveredClasses()
Returns the classes covered by this hierarchy splitted into several arrays according to their distribution into several superclasses (reflecting the distribution on several children of this hierarchy).

Specified by:
getCoveredClasses in interface ClassHierarchy
Returns:
String[][] the classes covered by this hierarchy splitted according to their distribution into superclasses - the first index reflecting the superclass-index, the second gives the specific class (not reflecting the class-index in Instances).
See Also:
ClassHierarchy.getCoveredClasses()

getCoveredClassesFlat

public java.lang.String[] getCoveredClassesFlat()
Returns the class-names covered by this node of the hierarchy.

Specified by:
getCoveredClassesFlat in interface ClassHierarchy
Returns:
String[] the class-names covered by this node of the hierarchy

selectCoveredClasses

public Instances selectCoveredClasses(Instances data)
                               throws java.lang.Exception
Returns the part of data covered by this hierarchy. The classes not to be contained by the result are removed from the returned data's header.

Specified by:
selectCoveredClasses in interface ClassHierarchy
Parameters:
data - to data to select from
Returns:
Instances the selected data
Throws:
java.lang.Exception - due to use of filters
See Also:
ClassHierarchy.selectCoveredClasses(Instances)

createKey

private java.lang.String createKey(Instances instanceInfo)
                            throws java.lang.Exception
Provides a String as unique key for a ClassTree with respect to the given Instances.

Parameters:
instanceInfo - the Instances to prepare a key for
Returns:
String the concatenated class names of the classes covered by this ClassTree with respect to the sequence of their indices in class-attribute of the given Instances
Throws:
java.lang.Exception

splitForSuperClasses

public Instances[] splitForSuperClasses(Instances data)
                                 throws java.lang.Exception
Returns an array of Instances by splitting the given Instances with respect to the current superclasses.

Parameters:
data - the Instances to be split
Returns:
Instances[] the splitted Instances
Throws:
java.lang.Exception

mergeClasses

public Instance mergeClasses(Instance instance)
                      throws java.lang.Exception
Returns a new Instance with classes selected and merged to superclasses according to the superclasses of this ClassTree.

Specified by:
mergeClasses in interface ClassHierarchy
Parameters:
instance - the instance to merge the classes of
Returns:
Instance a new Instance with classes merged to superclasses according to the superclasses of this hierarchy
Throws:
java.lang.Exception - due to the use of filters
See Also:
ClassHierarchy.mergeClasses(weka.core.Instance)

mergeClasses

public Instances mergeClasses(Instances instances)
                       throws java.lang.Exception
Returns a new Instances with classes merged to superclasses according to the superclasses of this ClassTree.

Specified by:
mergeClasses in interface ClassHierarchy
Parameters:
instances - the instances to merge the classes of
Returns:
Instances a new Instances with classes merged to superclasses according to the superclasses of this hierarchy
Throws:
java.lang.Exception - due to the use of filters
See Also:
ClassHierarchy.mergeClasses(weka.core.Instances)

toString

public java.lang.String toString()
Returns a String-representation of this ClassTree readable by a ClassTreeParser.

Specified by:
toString in interface ClassHierarchy
See Also:
ClassHierarchy.toString()

depth

public int depth()
Returns the depth of this ClassTree.

Specified by:
depth in interface ClassHierarchy
Returns:
int the depth of this ClassTree, i.e. is the maximal length of branches from the root to a leaf.
See Also:
ClassHierarchy.depth()

setChildren

public void setChildren(ClassTree[] children)
Sets the children. If children consist of only one subtree, its children are directly set recursively.

Parameters:
children - The children to set

setLeaves

public void setLeaves(java.lang.String[] classes)
Sets the leaves.

Parameters:
classes - The leaves to set