Пример #1
0
 /** returns true iff <code>head</code> (transitively) heads <code>node</code> */
 public static boolean heads(Tree head, Tree node, HeadFinder hf) {
   if (node.isLeaf()) {
     return false;
   } else {
     return heads(head, hf.determineHead(node), hf);
   }
 }
 /**
  * Add -TMP when not present within an NP
  *
  * @param tree The tree to add temporal info to.
  */
 private void addTMP9(final Tree tree) {
   // do the head chain under it
   Tree ht = headFinder.determineHead(tree);
   // special fix for possessives! -- make noun before head
   if (ht.value().equals("POS")) {
     int j = tree.objectIndexOf(ht);
     if (j > 0) {
       ht = tree.getChild(j - 1);
     }
   }
   // Note: this next bit changes the tree label, rather
   // than creating a new tree node.  Beware!
   if (ht.isPreTerminal()
       || ht.value().startsWith("NP")
       || ht.value().startsWith("PP")
       || ht.value().startsWith("ADVP")) {
     if (!TmpPattern.matcher(ht.value()).matches()) {
       LabelFactory lf = ht.labelFactory();
       // System.err.println("TMP: Changing " + ht.value() + " to " +
       //                   ht.value() + "-TMP");
       ht.setLabel(lf.newLabel(ht.value() + "-TMP"));
     }
     if (ht.value().startsWith("NP")
         || ht.value().startsWith("PP")
         || ht.value().startsWith("ADVP")) {
       addTMP9(ht);
     }
   }
   // do the NPs under it (which may or may not be the head chain
   Tree[] kidlets = tree.children();
   for (int k = 0; k < kidlets.length; k++) {
     ht = kidlets[k];
     LabelFactory lf;
     if (tree.isPrePreTerminal() && !TmpPattern.matcher(ht.value()).matches()) {
       // System.err.println("TMP: Changing " + ht.value() + " to " +
       //                   ht.value() + "-TMP");
       lf = ht.labelFactory();
       // Note: this next bit changes the tree label, rather
       // than creating a new tree node.  Beware!
       ht.setLabel(lf.newLabel(ht.value() + "-TMP"));
     } else if (ht.value().startsWith("NP")) {
       // don't add -TMP twice!
       if (!TmpPattern.matcher(ht.value()).matches()) {
         lf = ht.labelFactory();
         // System.err.println("TMP: Changing " + ht.value() + " to " +
         //                   ht.value() + "-TMP");
         // Note: this next bit changes the tree label, rather
         // than creating a new tree node.  Beware!
         ht.setLabel(lf.newLabel(ht.value() + "-TMP"));
       }
       addTMP9(ht);
     }
   }
 }
Пример #3
0
 /**
  * returns the maximal projection of <code>head</code> in <code>root</code> given a {@link
  * HeadFinder}
  */
 public static Tree maximalProjection(Tree head, Tree root, HeadFinder hf) {
   Tree projection = head;
   if (projection == root) {
     return root;
   }
   Tree parent = projection.parent(root);
   while (hf.determineHead(parent) == projection) {
     projection = parent;
     if (projection == root) {
       return root;
     }
     parent = projection.parent(root);
   }
   return projection;
 }
Пример #4
0
 /* applies a TreeVisitor to all projections (including the node itself) of a node in a Tree.
  *  Does nothing if head is not in root.
  * @return the maximal projection of head in root.
  */
 public static Tree applyToProjections(TreeVisitor v, Tree head, Tree root, HeadFinder hf) {
   Tree projection = head;
   Tree parent = projection.parent(root);
   if (parent == null && projection != root) {
     return null;
   }
   v.visitTree(projection);
   if (projection == root) {
     return root;
   }
   while (hf.determineHead(parent) == projection) {
     projection = parent;
     v.visitTree(projection);
     if (projection == root) {
       return root;
     }
     parent = projection.parent(root);
   }
   return projection;
 }