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


Java Tree.getLeaves方法代码示例

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


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

示例1: 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

示例2: getLeavesOfRoot

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public Clause getLeavesOfRoot(Tree tree)
{
	ArrayList<Word> retList = new ArrayList<Word>();
	for(Tree t: tree.getLeaves())
		retList.add(new Word(t.label().value(), t.parent(tree).label().value()));
	return new Clause(retList, tree.label().value());
}
 
开发者ID:nus-mmsys,项目名称:talk-to-code,代码行数:8,代码来源:StanfordParser.java

示例3: getWordList

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public ArrayList<Word> getWordList(Tree t)
{
	ArrayList<Word>	retList = new ArrayList<Word>();
	for(Tree tree:t.getLeaves())
	{
		retList.add(new Word(tree.label().value(), tree.parent(t).label().value()));
	}
	return retList;
}
 
开发者ID:nus-mmsys,项目名称:talk-to-code,代码行数:10,代码来源:StanfordParser.java

示例4: fillVectorWithYield

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
static void fillVectorWithYield(String[] vector, TregexMatcher tregexMatcher) {
  while (tregexMatcher.find()) {
    Tree match = tregexMatcher.getMatch();
    List<Tree> leaves = match.getLeaves();
    if (leaves.size() == 1) continue;
    boolean seenStart = false;
    for (Tree leaf : leaves) {
      int index = ((HasIndex) leaf.label()).index() - 1;
      if ( ! vector[index].equals("O")) break;
      vector[index] = seenStart ? "I" : "B";
      seenStart = true;
    }
  }
}
 
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:15,代码来源:CoreNLPToJSON.java

示例5: computeIncrementalTrees

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static Map<Integer, String> computeIncrementalTrees(String treeStr)
    {
        Map<Integer, String> map = new TreeMap<Integer, String>();        
        Tree tree = Tree.valueOf(treeStr);
        List<Tree> leaves = tree.getLeaves();
        Tree firstLeaf = leaves.get(0);
        // first prefix tree by default is the sub-tree rooted on the preterminal (don't add, as we compute evalb for words>1)
//        map.put(0, firstLeaf.parent(tree).toString());
        for(int i = 1; i < leaves.size(); i++)
        {
            Tree lastLeaf = leaves.get(i);
            map.put(i, getMinimalConnectedStructure(tree, firstLeaf, lastLeaf, i).toString());
        }
        return map;
    }
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:16,代码来源:Utils.java

示例6: computeIncrementalTree

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static String computeIncrementalTree(String treeStr)
{
    Tree tree = Tree.valueOf(treeStr);
    List<Tree> leaves = tree.getLeaves();
    leaves.get(leaves.size() - 1);
    return computeIncrementalTree(treeStr, leaves.size() - 1).toString();
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:8,代码来源:Utils.java

示例7: 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

示例8: 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

示例9: getChunkVector

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
   * Extract chunks. 
   * 
   * @param tree
   * @return
   */
  private static int[] getChunkVector(Tree tree) {
    String[] iobVector = new String[tree.yield().size()];
    Arrays.fill(iobVector, "O");
    
    // Yield patterns
//    TregexPattern baseNPPattern = TregexPattern.compile("@NP < (/NN/ < (__ !< __)) !< @NP");
    TregexPattern baseXPPattern = TregexPattern.compile("__ < (__ < (__ !< __)) !< (__ < (__ < __))");
    TregexPattern basePPPattern = TregexPattern.compile("@PP <, @IN !<< @NP >! @PP");
    TregexMatcher tregexMatcher = baseXPPattern.matcher(tree);
    fillVectorWithYield(iobVector, tregexMatcher);
    tregexMatcher = basePPPattern.matcher(tree);
    fillVectorWithYield(iobVector, tregexMatcher);
    
    // Edge patterns
    TregexPattern vpPattern = TregexPattern.compile("@VP >! @VP");
    TregexPattern argumentPattern = TregexPattern.compile("[email protected]=node > @VP !< (__ !< __)");
    TregexPattern puncPattern = TregexPattern.compile("/^[^a-zA-Z0-9]+$/=node < __ ");
    TsurgeonPattern p = Tsurgeon.parseOperation("delete node");
    tregexMatcher = vpPattern.matcher(tree);
    while (tregexMatcher.find()) {
      Tree match = tregexMatcher.getMatch();
      Tsurgeon.processPattern(argumentPattern, p, match);
      Tsurgeon.processPattern(puncPattern, p, match);
      List<Tree> leaves = match.getLeaves();
      if (leaves.size() == 1) continue;
      boolean seenStart = false;
      int lastIndex = -1;
      for (Tree leaf : leaves) {
        int index = ((HasIndex) leaf.label()).index() - 1;
        if (index < 0 || index >= iobVector.length) {
          System.err.println("ERROR: Mangled subtree: " + match.toString());
          continue;
        }
        if (lastIndex > 0 && index - lastIndex != 1) break;
        if ( ! iobVector[index].equals("O")) break;
        iobVector[index] = seenStart ? "I" : "B";
        seenStart = true;
        lastIndex = index;
      }
    }
    int[] indexVector = iobToIndices(iobVector);
    return indexVector;
  }
 
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:50,代码来源:CoreNLPToJSON.java


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