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


Java TregexMatcher.matchesAt方法代码示例

本文整理汇总了Java中edu.stanford.nlp.trees.tregex.TregexMatcher.matchesAt方法的典型用法代码示例。如果您正苦于以下问题:Java TregexMatcher.matchesAt方法的具体用法?Java TregexMatcher.matchesAt怎么用?Java TregexMatcher.matchesAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.trees.tregex.TregexMatcher的用法示例。


在下文中一共展示了TregexMatcher.matchesAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyRuleOnNode

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
/**
 * Applies rule on the root node.
 * 
 * @param rule the rule to be applied.
 * @param tree the tree in which the target node is present.
 * @param targetNode the target node on which the rule has to be applied.
 * @return Returns true if a rule group is successfully applied on the root
 *         node.
 */
private static boolean applyRuleOnNode(TransformationRule rule,
    DependencyTree tree, DependencyTree targetNode) {
  TregexPattern tregex = rule.getTregex();
  TregexMatcher matcher = tregex.matcher(tree);
  if (matcher.matchesAt(targetNode)) {
    for (Transformation transformation : rule.getTransformationList()) {
      applyTransformation(transformation, matcher);
    }
    return true;
  }
  return false;
}
 
开发者ID:sivareddyg,项目名称:UDepLambda,代码行数:22,代码来源:TreeTransformer.java

示例2: transformTree

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入方法依赖的package包/类
@Override
public Tree transformTree(Tree t, Tree root) {

  String baseCat = t.value();
  StringBuilder newCategory = new StringBuilder();

  //Add manual state splits
  for (Pair<TregexPattern,Function<TregexMatcher,String>> e : activeAnnotations) {
    TregexMatcher m = e.first().matcher(root);
    if (m.matchesAt(t))
      newCategory.append(e.second().apply(m));
  }

  //Add morphosyntactic features if this is a POS tag
  if(t.isPreTerminal() && tagSpec != null) {
    if( !(t.firstChild().label() instanceof CoreLabel) || ((CoreLabel) t.firstChild().label()).originalText() == null )
      throw new RuntimeException(String.format("%s: Term lacks morpho analysis: %s",this.getClass().getName(),t.toString()));

    String morphoStr = ((CoreLabel) t.firstChild().label()).originalText();
    Pair<String,String> lemmaMorph = MorphoFeatureSpecification.splitMorphString("", morphoStr);
    MorphoFeatures feats = tagSpec.strToFeatures(lemmaMorph.second());
    baseCat = feats.getTag(baseCat);
  }

  //Update the label(s)
  String newCat = baseCat + newCategory.toString();
  t.setValue(newCat);
  if (t.isPreTerminal() && t.label() instanceof HasTag)
    ((HasTag) t.label()).setTag(newCat);

  return t;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:33,代码来源:FrenchTreebankParserParams.java


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