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


Java Tree.value方法代码示例

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


在下文中一共展示了Tree.value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: annotatePhraseStructureRecursively

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
/**
 * Generate a SyntaxTreeNode Annotation corresponding to this Tree. Work
 * recursively so that the annotations are actually generated from the bottom
 * up, in order to build the consists list of annotation IDs.
 * 
 * @param tree
 *          the current subtree
 * @param rootTree
 *          the whole sentence, used to find the span of the current subtree
 * @return a GATE Annotation of type "SyntaxTreeNode"
 */
protected Annotation annotatePhraseStructureRecursively(
    AnnotationSet annotationSet, StanfordSentence stanfordSentence,
    Tree tree, Tree rootTree) {
  Annotation annotation = null;
  Annotation child;
  String label = tree.value();
  List<Tree> children = tree.getChildrenAsList();
  if(children.size() == 0) { return null; }
  /* implied else */
  /*
   * following line generates ClassCastException IntPair span =
   * tree.getSpan(); edu.stanford.nlp.ling.CategoryWordTag at
   * edu.stanford.nlp.trees.Tree.getSpan(Tree.java:393) but I think it's a bug
   * in the parser, so I'm hacking around it as follows.
   */
  int startPos = Trees.leftEdge(tree, rootTree);
  int endPos = Trees.rightEdge(tree, rootTree);
  Long startNode = stanfordSentence.startPos2offset(startPos);
  Long endNode = stanfordSentence.endPos2offset(endPos);
  List<Integer> consists = new ArrayList<Integer>();
  Iterator<Tree> childIter = children.iterator();
  while(childIter.hasNext()) {
    child =
        annotatePhraseStructureRecursively(annotationSet, stanfordSentence,
            childIter.next(), rootTree);
    if((child != null) && (!child.getType().equals(inputTokenType))) {
      consists.add(child.getId());
    }
  }
  annotation =
      annotatePhraseStructureConstituent(annotationSet, startNode, endNode,
          label, consists, tree.depth());
  return annotation;
}
 
开发者ID:GateNLP,项目名称:gateplugin-Stanford_CoreNLP,代码行数:46,代码来源:Parser.java

示例3: countPOSTokens

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static IntCounter<String> countPOSTokens(Collection<Tree> trees) {
    IntCounter<String> particleParents = new IntCounter<String>();
    IntCounter<String> tokens = new IntCounter<String>();
    for( Tree tree : trees ) {
//      System.out.println("tree: " + tree);
      Collection<Tree> leaves = TreeOperator.leavesFromTree(tree);
      for( Tree leaf : leaves ) {
        // Lowercase the token.
        String token = leaf.getChild(0).value().toLowerCase();
        String tag = leaf.value();

        // Particles.
        // e.g. (PRT (RP up))
        if( tag.equals("RP") ) {
          Tree gparent = leaf.ancestor(2, tree);
          Tree gparentTree = gparent.children()[0];
          String gVerbHead = gparentTree.getChild(0).value().toLowerCase();
          char gTag = CalculateIDF.normalizePOS(gparentTree.value());

          String headKey = CalculateIDF.createKey(gVerbHead + "_" + token, gTag);
//          System.out.println("Particle verb " + headKey);

//          System.out.println("  Incrementing " + headKey);
          tokens.incrementCount(headKey);
          particleParents.incrementCount(CalculateIDF.createKey(gVerbHead, gTag));
        }
        // All other words.
        else {
          // e.g. v-helping
          String key = CalculateIDF.createKey(token, CalculateIDF.normalizePOS(tag));
          tokens.incrementCount(key);
        }
      }
    }

    // Remove counts from verbs that are counted with their particles.
    for( Map.Entry<String, Double> entry : particleParents.entrySet() ) {
//      System.out.println("  Decrementing " + entry.getKey());
      tokens.decrementCount(entry.getKey(), entry.getValue());
    }

//    System.out.println("Returning " + tokens);
    return tokens;
  }
 
开发者ID:nchambers,项目名称:schemas,代码行数:45,代码来源:ParsesToCounts.java


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