当前位置: 首页>>代码示例>>Java>>正文


Java Tree.parent方法代码示例

本文整理汇总了Java中edu.stanford.nlp.trees.Tree.parent方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.parent方法的具体用法?Java Tree.parent怎么用?Java Tree.parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.trees.Tree的用法示例。


在下文中一共展示了Tree.parent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: eventRelationship

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * Checks if one event syntactically dominates the other.
 * @param tree The root of the parse tree
 * @param e1 The first event's word
 * @param e2 The second event's word
 * @returns 1 if no dominance, 2 if e1 dominates, or 3 if e2 dominates
 */
public static int eventRelationship(Tree tree, Tree tree1, Tree tree2) {
  if( tree1 != null && tree2 != null ) {
    // Find grandparent of event1, check dominance
    Tree p = tree1.parent(tree); // parent is POS tag
    Tree gp = p.parent(tree); // gp is actual parent
    if( gp.dominates(tree2) ) return Features.DOMINATES;

    // Find grandparent of event2, check dominance
    p = tree2.parent(tree);
    gp = p.parent(tree);
    if( gp.dominates(tree1) ) return Features.DOMINATED;
  }
  //	else System.out.println("WARNING: no tree1 or no tree2 (" + e1 + "," + e2 + ")");
  else System.out.println("WARNING: no tree1 or no tree2");

  return 1;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:25,代码来源:EventParser.java

示例2: isPrepClause

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * @desc Check if the tree is a clause in a prepositional phrase.
 * @returns The string preposition that heads the PP
 */
public static String isPrepClause(Tree root, Tree tree) {
  if( tree != null ) {
    Tree p = tree.parent(root).parent(root);
    String pos = p.label().toString();

    // Keep moving up the tree till we hit a new type of POS
    while( p.label().toString().equals(pos) ) p = p.parent(root);

    // We can hit one sentence, but the S must be the PP clause
    if( p.label().toString().equals("S") ) {
      p = p.parent(root);
      if( !p.label().toString().equals("PP") ) return null;
    }

    // We found the PP, return the preposition
    if( p.label().toString().equals("PP") ) {
      List<Tree> list = p.getChildrenAsList();
      for( Tree node : list ) {
        if( node.label().toString().equals("IN") ) 
          return node.firstChild().toString();
      }
    }
  }
  return null;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:30,代码来源:EventParser.java

示例3: eventRelationship

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * Checks if one event syntactically dominates the other.
 * @param tree The root of the parse tree
 * @param e1 The first event's word
 * @param e2 The second event's word
 * @returns 1 if no dominance, 2 if e1 dominates, or 3 if e2 dominates
 */
public int eventRelationship(Tree tree, Tree tree1, Tree tree2) {
  //	System.out.println("rel? " + e1 + " " + e2);
  //	Tree tree1 = (Tree)findEventInTree(tree, e1);
  //	Tree tree2 = (Tree)findEventInTree(tree, e2);

  if( tree1 != null && tree2 != null ) {
    // Find grandparent of event1, check dominance
    Tree p = tree1.parent(tree); // parent is POS tag
    Tree gp = p.parent(tree); // gp is actual parent
    if( gp.dominates(tree2) ) return Features.DOMINATES;

    // Find grandparent of event2, check dominance
    p = tree2.parent(tree);
    gp = p.parent(tree);
    if( gp.dominates(tree1) ) return Features.DOMINATED;
  }
  //	else System.out.println("WARNING: no tree1 or no tree2 (" + e1 + "," + e2 + ")");
  else System.out.println("WARNING: no tree1 or no tree2");

  return 1;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:29,代码来源:GigaEventParser.java

示例4: getListOfRightMostCompleteNonTerminals

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * Identify the list of rightmost non-terminals that span a complete subtree, i.e., one that
 * a) the leaf of its' rightmost child is a word, OR
 * b) the index of the leaf of its' rightmost is a word AND is the last in the yield (AND this leaf is the last word - optional, as this condition breeches incrementality).
 * @param analysisTree
 * @return 
 */
private List<Tree> getListOfRightMostCompleteNonTerminals(Tree tree)
{
    List<Tree> list = new ArrayList();
    List<Tree> leaves = tree.getLeaves();
    // check if the last leaf is a word.
    Tree currentWord = leaves.get(leaves.size() - 1);
    if(currentWord.nodeString().endsWith("<>"))
    {
        Tree parent = currentWord.parent(tree);
        while(parent != tree)
        {
            if(parent.isPhrasal())
            {
                list.add(parent);
            }
            parent = parent.parent(tree);
        }
        list.add(tree);
    }
    return list;
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:29,代码来源:ExtractFeatures.java

示例5: flatNP

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static boolean flatNP(Tree tree, int start, int end) {
    Tree startTree = indexToSubtree(tree, start);
    Tree endTree = indexToSubtree(tree, end-1);

    Tree startParent = startTree.parent(tree);
    Tree endParent = endTree.parent(tree);
    
//    if( startParent == endParent ) System.out.println("  same!!");
//    else System.out.println("  diff!!");
    
    if( startParent == endParent )
      return true;
    else return false;
  }
 
开发者ID:nchambers,项目名称:probschemas,代码行数:15,代码来源:TreeOperator.java

示例6: isPrepClause

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
   * @desc Check if the tree is a clause in a prepositional phrase.
   * @returns The string preposition that heads the PP
   */
  public static String isPrepClause(Tree root, Tree tree) {
//    System.out.println("isPrepClause: subtree=" + tree);
    if( tree != null ) {
      Tree p = tree.parent(root).parent(root);
//      System.out.println("parent=" + p);
      String pos = p.label().value();
//      System.out.println("parent pos=" + pos);

      if( !pos.equals("PP") ) {
        // Keep moving up the tree till we hit a new type of POS
        while( p.label().toString().equals(pos) ) p = p.parent(root);
      }
      
      // We can hit one sentence, but the S must be the PP clause
      if( p.label().value().equals("S") ) {
        p = p.parent(root);
        if( !p.label().value().equals("PP") ) return null;
      }

      // We found the PP, return the preposition
      if( p.label().value().equals("PP") ) {
        List<Tree> list = p.getChildrenAsList();
        for( Tree node : list ) {
          if( node.label().value().equals("IN") ) 
            return node.firstChild().toString();
        }
      }
    }
    return null;
  }
 
开发者ID:nchambers,项目名称:schemas,代码行数:35,代码来源:TLinkFeaturizer.java

示例7: treeDominates

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * Checks if the first tree1 syntactically dominates the second tree2.
 * @param tree1 A subtree.
 * @param tree2 A subtree.
 * @param tree The full sentence's parse tree.
 * @returns True if the first tree dominates the second, false otherwise.
 */
private boolean treeDominates(Tree tree1, Tree tree2, Tree tree) {
  if( tree1 != null && tree2 != null ) {
    // Find parent tree of event1, check dominance
    Tree p = tree1.parent(tree); // parent is POS tag
    if( p.dominates(tree2) ) 
      return true;
  }
  else 
    System.out.println("WARNING: no tree1 or no tree2");
  return false;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:19,代码来源:TLinkFeaturizer.java

示例8: getMinimalConnectedStructure

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static Tree getMinimalConnectedStructure(Tree tree, Tree firstLeaf, Tree lastLeaf, int lastLeafIndex)
{
    // find common ancestor node by traversing the tree bottom-up from the last leaf and up
    Tree commonAncestorNode = lastLeaf.parent(tree);
    while(!commonAncestorNode.getLeaves().get(0).equals(firstLeaf))
    {
        commonAncestorNode = commonAncestorNode.parent(tree);
    }
    // found the common ancestor, now we need to clone the tree and chop the children non-terminals the span of which is outwith the last leaf
    Tree result = commonAncestorNode.deepCopy();
    List<Tree> leaves = result.getLeaves();
    lastLeaf = leaves.get(lastLeafIndex);
    Tree p = lastLeaf.parent(result);
    Tree d = lastLeaf;
    while(p != null)
    {
        if(p.numChildren() > 1)
        {
            // remove siblings to the right of d
            int index = indexOfChild(p, d.nodeNumber(result), result);
            pruneChildrenAfter(p, index);
        }
        d = p;
        p = p.parent(result);
    }
    return result;
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:28,代码来源:Utils.java

示例9: removeSubtreesAfterWord

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static String removeSubtreesAfterWord(String inputTree, int numOfLeaves)
{
    Tree tree = Tree.valueOf(inputTree);
    List<Tree> leaves = tree.getLeaves();
    if(leaves.size() > numOfLeaves)
    {
        // find common ancestor between last valid leaf and extraneous leaf
        Tree firstLeaf = leaves.get(numOfLeaves - 1);
        Tree lastLeaf = leaves.get(leaves.size() - 1);
        Tree commonAncestorNode = lastLeaf.parent(tree);            
        while(!commonAncestorNode.getLeaves().contains(firstLeaf))
        {
            commonAncestorNode = commonAncestorNode.parent(tree);
        }
        // found the common ancestor, now we need to chop the children nodes the span of which is outwith the last valid leaf

        Tree p = lastLeaf.parent(tree);
        while(p != commonAncestorNode)
        {
            int numOfChildren = p.numChildren();
            for(int i = 0; i < numOfChildren; i++)
                p.removeChild(0);     
            p = p.parent(tree);
        }
        // remove last leftover parent node of the invalid leaf
        commonAncestorNode.removeChild(commonAncestorNode.numChildren() - 1);
        return tree.toString();
    }
    else
    {        
        return inputTree;
    }        
    
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:35,代码来源:Utils.java

示例10: eventSubTree

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
private Tree eventSubTree(Tree tree, WordEvent event) {
  Tree terminal = TreeOperator.indexToSubtree(tree, event.position());
  return terminal.parent(tree); // return the VP, e.g. (VP (VBG running)) 
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:5,代码来源:BasicEventAnalyzer.java


注:本文中的edu.stanford.nlp.trees.Tree.parent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。