weka.core.converters
Class ClassTreeParser

java.lang.Object
  extended byweka.core.converters.AbstractClassHierarchyParser
      extended byweka.core.converters.ClassTreeParser
All Implemented Interfaces:
ClassHierarchyParser, java.io.Serializable
Direct Known Subclasses:
ClassTreeFileParser

public class ClassTreeParser
extends AbstractClassHierarchyParser

ClassTreeParser is a ClassHierarchyParser which provides as ClassHierarchy-structure a ClassTree

Author:
Arthur Zimek
See Also:
Serialized Form

Field Summary
private  java.util.List classNames
          Provides the class-names of a nominal class-attribute after initialization with the init(Instances)-method.
private  java.lang.String encodedHierarchy
          The encoded hierarchy currently to be parsed by this ClassTreeParser.
static java.lang.String ILLEGAL_ARGUMENT
          Error-message for an exception thrown in case of a invalid argument.
static char LEFT
          Lefthand-side delimiter of a set of classes or of superclasses.
static char RIGHT
          Righthand-side delimiter of a set of classes or of superclasses.
static java.lang.String SEPARATOR
          Separator of two sets of classes or of superclasses.
 
Constructor Summary
ClassTreeParser()
           
 
Method Summary
private  ClassTree decodeClassTree(java.lang.String encodedClassTree)
          Decodes the given code recursively.
 ClassHierarchy getClassHierarchy()
          Returns the classHierarchy encoded in the currently set encodedHierarchy.
 java.lang.String getEncodedHierarchy()
          Returns the currently encoded hierarchy.
 void init(Instances instanceInfo)
          Inits the ClassTreeParser.
static void main(java.lang.String[] args)
          Method to test a hierarchy with respect to given Instances.
 void setEncodedHierarchy(java.lang.String encodedHierarchy)
          The given String is supposed to have no whitespace-signs and to collect classes as a comma-separated list delimited by left- and right-brackets - so superclasses are collected as comma-separated list of substrings delimited by left- and right-brackets.
 boolean validate()
          Validates the currently encoded hierarchy with respect to the Instances given in initialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final char LEFT
Lefthand-side delimiter of a set of classes or of superclasses.

See Also:
Constant Field Values

RIGHT

public static final char RIGHT
Righthand-side delimiter of a set of classes or of superclasses.

See Also:
Constant Field Values

SEPARATOR

public static final java.lang.String SEPARATOR
Separator of two sets of classes or of superclasses.

See Also:
Constant Field Values

ILLEGAL_ARGUMENT

public static final java.lang.String ILLEGAL_ARGUMENT
Error-message for an exception thrown in case of a invalid argument.

See Also:
Constant Field Values

classNames

private java.util.List classNames
Provides the class-names of a nominal class-attribute after initialization with the init(Instances)-method.


encodedHierarchy

private java.lang.String encodedHierarchy
The encoded hierarchy currently to be parsed by this ClassTreeParser.

Constructor Detail

ClassTreeParser

public ClassTreeParser()
Method Detail

init

public void init(Instances instanceInfo)
          throws UnsupportedAttributeTypeException
Inits the ClassTreeParser. The method extends AbstractClassHierarchyParser#init(Instances). Furthermore the classNames are set according to the class names occuring in the given Instances. This enables validation of a hierarchy, that must contain all class names and only the here defined class names.

Specified by:
init in interface ClassHierarchyParser
Overrides:
init in class AbstractClassHierarchyParser
Throws:
UnsupportedAttributeTypeException
See Also:
ClassHierarchyParser.init(Instances)

setEncodedHierarchy

public void setEncodedHierarchy(java.lang.String encodedHierarchy)
The given String is supposed to have no whitespace-signs and to collect classes as a comma-separated list delimited by left- and right-brackets - so superclasses are collected as comma-separated list of substrings delimited by left- and right-brackets. For example the following structure:

should be encoded as
{{{a,b,c},{d,e},{f,g,h}},{{i,j},{k,l,m}}}
Note that single classes among subtrees are supposed to be parenthesized e.g.:
{{a,b},{c},{d,e}}
The classHierarchy provided by this method will be an instance of ClassTree.

Parameters:
encodedHierarchy - the encoded hierarchy to be decoded
See Also:
ClassHierarchyParser.setEncodedHierarchy(java.lang.String)

getEncodedHierarchy

public java.lang.String getEncodedHierarchy()
Returns the currently encoded hierarchy.

Returns:
String the currently set encoded hierarchy
See Also:
ClassHierarchyParser.getEncodedHierarchy()

getClassHierarchy

public ClassHierarchy getClassHierarchy()
                                 throws java.text.ParseException
Returns the classHierarchy encoded in the currently set encodedHierarchy. The classHierarchy provided by this method will be an instance of ClassTree.

Returns:
ClassHierarchy the ClassHierarchy decoded out of the currently set encodedHierarchy
Throws:
java.text.ParseException - in case of a invalid hierarchy-code with respect to the Instances set int the init(Instances)-method
See Also:
ClassHierarchyParser.getClassHierarchy()

validate

public boolean validate()
                 throws java.text.ParseException
Validates the currently encoded hierarchy with respect to the Instances given in initialization. The hierarchy will be invalid, if it does not cover exactly the classes set in classNames during initialization, each class once, or if the hierarchy encoding String is syntactically wrong.

Returns:
boolean true, if the currently set encodedHierarchy is valid with respect to the current initialization
Throws:
java.text.ParseException - if the currently set encodedHierarchy is invalid in some manner

decodeClassTree

private ClassTree decodeClassTree(java.lang.String encodedClassTree)
                           throws java.lang.IllegalArgumentException
Decodes the given code recursively.

Parameters:
encodedClassTree - the code of a hierarchy to be decoded
Returns:
ClassTree the ClassTree decoded out of the given code
Throws:
java.lang.IllegalArgumentException - in case of an invalid code leading to empty Strings or empty subtrees

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Method to test a hierarchy with respect to given Instances. Reads Instances from a file and an encoded hierarchy in a given String and prints out the resulting ClassTree.

Parameters:
args - expected arguments are:
  1. file: instances.arff
  2. String: encodedHierarchy
  3. Throws:
    java.lang.Exception