當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。