本文整理汇总了Java中edu.stanford.nlp.trees.tregex.TregexMatcher.getNode方法的典型用法代码示例。如果您正苦于以下问题:Java TregexMatcher.getNode方法的具体用法?Java TregexMatcher.getNode怎么用?Java TregexMatcher.getNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.trees.tregex.TregexMatcher
的用法示例。
在下文中一共展示了TregexMatcher.getNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAntecendentInPredicateNominativeConstruction
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/**
* returns the antecedent NP or null
* The way this method is called could be made more efficient.
* It doesn't really need to get called for every mention
*
*/
private static Mention findAntecendentInPredicateNominativeConstruction(Mention m, Document d) {
Tree root = m.getSentence().rootNode();
Tree node = m.node();
TregexPattern pat = TregexPatternFactory.getPattern("S < NP=np1 <+(VP) (VP < (/^VB.*/ < be|is|was|were|are|being|been) < NP=np2)");
TregexMatcher matcher = pat.matcher(root);
while (matcher.find()) {
if(matcher.getNode("np2") == node){
Tree ante = matcher.getNode("np1");
for(Mention m2: d.mentions()){
if(ante == m2.node()){
return m2;
}
}
}
}
return null;
}
示例2: through
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
private boolean through(ExtractorMatcher matcher) {
Tree rightMostVp = RightMostVp.rightMostVp(matcher.trigger);
TregexMatcher m = through1.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
m = through2.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
m = through3.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
return false;
}
示例3: findTreePattern
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/** Find syntactic pattern in a sentence by tregex */
private void findTreePattern(Tree tree, String pattern, Set<Pair<Integer, Integer>> foundPairs) {
try {
TregexPattern tgrepPattern = TregexPattern.compile(pattern);
TregexMatcher m = tgrepPattern.matcher(tree);
while (m.find()) {
Tree t = m.getMatch();
Tree np1 = m.getNode("m1");
Tree np2 = m.getNode("m2");
Tree np3 = null;
if(pattern.contains("m3")) np3 = m.getNode("m3");
addFoundPair(np1, np2, t, foundPairs);
if(np3!=null) addFoundPair(np2, np3, t, foundPairs);
}
} catch (Exception e) {
// shouldn't happen....
throw new RuntimeException(e);
}
}
示例4: findHeadVerb
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
public Optional<String> findHeadVerb(Tree parseTree) {
TregexPattern pattern = TregexPattern.compile("ROOT <<: (__ < (VP=vp [ <+(VP) (VP=lowestvp !< VP) | ==(VP=lowestvp !< VP) ]))");
TregexMatcher matcher = pattern.matcher(parseTree);
while (matcher.findAt(parseTree)) {
Tree lowestvp = matcher.getNode("lowestvp");
return Optional.of(ParseTreeExtractionUtils.getContainingWords(lowestvp).get(0).word());
}
return Optional.empty();
}
示例5: replaceNamedVars
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
private static String replaceNamedVars(TregexMatcher matcher, String original) {
Pattern namedNodePattern = Pattern.compile("\\{(.+?)\\}");
Matcher namedNodematcher = namedNodePattern.matcher(original);
while (namedNodematcher.find()) {
String namedNodeString = namedNodematcher.group(1);
Tree namedNode = matcher.getNode(namedNodeString);
original =
original.replace(String.format("{%s}", namedNodeString),
replaceSpecialChars(namedNode.label().value()));
namedNodematcher = namedNodePattern.matcher(original);
}
return original;
}
示例6: npppHead
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
protected Tree npppHead(Tree t) {
TregexMatcher m = p0.matcher(t);
if (m.find() && t == m.getMatch()) {
return m.getNode("np1");
}
m = p01.matcher(t);
if (m.find() && t.getLeaves().get(0) == m.getMatch().getLeaves().get(0)) {
Tree np1 = m.getNode("np1");
Tree pp1 = m.getNode("pp");
Tree res = np1.deepCopy();
for(Tree child : pp1.children())
{
res.addChild(child);
}
return res;
}
m = p1.matcher(t);
if (m.find() && t == m.getMatch()) {
return m.getNode("np1");
}
m = p2.matcher(t);
if (m.find() && t == m.getMatch()) {
return m.getNode("np1");
}
m = p3.matcher(t);
if (m.find() && t == m.getMatch()) {
return m.getNode("np1");
}
return t;
}
示例7: through
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
private boolean through(ExtractorMatcher matcher) {
Tree rightMostVp = RightMostVp.rightMostVp(matcher.trigger);
TregexMatcher m = by1.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
m = by2.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
m = by3.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
m = by4.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
m = by5.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
m = by6.matcher(rightMostVp);
if (m.find()) {
matcher.trigger = m.getNode("tr");
return true;
}
return false;
}
示例8: match
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
protected boolean match(ExtractorMatcher matcher,
TregexMatcher tregexMatcher, Tree tree) {
matcher.matched = tregexMatcher.getNode("p");
matcher.argument = tregexMatcher.getNode("arg");
matcher.trigger = tregexMatcher.getNode("tr");
return true;
}
示例9: npppHead
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
protected Tree npppHead(Tree t) {
// when extracting causal relation, do not use head only, because the arugment can be an event itself
// TregexMatcher m = p0.matcher(t);
// if (m.find() && t == m.getMatch()) {
//
// return m.getNode("np1");
// }
//
// m = p01.matcher(t);
//
// if (m.find() && t.getLeaves().get(0) == m.getMatch().getLeaves().get(0)) {
//
// Tree np1 = m.getNode("np1");
// Tree pp1 = m.getNode("pp");
// Tree res = np1.deepCopy();
// for(Tree child : pp1.children())
// {
// res.addChild(child);
// }
// return res;
// }
TregexMatcher m = p1.matcher(t);
if (m.find() && t == m.getMatch()) {
return m.getNode("np1");
}
m = p2.matcher(t);
if (m.find() && t == m.getMatch()) {
return m.getNode("np1");
}
m = p3.matcher(t);
if (m.find() && t == m.getMatch()) {
return m.getNode("np1");
}
return t;
}
示例10: evaluate
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
public Tree evaluate(Tree t, TregexMatcher matcher) {
while (t.numChildren() != 0) {
t.removeChild(0);
}
for (String arg : args) {
Tree child = matcher.getNode(arg);
t.addChild(child);
}
return t;
}
示例11: evaluate
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
@Override
public Tree evaluate(Tree t, TregexMatcher m) {
Tree result = root.newNodeNames.get(label);
if (result == null) {
result = m.getNode(label);
}
if (result == null) {
System.err.println("Warning -- null node fetched by Tsurgeon operation for node: " + this +
" (either no node labeled this, or the labeled node didn't match anything)");
}
return result;
}
示例12: extractEnumerations
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/** Extract enumerations (A, B, and C) */
protected void extractEnumerations(CoreMap s, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet){
List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class);
SemanticGraph dependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
final String mentionPattern = "NP < (/^(?:NP|NNP|NML)/=m1 $.. (/^CC|,/ $.. /^(?:NP|NNP|NML)/=m2))";
TregexPattern tgrepPattern = TregexPattern.compile(mentionPattern);
TregexMatcher matcher = tgrepPattern.matcher(tree);
Map<IntPair, Tree> spanToMentionSubTree = Generics.newHashMap();
while (matcher.find()) {
matcher.getMatch();
Tree m1 = matcher.getNode("m1");
Tree m2 = matcher.getNode("m2");
List<Tree> mLeaves = m1.getLeaves();
int beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1;
int endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class);
spanToMentionSubTree.put(new IntPair(beginIdx, endIdx), m1);
mLeaves = m2.getLeaves();
beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1;
endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class);
spanToMentionSubTree.put(new IntPair(beginIdx, endIdx), m2);
}
for(IntPair mSpan : spanToMentionSubTree.keySet()){
if(!mentionSpanSet.contains(mSpan) && !insideNE(mSpan, namedEntitySpanSet)) {
int mentionID = assignIds? ++maxID:-1;
Mention m = new Mention(mentionID, mSpan.get(0), mSpan.get(1), dependency,
new ArrayList<CoreLabel>(sent.subList(mSpan.get(0), mSpan.get(1))), spanToMentionSubTree.get(mSpan));
mentions.add(m);
mentionSpanSet.add(mSpan);
}
}
}
示例13: checkPleonastic
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
private static boolean checkPleonastic(Mention m, Tree tree, String pattern) {
try {
TregexPattern tgrepPattern = TregexPattern.compile(pattern);
TregexMatcher matcher = tgrepPattern.matcher(tree);
while (matcher.find()) {
Tree np1 = matcher.getNode("m1");
if (((CoreLabel)np1.label()).get(CoreAnnotations.BeginIndexAnnotation.class)+1 == m.headWord.get(CoreAnnotations.IndexAnnotation.class)) {
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例14: findAntecedentInRoleAppositiveConstruction
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/**
*
* Note: This is slightly different than what is described in H&K EMNLP 09.
* I think the head rules they used were slightly different (or possibly their description is a little off).
*
* @param m
* @param d
* @return
*/
private static Mention findAntecedentInRoleAppositiveConstruction(Mention m, Document d) {
Tree root = m.getSentence().rootNode();
Tree node = m.node();
Tree parent = node.parent(root);
//System.err.println("mention:"+node.yield().toString()+"\thead:"+node.headTerminal(AnalysisUtilities.getInstance().getHeadFinder()).yield().toString());
if(!parent.label().value().equals("NP")){
return null;
}
int index = parent.indexOf(node);
if(index+1 >= parent.numChildren()){
return null;
}
TregexPattern pat = TregexPatternFactory.getPattern("NP=parent !> __ <<# (NNP=head ,, NP=mention)");
TregexMatcher matcher = pat.matcher(parent);
while (matcher.find()) {
if (matcher.getNode("mention") == node){
Tree head = matcher.getNode("head");
//find maximal projection of the head of the parent
Tree maxProj = SyntacticPaths.getMaximalProjection(head, root);
//find the mention for the parent
for(Mention cand:d.mentions()){
if(cand.node() == maxProj){
// Asher, 20-January-2013 - yet another workaround:
// Wrapping the "if" by try...catch
try
{
if(Types.personhood(cand) == Types.Personhood.Person){
return cand;
}
}
catch(NullPointerException npe)
{
// Do nothing. Just assume that Types.personhood(cand) != Types.Personhood.Person
}
break;
}
}
}
}
return null;
}
示例15: find
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
private static boolean find(TregexMatcher m, Tree vp) {
return m.find() && m.getNode("p") == vp;
}