Esempio n. 1
0
  /**
   * 显示决策树
   *
   * @param node 待显示的节点
   * @param blankNum 行空格符,用于显示树型结构
   */
  private void showDecisionTree(AttrNode node, int blankNum) {
    System.out.println();
    for (int i = 0; i < blankNum; i++) {
      System.out.print("\t");
    }
    System.out.print("--");
    // 显示分类的属性值
    if (node.getParentAttrValue() != null && node.getParentAttrValue().length() > 0) {
      System.out.print(node.getParentAttrValue());
    } else {
      System.out.print("--");
    }
    System.out.print("--");

    if (node.getChildDataIndex() != null && node.getChildDataIndex().size() > 0) {
      String i = node.getChildDataIndex().get(0);
      System.out.print("类别:" + data[Integer.parseInt(i)][attrNames.length - 1]);
      System.out.print("[");
      for (String index : node.getChildDataIndex()) {
        System.out.print(index + ", ");
      }
      System.out.print("]");
    } else {
      // 递归显示子节点
      System.out.print("【" + node.getAttrName() + "】");
      for (AttrNode childNode : node.getChildAttrNode()) {
        showDecisionTree(childNode, 2 * blankNum);
      }
    }
  }