コード例 #1
0
ファイル: Trees.java プロジェクト: hercky/undergradCourses
 public static String treeToLatexEven(Tree t) {
   StringBuilder connections = new StringBuilder();
   StringBuilder hierarchy = new StringBuilder();
   int maxDepth = t.depth();
   treeToLatexEvenHelper(t, connections, hierarchy, 0, 1, 0, 0, maxDepth);
   return "\\tree" + hierarchy + '\n' + connections + '\n';
 }
コード例 #2
0
 public Tree transformTree(Tree tree) {
   Tree treeCopy = tree.deepCopy();
   for (Tree subtree : treeCopy) {
     if (subtree.depth() < 2) {
       continue;
     }
     String categoryLabel = subtree.label().toString();
     Label label = subtree.label();
     label.setFromString(categoryLabel + "-t3");
   }
   return treeCopy;
 }
コード例 #3
0
ファイル: Trees.java プロジェクト: hercky/undergradCourses
 private static int treeToLatexEvenHelper(
     Tree t,
     StringBuilder c,
     StringBuilder h,
     int n,
     int nextN,
     int indent,
     int curDepth,
     int maxDepth) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < indent; i++) sb.append("  ");
   h.append('\n').append(sb);
   int tDepth = t.depth();
   if (tDepth == 0 && tDepth + curDepth < maxDepth) {
     for (int pad = 0; pad < maxDepth - tDepth - curDepth; pad++) {
       h.append("{\\ntnode{pad}{}, ");
     }
   }
   h.append("{\\ntnode{z").append(n).append("}{").append(t.label()).append('}');
   if (!t.isLeaf()) {
     for (int k = 0; k < t.children().length; k++) {
       h.append(", ");
       c.append("\\nodeconnect{z").append(n).append("}{z").append(nextN).append("}\n");
       nextN =
           treeToLatexEvenHelper(
               t.children()[k], c, h, nextN, nextN + 1, indent + 1, curDepth + 1, maxDepth);
     }
   }
   if (tDepth == 0 && tDepth + curDepth < maxDepth) {
     for (int pad = 0; pad < maxDepth - tDepth - curDepth; pad++) {
       h.append('}');
     }
   }
   h.append('}');
   return nextN;
 }