本文整理汇总了Java中edu.stanford.nlp.trees.TreeFactory.newTreeNode方法的典型用法代码示例。如果您正苦于以下问题:Java TreeFactory.newTreeNode方法的具体用法?Java TreeFactory.newTreeNode怎么用?Java TreeFactory.newTreeNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.trees.TreeFactory
的用法示例。
在下文中一共展示了TreeFactory.newTreeNode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: match
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
protected boolean match(ExtractorMatcher matcher,
TregexMatcher tregexMatcher, Tree tree) {
boolean result = super.match(matcher, tregexMatcher, tree);
if (result) {
List<Tree> children = matcher.getMatch().getChildrenAsList();
int triggerIndex = children.indexOf(matcher.trigger);
int argIndex = children.indexOf(matcher.argument);
matcher.matched = tregexMatcher.getMatch().deepCopy();
children = matcher.matched.getChildrenAsList();
matcher.trigger = children.get(triggerIndex);
TreeFactory tf = matcher.matched.treeFactory();
matcher.argument = tf.newTreeNode(
"NP",
children.subList(argIndex, children.size()));
}
return result;
}
示例2: match
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
protected boolean match(ExtractorMatcher matcher,
TregexMatcher tregexMatcher, Tree tree) {
boolean result = super.match(matcher, tregexMatcher, tree);
if (result) {
List<Tree> children = matcher.getMatch().getChildrenAsList();
int argIndex = children.indexOf(matcher.argument);
matcher.matched = tregexMatcher.getMatch().deepCopy();
children = matcher.matched.getChildrenAsList();
matcher.trigger = matcher.matched;
TreeFactory tf = matcher.matched.treeFactory();
matcher.argument = tf
.newTreeNode("NP", children.subList(0, argIndex + 1));
}
return result;
}
示例3: fixNonUnaryRoot
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
private Tree fixNonUnaryRoot(Tree t, TreeFactory tf) {
List<Tree> kids = t.getChildrenAsList();
if(kids.size() == 2 && t.firstChild().isPhrasal() && tlp.isSentenceFinalPunctuationTag(t.lastChild().value())) {
List<Tree> grandKids = t.firstChild().getChildrenAsList();
grandKids.add(t.lastChild());
t.firstChild().setChildren(grandKids);
kids.remove(kids.size() - 1);
t.setChildren(kids);
t.setValue(tlp.startSymbol());
} else {
t.setValue(nonUnaryRoot);
t = tf.newTreeNode(tlp.startSymbol(), Collections.singletonList(t));
}
return t;
}
示例4: match
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
protected boolean match(ExtractorMatcher matcher,
TregexMatcher tregexMatcher,
Tree tree) {
boolean result = super.match(matcher, tregexMatcher, tree);
if (result) {
List<Tree> children = matcher.getMatch().getChildrenAsList();
int triggerIndex = children.indexOf(matcher.trigger);
int argIndex = children.indexOf(matcher.argument);
matcher.matched = tregexMatcher.getMatch();
TreeFactory tf = tregexMatcher.getMatch().treeFactory();
matcher.matched = tregexMatcher.getMatch().deepCopy(tf);
children = matcher.matched.getChildrenAsList();
matcher.trigger = tf.newTreeNode(
"NP",
children.subList(triggerIndex, children.size()));
matcher.argument = tf
.newTreeNode("NP", children.subList(0, argIndex + 1));
while (matcher.matched.numChildren() != 0) {
matcher.matched.removeChild(0);
}
matcher.matched.addChild(matcher.argument);
matcher.matched.addChild(matcher.trigger);
}
return result;
}
示例5: match
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
protected boolean match(ExtractorMatcher matcher,
TregexMatcher tregexMatcher, Tree tree) {
Tree leaf = tregexMatcher.getMatch().getChild(0);
if (!leaf.isLeaf()) {
return false;
}
OffsetLabel label = (OffsetLabel) leaf.label();
int dash = label.value().lastIndexOf('-');
if (dash == -1 || dash == 0) {
return false;
}
matcher.matched = leaf.parent(tree).deepCopy();
TreeFactory tf = matcher.matched.treeFactory();
OffsetLabel newLeafLabel = new OffsetLabel(label.value()
.substring(dash + 1));
newLeafLabel.setBeginPosition(dash + 1 + label.beginPosition());
newLeafLabel.setEndPosition(label.endPosition());
leaf = tf.newLeaf(newLeafLabel);
matcher.trigger = tf.newTreeNode("NP", Collections.singletonList(leaf));
newLeafLabel = new OffsetLabel(label.value()
.substring(0, dash));
newLeafLabel.setBeginPosition(label.beginPosition());
newLeafLabel.setEndPosition(label.beginPosition() + dash);
leaf = tf.newLeaf(newLeafLabel);
matcher.argument = tf.newTreeNode("NP", Collections.singletonList(leaf));
matcher.matched.removeChild(0);
matcher.matched.addChild(matcher.argument);
matcher.matched.addChild(matcher.trigger);
return true;
}
示例6: transformRoot
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
Tree transformRoot(Tree tree, TreeFactory tf) {
// XXXX TODO: use tlp and don't assume 1 daughter of ROOT!
// leave the root intact
// if (tlp.isStartSymbol(tlp.basicCategory(tree.label().value())))
if (tree.label().toString().startsWith("ROOT")) {
return tf.newTreeNode(tree.label(), Collections.singletonList(transformNode(tree.children()[0], tf)));
}
return transformNode(tree, tf);
}
示例7: xTree
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
/**
* Construct a fall through tree in case we can't parse this sentence
* @param words
* @return a tree with X for all the internal nodes
*/
public static Tree xTree(List<? extends HasWord> words) {
TreeFactory lstf = new LabeledScoredTreeFactory();
List<Tree> lst2 = new ArrayList<Tree>();
for (HasWord obj : words) {
String s = obj.word();
Tree t = lstf.newLeaf(s);
Tree t2 = lstf.newTreeNode("X", Collections.singletonList(t));
lst2.add(t2);
}
return lstf.newTreeNode("X", lst2);
}
示例8: normalizeWholeTree
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
public Tree normalizeWholeTree(Tree tree, TreeFactory tf) {
tree = tree.prune(hebrewEmptyFilter, tf).spliceOut(aOverAFilter, tf);
//Add start symbol so that the root has only one sub-state. Escape any enclosing brackets.
//If the "tree" consists entirely of enclosing brackets e.g. ((())) then this method
//will return null. In this case, readers e.g. PennTreeReader will try to read the next tree.
while(tree != null && (tree.value() == null || tree.value().equals("")) && tree.numChildren() <= 1)
tree = tree.firstChild();
if(tree != null && !tree.value().equals(tlp.startSymbol()))
tree = tf.newTreeNode(tlp.startSymbol(), Collections.singletonList(tree));
return tree;
}
示例9: normalizeWholeTree
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
/**
* Normalize a whole tree -- one can assume that this is the
* root. This implementation deletes empty elements (ones with
* nonterminal tag label starting with '*T') from the tree. It
* does work for a null tree.
*/
@Override
public Tree normalizeWholeTree(Tree tree, TreeFactory tf) {
// add an extra root to non-unary roots
if(tree.value() == null)
tree = fixNonUnaryRoot(tree, tf);
else if(!tree.value().equals(tlp.startSymbol()))
tree = tf.newTreeNode(tlp.startSymbol(), Collections.singletonList(tree));
tree = tree.prune(emptyFilter, tf).spliceOut(aOverAFilter, tf);
// insert NPs in PPs if you're supposed to do that
if (insertNPinPP) {
insertNPinPPall(tree);
}
for(Tree t : tree) {
if(t.isLeaf() || t.isPreTerminal()) continue;
if(t.value() == null || t.value().equals("")) t.setValue("DUMMY");
// there's also a '--' category
if(t.value().matches("--.*")) continue;
// fix a bug in the ACL08 German tiger treebank
String cat = t.value();
if(cat == null || cat.equals("")) {
if (t.numChildren() == 3 && t.firstChild().label().value().equals("NN") && t.getChild(1).label().value().equals("$.")) {
System.err.println("Correcting treebank error: giving phrase label DL to " + t);
t.label().setValue("DL");
}
}
}
return tree;
}
示例10: match
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
protected boolean match(ExtractorMatcher matcher,
TregexMatcher tregexMatcher, Tree tree) {
Tree leaf = tregexMatcher.getMatch().getChild(0);
if (!leaf.isLeaf()) {
return false;
}
OffsetLabel label = (OffsetLabel) leaf.label();
if (label.value().contains("-RRB-")) {
return false;
}
Matcher m = p.matcher(label.value());
if (!m.find()) {
return false;
}
matcher.matched = leaf.parent(tree).deepCopy();
TreeFactory tf = matcher.matched.treeFactory();
OffsetLabel newLeafLabel = new OffsetLabel(m.group(2));
newLeafLabel.setBeginPosition(m.start(2) + label.beginPosition());
newLeafLabel.setEndPosition(m.end(2) + label.beginPosition());
leaf = tf.newLeaf(newLeafLabel);
matcher.trigger = tf.newTreeNode(matcher.matched.value(), Collections.singletonList(leaf));
newLeafLabel = new OffsetLabel(m.group(1));
newLeafLabel.setBeginPosition(m.start(1) + label.beginPosition());
newLeafLabel.setEndPosition(m.end(1) + label.beginPosition());
leaf = tf.newLeaf(newLeafLabel);
matcher.argument = tf.newTreeNode(matcher.matched.value(), Collections.singletonList(leaf));
matcher.matched.removeChild(0);
matcher.matched.addChild(matcher.argument);
matcher.matched.addChild(matcher.trigger);
return true;
}
示例11: normalizeWholeTree
import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
public Tree normalizeWholeTree(Tree tree, TreeFactory tf) {
tree = tree.prune(emptyFilter, tf).spliceOut(aOverAFilter, tf);
for(Tree t : tree) {
//Map punctuation tags back like the PTB
if(t.isPreTerminal()) {
String posStr = normalizePreterminal(t);
t.setValue(posStr);
if(t.label() instanceof HasTag) ((HasTag) t.label()).setTag(posStr);
} else if(t.isLeaf()) {
//Strip off morphological analyses and place them in the OriginalTextAnnotation, which is
//specified by HasContext.
if(t.value().contains(MorphoFeatureSpecification.MORPHO_MARK)) {
String[] toks = t.value().split(MorphoFeatureSpecification.MORPHO_MARK);
if(toks.length != 2)
System.err.printf("%s: Word contains malformed morph annotation: %s%n",this.getClass().getName(),t.value());
else if(t.label() instanceof CoreLabel) {
((CoreLabel) t.label()).setValue(toks[0].trim().intern());
((CoreLabel) t.label()).setWord(toks[0].trim().intern());
((CoreLabel) t.label()).setOriginalText(toks[1].trim().intern());
} else {
System.err.printf("%s: Cannot store morph analysis in non-CoreLabel: %s%n",this.getClass().getName(),t.label().getClass().getName());
}
}
}
}
//Add start symbol so that the root has only one sub-state. Escape any enclosing brackets.
//If the "tree" consists entirely of enclosing brackets e.g. ((())) then this method
//will return null. In this case, readers e.g. PennTreeReader will try to read the next tree.
while(tree != null && (tree.value() == null || tree.value().equals("")) && tree.numChildren() <= 1)
tree = tree.firstChild();
//Ensure that the tree has a top-level unary rewrite
if(tree != null && !tree.value().equals(rootLabel))
tree = tf.newTreeNode(rootLabel, Collections.singletonList(tree));
return tree;
}