コード例 #1
0
ファイル: Trees.java プロジェクト: hercky/undergradCourses
 /** 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);
   }
 }
コード例 #2
0
ファイル: Trees.java プロジェクト: hercky/undergradCourses
 /**
  * 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;
 }
コード例 #3
0
ファイル: Trees.java プロジェクト: hercky/undergradCourses
 /* 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;
 }