本文整理汇总了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;
}
示例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;
}