本文整理汇总了Java中edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon.processPattern方法的典型用法代码示例。如果您正苦于以下问题:Java Tsurgeon.processPattern方法的具体用法?Java Tsurgeon.processPattern怎么用?Java Tsurgeon.processPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon
的用法示例。
在下文中一共展示了Tsurgeon.processPattern方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChunkVector
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入方法依赖的package包/类
/**
* Extract chunks.
*
* @param tree
* @return
*/
private static int[] getChunkVector(Tree tree) {
String[] iobVector = new String[tree.yield().size()];
Arrays.fill(iobVector, "O");
// Yield patterns
// TregexPattern baseNPPattern = TregexPattern.compile("@NP < (/NN/ < (__ !< __)) !< @NP");
TregexPattern baseXPPattern = TregexPattern.compile("__ < (__ < (__ !< __)) !< (__ < (__ < __))");
TregexPattern basePPPattern = TregexPattern.compile("@PP <, @IN !<< @NP >! @PP");
TregexMatcher tregexMatcher = baseXPPattern.matcher(tree);
fillVectorWithYield(iobVector, tregexMatcher);
tregexMatcher = basePPPattern.matcher(tree);
fillVectorWithYield(iobVector, tregexMatcher);
// Edge patterns
TregexPattern vpPattern = TregexPattern.compile("@VP >! @VP");
TregexPattern argumentPattern = TregexPattern.compile("[email protected]=node > @VP !< (__ !< __)");
TregexPattern puncPattern = TregexPattern.compile("/^[^a-zA-Z0-9]+$/=node < __ ");
TsurgeonPattern p = Tsurgeon.parseOperation("delete node");
tregexMatcher = vpPattern.matcher(tree);
while (tregexMatcher.find()) {
Tree match = tregexMatcher.getMatch();
Tsurgeon.processPattern(argumentPattern, p, match);
Tsurgeon.processPattern(puncPattern, p, match);
List<Tree> leaves = match.getLeaves();
if (leaves.size() == 1) continue;
boolean seenStart = false;
int lastIndex = -1;
for (Tree leaf : leaves) {
int index = ((HasIndex) leaf.label()).index() - 1;
if (index < 0 || index >= iobVector.length) {
System.err.println("ERROR: Mangled subtree: " + match.toString());
continue;
}
if (lastIndex > 0 && index - lastIndex != 1) break;
if ( ! iobVector[index].equals("O")) break;
iobVector[index] = seenStart ? "I" : "B";
seenStart = true;
lastIndex = index;
}
}
int[] indexVector = iobToIndices(iobVector);
return indexVector;
}