public class DecisionTree
extends java.lang.Object
NODE feat operand value qfalse
Where feat
is an string that represents a feature to pass to
the findFeature
method of an item.
The value
represents the value to be compared against the
feature obtained from the item via the feat
string. The
operand
is the operation to do the comparison. The available
operands are as follows:
[[[TODO: provide support for the IN operator.]]]
For < and >, this CART coerces the value and feature to float's. For =, this CART coerces the value and feature to string and checks for string equality. For MATCHES, this CART uses the value as a regular expression and compares the obtained feature to that.
A CART is represented by an array in this implementation. The
qfalse
value represents the index of the array to go to if the
comparison does not match. In this implementation, qtrue index is always
implied, and represents the next element in the array. The root node of the
CART is the first element in the array.
The interpretations always start at the root node of the CART and continue until a final node is found. The final nodes have the following form:
LEAF value
Where value
represents the value of the node. Reaching a final
node indicates the interpretation is over and the value of the node is the
interpretation result.
Constructor and Description |
---|
DecisionTree(java.io.BufferedReader reader,
int nodes)
Creates a new CART by reading from the given reader.
|
DecisionTree(java.net.URL url)
Creates a new CART by reading from the given URL.
|
Modifier and Type | Method and Description |
---|---|
void |
dumpDot(java.io.PrintWriter out)
Dump the CART tree as a dot file.
|
protected java.lang.String |
dumpDotNodeColor(edu.cmu.sphinx.alignment.tokenizer.DecisionTree.Node n) |
protected java.lang.String |
dumpDotNodeShape(edu.cmu.sphinx.alignment.tokenizer.DecisionTree.Node n) |
protected edu.cmu.sphinx.alignment.tokenizer.DecisionTree.Node |
getNode(java.lang.String type,
java.util.StringTokenizer tokenizer,
int currentNode)
Gets the node based upon the type and tokenizer.
|
java.lang.Object |
interpret(Item item)
Passes the given item through this CART and returns the interpretation.
|
protected void |
parseAndAdd(java.lang.String line)
Creates a node from the given input line and add it to the CART.
|
protected java.lang.Object |
parseValue(java.lang.String string)
Coerces a string into a value.
|
public DecisionTree(java.net.URL url) throws java.io.IOException
url
- the location of the CART datajava.io.IOException
- if errors occur while reading the datapublic DecisionTree(java.io.BufferedReader reader, int nodes) throws java.io.IOException
reader
- the source of the CART datanodes
- the number of nodes to read for this cartjava.io.IOException
- if errors occur while reading the datapublic void dumpDot(java.io.PrintWriter out)
The dot tool is part of the graphviz distribution at http://www.graphviz.org/. If installed, call it as "dot -O -Tpdf *.dot" from the console to generate pdfs.
out
- The PrintWriter to write to.protected java.lang.String dumpDotNodeColor(edu.cmu.sphinx.alignment.tokenizer.DecisionTree.Node n)
protected java.lang.String dumpDotNodeShape(edu.cmu.sphinx.alignment.tokenizer.DecisionTree.Node n)
protected void parseAndAdd(java.lang.String line)
line
- a line of input to parseprotected edu.cmu.sphinx.alignment.tokenizer.DecisionTree.Node getNode(java.lang.String type, java.util.StringTokenizer tokenizer, int currentNode)
type
- NODE
or LEAF
tokenizer
- the StringTokenizer containing the data to getcurrentNode
- the index of the current node we're looking atprotected java.lang.Object parseValue(java.lang.String string)
string
- of the form "type(value)"; for example, "Float(2.3)"public java.lang.Object interpret(Item item)
item
- the item to analyze