当前位置: 首页>>代码示例>>Java>>正文


Java TregexMatcher.getNodeNames方法代码示例

本文整理汇总了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;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:27,代码来源:GrammaticalRelation.java

示例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;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:30,代码来源:GrammaticalRelation.java

示例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;
}
 
开发者ID:dmnapolitano,项目名称:stanford-thrift,代码行数:19,代码来源:StanfordTregexThrift.java


注:本文中的edu.stanford.nlp.trees.tregex.TregexMatcher.getNodeNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。