本文整理汇总了Java中edu.stanford.nlp.trees.tregex.TregexMatcher.getNodeNames方法的典型用法代码示例。如果您正苦于以下问题:Java TregexMatcher.getNodeNames方法的具体用法?Java TregexMatcher.getNodeNames怎么用?Java TregexMatcher.getNodeNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.trees.tregex.TregexMatcher
的用法示例。
在下文中一共展示了TregexMatcher.getNodeNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRelatedNodes
import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/** Given a {@code Tree} node {@code t}, attempts to
* return a list of nodes to which node {@code t} has this
* grammatical relation, with {@code t} as the governor.
*
* @param t Target for finding dependents of t related by this GR
* @param root The root of the Tree
* @return A Collection of dependent nodes to which t bears this GR
*/
public Collection<Tree> getRelatedNodes(Tree t, Tree root) {
Set<Tree> nodeList = new ArraySet<Tree>();
for (TregexPattern p : targetPatterns) { // cdm: I deleted: && nodeList.isEmpty()
TregexMatcher m = p.matcher(root);
while (m.findAt(t)) {
nodeList.add(m.getNode("target"));
if (DEBUG) {
System.err.println("found " + this + "(" + t + ", " + m.getNode("target") + ") using pattern " + p);
for (String nodeName : m.getNodeNames()) {
if (nodeName.equals("target"))
continue;
System.err.println(" node " + nodeName + ": " + m.getNode(nodeName));
}
}
}
}
return nodeList;
}
示例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.findAt(t)) {
nodeList.add(m.getNode("target"));
if (DEBUG) {
System.err.println("found " + this + "(" + t + ", " + m.getNode("target") + ") using pattern " + p);
for (String nodeName : m.getNodeNames()) {
if (nodeName.equals("target"))
continue;
System.err.println(" node " + nodeName + ": " + m.getNode(nodeName));
}
}
}
}
return nodeList;
}
示例3: 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;
}