Пример #1
0
  private String getNodeTypeAndDatabaseIdString(FeatureTree tree, TreeNode node) {

    StringBuilder sb = new StringBuilder();

    // type-attribute
    // level of the tree
    sb.append(tree.getBabyTreeType());
    sb.append("/");

    if (tree.getClass() == JointlyCodingFeatureTree.class) {
      sb.append(tree.getAlignmentType());
      sb.append("/");
    }

    // name of the feature
    sb.append(tree.getFeatureName());
    sb.append("_");

    // unique node number -  database_id -attribute
    int nodeIdentity = node.getNodeIdentityNumber();
    sb.append(nodeIdentity);

    sb.append(" ");

    return sb.toString();
  }
Пример #2
0
  private void printTree(FeatureTree tree) {
    minEntropy = Double.POSITIVE_INFINITY;
    maxEntropy = Double.NEGATIVE_INFINITY;

    for (TreeNode node : tree.getNodes()) {

      // if node matrix contains only zeros, don't print
      if (node.getCost() != 0) {
        node.setNodeIdentityNumber(nodeCounter);
        nodeCounter += 1;

        double nodeEntropy = computeEntropy(node.getCountMatrix());
        if (nodeEntropy > maxEntropy) {
          maxEntropy = nodeEntropy;
        }
        if (nodeEntropy < minEntropy) {
          minEntropy = nodeEntropy;
        }
      }
    }

    for (TreeNode node : tree.getNodes()) {
      try {
        if (node.getCost() != 0) {
          fw.write(getEdgeString(tree, node));
          fw.write(getNodeString(tree, node));
        }
      } catch (IOException ex) {
        Logger.getLogger(TreeGraphPrinter.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
Пример #3
0
  private String getMatrixString(FeatureTree tree, TreeNode node) {
    StringBuilder sb = new StringBuilder();
    int[][] matrix = node.getCountMatrix();
    if (tree.getClass() != JointlyCodingFeatureTree.class) {
      return Arrays.toString(matrix[0]);
    } else {
      int counter = 0;
      sb.append("    ");
      for (char c : tree.getColumnLabels()) {

        sb.append(c).append("  ");
      }
      sb.append("\\n");
      for (int[] row : matrix) {
        sb.append(tree.getRowLabels().get(counter)).append(" ");
        sb.append(Arrays.toString(row)).append("\\n");
        counter++;
      }
      // sb.deleteCharAt(sb.length()-1);
    }
    return sb.toString();
  }
Пример #4
0
  private String getRootNodePositionString(FeatureTree tree, TreeNode node) {
    StringBuilder sb = new StringBuilder();

    int x = 0;
    int y = 0;

    if (tree.getBabyTreeType().equals(BabyTreeType.SOURCE)) {
      prevSourceXCoordinate += 1000;
      x = prevSourceXCoordinate;
      y = 0;

    } else {
      prevTargetXCoordinate += 1000;
      x = prevTargetXCoordinate;
      y = 2000;
    }

    sb.append(x);
    sb.append(",");
    sb.append(y);

    return sb.toString();
  }
Пример #5
0
  private String getNodeString(FeatureTree tree, TreeNode parentNode) {
    StringBuilder sb = new StringBuilder();

    // each node line begins with this
    sb.append("# _attributes ");

    String language = tree.getLanguage();

    // the default name of the node; here the name of the feature
    sb.append(getNodeTypeAndDatabaseIdString(tree, parentNode));

    if (parentNode.isRootNode()) {
      // add some extra attributes for root node
      sb.append(getAttributeString(NodeLabels.TOTAL_COST_OF_TREE, tree.getTotalTreeCost()));
      sb.append(getAttributeString(NodeLabels.MODEL_COST_OF_TREE, tree.getModelCost()));
      sb.append(getAttributeString(NodeLabels.DATA_COST_OF_TREE, tree.getDataCost()));
      sb.append(getAttributeString(NodeLabels.FEATURE_NAME, tree.getFeatureName()));
      sb.append(
          getAttributeString(
              NodeLabels.TREE_LEVEL, tree.getBabyTreeType().toString() + ":" + language));
      sb.append(getAttributeString(NodeLabels.TREE_TYPE, tree.getTreeType()));
      sb.append(getAttributeString(NodeLabels.COLUMN_LABELS, tree.getColumnLabels()));
      if (tree.getClass() == JointlyCodingFeatureTree.class) {
        sb.append(getAttributeString(NodeLabels.ROW_LABELS, tree.getRowLabels()));
        sb.append(getAttributeString(NodeLabels.ALIGNMENT_TYPE, tree.getAlignmentType()));
      }
      if (tree.getBabyTreeType() != BabyTreeType.JOINT) {
        sb.append(getAttributeString(NodeLabels.POS, getRootNodePositionString(tree, parentNode)));
      }
      sb.append("queryset=root ");

    } else {
      // not root node
      sb.append(
          getAttributeString(
              NodeLabels.FILL,
              getColor(minEntropy, maxEntropy, computeEntropy(parentNode.getCountMatrix()))));
    }

    // default label, if not defined, the getNodeDatabaseIdString is shown in nodes instead
    sb.append(getAttributeString(NodeLabels.LABEL, getMatrixString(tree, parentNode)));

    // attributes that all nodes share
    sb.append(getAttributeString(NodeLabels.MATRIX_COST, parentNode.getCost()));
    sb.append(getAttributeString(NodeLabels.MATRIX, getMatrixString(tree, parentNode)));

    sb.append(
        getAttributeString(
            NodeLabels.FEATURE_VALUE_IN_PREVIOUS_SPLIT, parentNode.getValueOfCandidateFeature()));
    sb.append(
        getAttributeString(NodeLabels.NUMBER_OF_CANDIDATES, parentNode.getCandidates().size()));
    sb.append(getAttributeString(NodeLabels.ENTROPY, computeEntropy(parentNode.getCountMatrix())));

    // inner nodes have been split
    if (parentNode.getAppliedCandidate() != null) {
      sb.append(getAttributeString(NodeLabels.BEST_CANDIDATE, parentNode.getAppliedCandidate()));
      sb.append(
          getAttributeString(
              NodeLabels.BEST_CANDIDATE_COST, parentNode.getAppliedCandidate().getCost()));
    }

    sb.append("\n");

    return sb.toString();
  }