Пример #1
0
  private void getAsPennTreebankString(int indent, int numOnLine, StringBuilder sb) {
    int numSpaces = indent - numOnLine;
    for (int i = 0; i < numSpaces; i++) {
      sb.append(" ");
    }
    if (isLexical) {
      sb.append(getSymbolStr());
    } else {
      sb.append("(");
      sb.append(getSymbolStr());

      // If this is a constant instead, then we have each depth in one column.
      int numNewChars = 1 + getSymbolStr().length();

      if (leftChild != null) {
        // sb.append("\n");
        leftChild.getAsPennTreebankString(indent + numNewChars + 1, indent + numNewChars, sb);
      }
      if (rightChild != null) {
        sb.append("\n");
        rightChild.getAsPennTreebankString(indent + numNewChars + 1, 0, sb);
      }
      sb.append(")");
    }
  }
Пример #2
0
 /**
  * Gets a string representation of this parse that looks like the typical Penn Treebank style
  * parse.
  *
  * <p>Example: ((ROOT (S (NP (NN time)) (VP (VBZ flies) (PP (IN like) (NP (DT an) (NN arrow)))))))
  *
  * @return A string representing this parse.
  */
 public String getAsPennTreebankString() {
   StringBuilder sb = new StringBuilder();
   sb.append("(");
   getAsPennTreebankString(1, 1, sb);
   sb.append(")");
   return sb.toString();
 }