Java Reference
In-Depth Information
String repres
#
node.toString();
assertTrue(repres
!
" doesn't include "
!
label,
repres.indexOf(label)>-1);
}
public
void testSimpleTree(){
String leftLabel
#
"left";
String rightLable
#
"right";
Node leftLeaf
#
new
Node(leftLabel);
Node rightLeaf
#
new
Node(rightLable);
String toLeft
#
"to the left";
String toRight
#
"to the right";
String rootLabel
#
"root";
Node root
#
new
Node(rootLabel);
root.addChild(toLeft,leftLeaf);
root.addChild(toRight,rightLeaf);
String repres
#
root.toString();
int
index
#
repres.indexOf("root");
assertTrue("root not found",index>0);
int
indexToL
#
repres.indexOf(toLeft,index);
int
indexToR
#
repres.indexOf(toRight,index);
assertTrue("left arc not found",indexToL>index);
assertTrue("right arc not found",indexToR>index);
int
indexL
#
repres.indexOf("left",indexToL);
int
indexR
#
repres.indexOf("right",indexToR);
assertTrue("left node not found",indexL>index);
assertTrue("right node not found",indexR>index);
}
}
4.6
■
Prototype 3: Training
In this iteration the decision tree construction algorithm is used to build a
classifier starting from a training set of items.
4.6.1
Analysis
The class structure remains basically unchanged; the increment is essen-
tially algorithmic. We have to implement Algorithm 4.2 that takes as input a
set of features that are already assigned to categories and builds a decision
tree that captures the criteria adopted to assign the categories.
4.6.2
Design
The main problem in the design of this prototype lies in the definition of the
data structures used for the implementation of the training algorithm