コード例 #1
0
 static <L> Tree<L> stripLeaves(Tree<L> tree) {
   if (tree.isLeaf()) return null;
   if (tree.isPreTerminal()) return new Tree<L>(tree.getLabel());
   List<Tree<L>> children = new ArrayList<Tree<L>>();
   for (Tree<L> child : tree.getChildren()) {
     children.add(stripLeaves(child));
   }
   return new Tree<L>(tree.getLabel(), children);
 }
コード例 #2
0
 private int addConstituents(Tree<L> tree, Set<Object> set, int start) {
   if (tree.isLeaf()) {
     if (punctuationTags.contains(tree.getLabel())) return 0;
     else return 1;
   }
   int end = start;
   for (Tree<L> child : tree.getChildren()) {
     int childSpan = addConstituents(child, set, end);
     end += childSpan;
   }
   L label = tree.getLabel();
   if (!labelsToIgnore.contains(label)) {
     set.add(new LabeledConstituent<L>(label, start, end));
   }
   return end - start;
 }