Esempio n. 1
0
  private String getEdgeString(FeatureTree tree, TreeNode parentNode) {
    StringBuilder sb = new StringBuilder();

    for (TreeNode child : parentNode.getChildren()) {
      if (child.getCost() != 0) {
        sb.append(getNodeTypeAndDatabaseIdString(tree, parentNode));
        sb.append(getNodeTypeAndDatabaseIdString(tree, child));

        String value = String.valueOf(child.getValueOfCandidateFeature());
        value = fixPlusAndMinusSigns(value);
        EdgeLabels.FEATURE_VALUE.setAttributeValue(value);
        sb.append(EdgeLabels.FEATURE_VALUE.getDefaultValueString());
        sb.append(EdgeLabels.FEATURE_VALUE.toString());

        value = String.valueOf(parentNode.getAppliedCandidate());
        value = fixPlusAndMinusSigns(value);
        EdgeLabels.CANDIDATE_USED.setAttributeValue(value);
        sb.append(EdgeLabels.CANDIDATE_USED.toString());

        sb.append("\n");
      }
    }

    return sb.toString();
  }
Esempio n. 2
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();
  }