本文整理汇总了Java中edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon类的典型用法代码示例。如果您正苦于以下问题:Java Tsurgeon类的具体用法?Java Tsurgeon怎么用?Java Tsurgeon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Tsurgeon类属于edu.stanford.nlp.trees.tregex.tsurgeon包,在下文中一共展示了Tsurgeon类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseOperation
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
public static TOperationPattern parseOperation(String line) {
String operations[] = line.split("[,]+");
TOperationPattern top = new TOperationPattern();
for (String operation : operations) {
String toks[] = operation.trim().split("[ ]+");
if (toks[0].equals("prune")
|| toks[0].equals("replace")
|| toks[0].equals("insert")
|| toks[0].equals("move")
|| toks[0].equals("relabel")) {
top.operations.add(Tsurgeon.parseOperation(operation));
} else if (toks[0].equals("new")) {
top.operations.add(NewNode.parseOperation(operation));
} else {
throw new TsurgeonParseException("Error parsing Tsurgeon expression: "
+ toks[0]
+ ":"
+ line, null);
}
}
return top;
}
示例2: UCPtransform
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
/**
* Transforms t if it contains an UCP, it will change the UCP tag
* into the phrasal tag of the first word of the UCP
* (UCP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
* will become
* (ADJP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
*
* @param t a tree to be transformed
* @return t transformed
*/
public static Tree UCPtransform(Tree t) {
Tree firstChild = t.firstChild();
if (firstChild != null) {
List<Pair<TregexPattern,TsurgeonPattern>> ops = Generics.newArrayList();
for (int i = 0; i < operations.length; i++) {
for (TregexPattern pattern : matchPatterns[i]) {
ops.add(Generics.newPair(pattern, operations[i]));
}
}
return Tsurgeon.processPatternsOnTree(ops, t);
} else {
return t;
}
}
示例3: UCPtransform
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
/**
* Transforms t if it contains an UCP, it will change the UCP tag
* into the phrasal tag of the first word of the UCP
* (UCP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
* will become
* (ADJP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
*
* @param t a tree to be transformed
* @return t transformed
*/
public static Tree UCPtransform(Tree t) {
if (t == null) {
return null;
}
Tree firstChild = t.firstChild();
if (firstChild != null) {
List<Pair<TregexPattern,TsurgeonPattern>> ops = Generics.newArrayList();
for (int i = 0; i < operations.length; i++) {
for (TregexPattern pattern : matchPatterns[i]) {
ops.add(Generics.newPair(pattern, operations[i]));
}
}
return Tsurgeon.processPatternsOnTree(ops, t);
} else {
return t;
}
}
示例4: loadOps
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
private List<Pair<TregexPattern, TsurgeonPattern>> loadOps() {
List<Pair<TregexPattern,TsurgeonPattern>> ops = new ArrayList<Pair<TregexPattern,TsurgeonPattern>>();
String line = null;
try {
BufferedReader br = new BufferedReader(new StringReader(editStr));
List<TsurgeonPattern> tsp = new ArrayList<TsurgeonPattern>();
while ((line = br.readLine()) != null) {
if (DEBUG) System.err.print("Pattern is " + line);
TregexPattern matchPattern = TregexPattern.compile(line);
if (DEBUG) System.err.println(" [" + matchPattern + "]");
tsp.clear();
while (continuing(line = br.readLine())) {
TsurgeonPattern p = Tsurgeon.parseOperation(line);
if (DEBUG) System.err.println("Operation is " + line + " [" + p + "]");
tsp.add(p);
}
if ( ! tsp.isEmpty()) {
TsurgeonPattern tp = Tsurgeon.collectOperations(tsp);
ops.add(new Pair<TregexPattern,TsurgeonPattern>(matchPattern, tp));
}
} // while not at end of file
} catch (IOException ioe) {
ioe.printStackTrace();
}
return ops;
}
示例5: 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;
}
示例6: stripEmptyNode
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
protected static Tree stripEmptyNode(Tree t) {
List<Pair<TregexPattern, TsurgeonPattern>> ops = Generics.newArrayList();
ops.add(Generics.newPair(matchPattern, operation));
return Tsurgeon.processPatternsOnTree(ops, t);
}
示例7: visitTree
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
public void visitTree(Tree t) {
Tsurgeon.processPatternsOnTree(ops, t);
}
示例8: transformTree
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
public Tree transformTree(Tree t) {
return Tsurgeon.processPatternsOnTree(ops, t);
}