edu.stanford.nlp.trees.tregex.tsurgeon.IfExistsNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-corenlp Show documentation
Show all versions of stanford-corenlp Show documentation
Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.
package edu.stanford.nlp.trees.tregex.tsurgeon;
import java.util.Map;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.tregex.TregexMatcher;
/**
* Executes the give children only if the named Tregex node exists in
* the TregexMatcher at match time (allows for OR relations or
* optional relations)
*
* @author John Bauer ([email protected])
*/
class IfExistsNode extends TsurgeonPattern {
final String name;
final boolean invert;
public IfExistsNode(String name, boolean invert, TsurgeonPattern ... children) {
super("if " + (invert ? "not " : "") + "exists " + name, children);
this.name = name;
this.invert = invert;
}
@Override
public TsurgeonMatcher matcher(Map newNodeNames, CoindexationGenerator coindexer) {
return new Matcher(newNodeNames, coindexer);
}
private class Matcher extends TsurgeonMatcher {
public Matcher(Map newNodeNames, CoindexationGenerator coindexer) {
super(IfExistsNode.this, newNodeNames, coindexer);
}
@Override
public Tree evaluate(Tree tree, TregexMatcher tregex) {
if (invert ^ (tregex.getNode(name) != null)) {
for (TsurgeonMatcher child : childMatcher) {
child.evaluate(tree, tregex);
}
}
return tree;
}
}
}