本文整理汇总了Java中edu.stanford.nlp.trees.tregex.TregexMatcher.find方法的典型用法代码示例。如果您正苦于以下问题:Java TregexMatcher.find方法的具体用法?Java TregexMatcher.find怎么用?Java TregexMatcher.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.trees.tregex.TregexMatcher
的用法示例。
在下文中一共展示了TregexMatcher.find方法的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: getRelatedNodes
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/** Given a <code>Tree</code> node <code>t</code>, attempts to
* return a list of nodes to which node <code>t</code> has this
* grammatical relation.
*
* @param t Target for finding governors of t related by this GR
* @param root The root of the Tree
* @return Governor nodes to which t bears this GR
*/
public Collection<Tree> getRelatedNodes(Tree t, Tree root) {
if (root.value() == null) {
root.setValue("ROOT"); // todo: cdm: it doesn't seem like this line should be here
}
Set<Tree> nodeList = new LinkedHashSet<Tree>();
for (TregexPattern p : targetPatterns) { // cdm: I deleted: && nodeList.isEmpty()
TregexMatcher m = p.matcher(root);
while (m.find()) {
if (m.getMatch() == t) {
nodeList.add(m.getNode("target"));
//System.out.println("found " + this + "(" + t + ", " + m.getNode("target") + ")");
}
}
}
return nodeList;
}
示例3: find
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
@Override
public boolean find() {
List<SimplificationPattern> list = SimplificationTregexReader
.getTregex(SimplificationTregexReader.Apposition);
for (SimplificationPattern p : list) {
TregexMatcher m = p.getTregexPattern().matcher(root);
if (m.find()) {
for (TOperationPattern oPattern : p.getOperations()) {
try {
Tree newTree = oPattern.evaluate(root, p.getTregexPattern());
simplifiedTrees.add(newTree);
} catch (NullPointerException e) {
System.err.println(p);
e.printStackTrace();
System.exit(1);
}
}
return true;
}
}
return false;
}
示例4: processPatternsOnTree
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
public static Tree processPatternsOnTree(List<Pair<TregexPattern, TsurgeonPattern>> ops, Tree t) {
matchedOnTree = false;
for (Pair<TregexPattern,TsurgeonPattern> op : ops) {
try {
TregexMatcher m = op.first().matcher(t);
while (m.find()) {
matchedOnTree = true;
t = op.second().evaluate(t,m);
if (t == null) {
return null;
}
m = op.first().matcher(t);
}
} catch (NullPointerException npe) {
throw new RuntimeException("Tsurgeon.processPatternsOnTree failed to match label for pattern: " + op.first() + ", " + op.second(), npe);
}
}
return t;
}
示例5: find
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
@Override
public boolean find() {
for (SimplificationPattern p : list) {
if (p.getTregexPattern().toString()
.startsWith("Root (NP=p < (NP=np1 $+ (PP <1 (JJ <: /such/ )")) {
// System.err.println();
}
TregexMatcher m = p.getTregexPattern().matcher(root);
if (m.find()) {
for (TOperationPattern oPattern : p.getOperations()) {
try {
Tree newTree = oPattern.evaluate(root, p.getTregexPattern());
simplifiedTrees.add(newTree);
} catch (NullPointerException e) {
System.err.println(p);
e.printStackTrace();
System.exit(1);
}
}
return true;
}
}
return false;
}
示例6: processPatternsOnTree
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
public static Tree processPatternsOnTree(List<Pair<TregexPattern, TsurgeonPattern>> ops, Tree t) {
matchedOnTree = false;
for (Pair<TregexPattern,TsurgeonPattern> op : ops) {
try {
if (DEBUG) {
System.err.println("Running pattern " + op.first());
}
TregexMatcher m = op.first().matcher(t);
while (m.find()) {
matchedOnTree = true;
t = op.second().evaluate(t,m);
if (t == null) {
return null;
}
m = op.first().matcher(t);
}
} catch (NullPointerException npe) {
throw new RuntimeException("Tsurgeon.processPatternsOnTree failed to match label for pattern: " + op.first() + ", " + op.second(), npe);
}
}
return t;
}
示例7: extractNPorPRP
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
protected void extractNPorPRP(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);
tree.indexLeaves();
SemanticGraph dependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
final String mentionPattern = "/^(?:NP|PRP)/";
TregexPattern tgrepPattern = TregexPattern.compile(mentionPattern);
TregexMatcher matcher = tgrepPattern.matcher(tree);
while (matcher.find()) {
Tree t = matcher.getMatch();
List<Tree> mLeaves = t.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);
IntPair mSpan = new IntPair(beginIdx, endIdx);
if(!mentionSpanSet.contains(mSpan) && !insideNE(mSpan, namedEntitySpanSet)) {
int mentionID = assignIds? ++maxID:-1;
Mention m = new Mention(mentionID, beginIdx, endIdx, dependency, new ArrayList<CoreLabel>(sent.subList(beginIdx, endIdx)), t);
mentions.add(m);
mentionSpanSet.add(mSpan);
}
}
}
示例8: 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);
}
}
示例9: evaluateTregexPattern
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
public List<String> evaluateTregexPattern(String parseTree, String tregexPattern)
{
List<String> foundMatches = new ArrayList<String>();
TregexPattern pattern = TregexPattern.compile(tregexPattern);
TregexMatcher matches = pattern.matcher(Tree.valueOf(parseTree));
Set<String> nodes = matches.getNodeNames();
while (matches.find())
{
foundMatches.add(matches.getMatch().pennString());
for (String node : nodes)
{
foundMatches.add(matches.getNode(node).pennString());
}
}
return foundMatches;
}
示例10: fillVectorWithYield
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
static void fillVectorWithYield(String[] vector, TregexMatcher tregexMatcher) {
while (tregexMatcher.find()) {
Tree match = tregexMatcher.getMatch();
List<Tree> leaves = match.getLeaves();
if (leaves.size() == 1) continue;
boolean seenStart = false;
for (Tree leaf : leaves) {
int index = ((HasIndex) leaf.label()).index() - 1;
if ( ! vector[index].equals("O")) break;
vector[index] = seenStart ? "I" : "B";
seenStart = true;
}
}
}
示例11: 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;
}
示例12: 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;
}
示例13: isVadj
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
private boolean isVadj(ExtractorMatcher matcher) {
for(TregexPattern vadj : vadjs)
{
// check VP matches Vadj patterns
TregexMatcher m = vadj.matcher(matcher.trigger);
if (m.find() && matcher.trigger == m.getMatch()) {
matcher.trigger = getLastJJ(m.getNode("tr"));
return true;
}
// check VP rightmost child matches Vadj patterns
Tree rightMostVp = RightMostVp.rightMostVp(matcher.trigger);
m = vadj.matcher(rightMostVp);
if (m.find() && rightMostVp == m.getMatch()) {
matcher.trigger = getLastJJ(m.getNode("tr"));
return true;
}
// check VP rightmost child's children matches Vadj patterns
for (Tree child : rightMostVp.children()) {
m = vadj.matcher(child);
if (m.find() && child == m.getMatch()) {
matcher.trigger = getLastJJ(m.getNode("tr"));
return true;
}
}
}
return false;
}
示例14: 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;
}
示例15: processPattern
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/**
* Tries to match a pattern against a tree. If it succeeds, apply the surgical operations contained in a {@link TsurgeonPattern}.
* @param matchPattern A {@link TregexPattern} to be matched against a {@link Tree}.
* @param p A {@link TsurgeonPattern} to apply.
* @param t the {@link Tree} to match against and perform surgery on.
* @return t, which has been surgically modified.
*/
public static Tree processPattern(TregexPattern matchPattern, TsurgeonPattern p, Tree t) {
TregexMatcher m = matchPattern.matcher(t);
while(m.find()) {
t = p.evaluate(t,m);
if(t==null)
break;
m = matchPattern.matcher(t);
}
return t;
}