本文整理匯總了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(')');
}
示例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;
}
示例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;
}