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


Java Tree.isLeaf方法代码示例

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


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

示例1: toStringBuilder

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
static StringBuilder toStringBuilder(Tree tree, StringBuilder sb, 
  boolean printOnlyLabelValue, String offset) {
  if (tree.isLeaf()) {
    if (tree.label() != null) sb.append(printOnlyLabelValue ? tree.label().value() : tree.label());
    return sb;
  } 
  sb.append('(');
  if (tree.label() != null) {
  	if (printOnlyLabelValue) {
  		if (tree.value() != null) sb.append(tree.label().value());
  		// don't print a null, just nothing!
  	} else {
  		sb.append(tree.label());
  	}
  }
  Tree[] kids = tree.children();
  if (kids != null) {
  	for (Tree kid : kids) {
  		if (kid.isLeaf()) sb.append(' '); 
  		else sb.append('\n').append(offset).append(' ');
  		toStringBuilder(kid, sb, printOnlyLabelValue,offset + "  ");
  	}
  }
  return sb.append(')');
}
 
开发者ID:sivareddyg,项目名称:UDepLambda,代码行数:26,代码来源:TreePrinter.java

示例2: findTreeLocation

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static Object findTreeLocation(Tree tree, int leafPos, Integer currentPos) {
  if( tree.isLeaf() ) {
    if( leafPos == currentPos.intValue() ) {
      return tree;
    }
    return new Integer(currentPos.intValue()+1);
  } else {
    List<Tree> children = tree.getChildrenAsList();
    for( Tree child : children ) {
      Object obj = findTreeLocation(child, leafPos, currentPos);
      if( obj != null && obj instanceof Integer ) {
        currentPos = (Integer)obj;
      } else return obj; // found the tree
    }
    return currentPos;
  }
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:18,代码来源:EventParser.java

示例3: sameLabelAtLevel

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
private boolean sameLabelAtLevel(Tree left, Tree right, int level)
{
    if(left.isLeaf() || right.isLeaf())
        return false;
    if(level == 0)
        return left.nodeString().equals(right.nodeString());
    Tree[] leftChildren = left.children();
    Tree[] rightChildren = right.children();
    if(leftChildren.length != rightChildren.length)
        return false;
    for(int i = 0; i < leftChildren.length; i++)
    {
        if(!sameLabelAtLevel(leftChildren[i], rightChildren[i], level - 1))
            return false;
    }
    return true;
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:18,代码来源:ExtractFeatures.java

示例4: determineHead

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public Tree determineHead(Tree t) {
    if (t.isLeaf()) {
        return null;
    } else {
        return t.children()[t.children().length - 1];
    }
}
 
开发者ID:Yaraku,项目名称:stanfordnlp-srparser-ja,代码行数:8,代码来源:RightHeadFinder.java

示例5: subSentence

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * 返回一个s节点下面的完整子句
 *
 * @param tree
 * @param sb
 */
private void subSentence(Tree tree, StringBuilder sb) {
    if (tree.isLeaf()) {
        sb.append(tree.nodeString() + " ");
        return;
    } else {
        List<Tree> childTrees = tree.getChildrenAsList();
        for (Tree child : childTrees) {
            this.subSentence(child, sb);
        }
    }
}
 
开发者ID:procyon-lotor,项目名称:event-direct-mts,代码行数:18,代码来源:ChineseWhispersCluster.java

示例6: subSentence

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * 返回一个s节点下面的完整子句
 * @param tree
 * @param sb
 */
private void subSentence(Tree tree, StringBuilder sb){
    if(tree.isLeaf()){
        sb.append(tree.nodeString() + " ");
        return;
    }else{
        final List<Tree> childTrees = tree.getChildrenAsList();
        for (final Tree child : childTrees) {
            this.subSentence(child, sb);
        }
    }
}
 
开发者ID:procyon-lotor,项目名称:event-direct-mts,代码行数:17,代码来源:SentenceExtractThread.java

示例7: preorder

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
private static String preorder(Tree tree) {
  
  List<Tree> queue = new LinkedList<>();
  queue.add(tree);
  
  
  while ( ! queue.isEmpty()) {
    Tree currentNode = queue.remove(0);
    
    if (currentNode.isLeaf())
      continue;
    
    Tree children[] = currentNode.children();
    int childCount = children.length;
    IndexedWord hw = (IndexedWord) currentNode.label();
    List<FeatureNode> featureNodes = new ArrayList<>(childCount);
    for (int i = 0; i < childCount; i++) {
      featureNodes.add(new FeatureNode(children[i], hw));
      queue.add(children[i]);
    }
    if (childCount < 8) {
      Pair<Double, List<Integer>> result = search(featureNodes, new LinkedList<Integer>(), Double.NEGATIVE_INFINITY);
      if (result != null) {
        List<Integer> permutation = result.second;
        List<Tree> newChildren = new ArrayList<>(Arrays.asList(children));
        for (int i = 0; i < childCount; i++) {
          int idx = permutation.get(i);
          newChildren.set(idx, children[i]);
        }
        currentNode.setChildren(newChildren);
      } else {
        System.err.println("Warning: No path found.");
      }
    }
  }
  
  return StringUtils.join(tree.yieldWords());
}
 
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:39,代码来源:DependencyBnBPreorderer.java

示例8: addTreebankNodeChildrenToIndexes

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
private FSArray addTreebankNodeChildrenToIndexes(
    TreebankNode parent,
    JCas jCas,
    List<CoreLabel> tokenAnns,
    Tree tree) {
  Tree[] childTrees = tree.children();

  // collect all children (except leaves, which are just the words - POS tags are pre-terminals in
  // a Stanford tree)
  List<TreebankNode> childNodes = new ArrayList<TreebankNode>();
  for (Tree child : childTrees) {
    if (!child.isLeaf()) {

      // set node attributes and add children (mutual recursion)
      TreebankNode node = new TreebankNode(jCas);
      node.setParent(parent);
      this.addTreebankNodeToIndexes(node, jCas, child, tokenAnns);
      childNodes.add(node);
    }
  }

  // convert the child list into an FSArray
  FSArray childNodeArray = new FSArray(jCas, childNodes.size());
  for (int i = 0; i < childNodes.size(); ++i) {
    childNodeArray.set(i, childNodes.get(i));
  }
  return childNodeArray;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:29,代码来源:StanfordCoreNlpAnnotator.java

示例9: constructConstituent

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 *
 * @param root
 * @param left
 * @param right
 * @param n
 *          is the length of the sentence is tokens.
 * @param p
 * @param tokenizationUUID
 * @return The constituent ID
 * @throws AnalyticException
 */
private static int constructConstituent(Tree root, int left,
    int right, int n, Parse p, UUID tokenizationUUID, HeadFinder hf)
    throws AnalyticException {

  Constituent constituent = new Constituent();
  constituent.setId(p.getConstituentListSize());
  constituent.setTag(root.value());
  constituent.setStart(left);
  constituent.setEnding(right);
  p.addToConstituentList(constituent);
  Tree headTree = null;
  if (!root.isLeaf()) {
    try {
      headTree = hf.determineHead(root);
    } catch (java.lang.IllegalArgumentException iae) {
      LOGGER.warn("Failed to find head, falling back on rightmost constituent.", iae);
      headTree = root.children()[root.numChildren() - 1];
    }
  }
  int i = 0, headTreeIdx = -1;

  int leftPtr = left;
  for (Tree child : root.getChildrenAsList()) {
    int width = child.getLeaves().size();
    int childId = constructConstituent(child, leftPtr, leftPtr
        + width, n, p, tokenizationUUID, hf);
    constituent.addToChildList(childId);

    leftPtr += width;
    if (headTree != null && child == headTree) {
      assert (headTreeIdx < 0);
      headTreeIdx = i;
    }
    i++;
  }

  if (headTreeIdx >= 0)
    constituent.setHeadChildIndex(headTreeIdx);

  if (!constituent.isSetChildList())
    constituent.setChildList(new ArrayList<Integer>());
  return constituent.getId();
}
 
开发者ID:hltcoe,项目名称:concrete-stanford-deprecated2,代码行数:56,代码来源:PreNERCoreMapWrapper.java


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