本文整理匯總了Java中edu.stanford.nlp.trees.Tree.getLeaves方法的典型用法代碼示例。如果您正苦於以下問題:Java Tree.getLeaves方法的具體用法?Java Tree.getLeaves怎麽用?Java Tree.getLeaves使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.stanford.nlp.trees.Tree
的用法示例。
在下文中一共展示了Tree.getLeaves方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getListOfRightMostCompleteNonTerminals
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
/**
* Identify the list of rightmost non-terminals that span a complete subtree, i.e., one that
* a) the leaf of its' rightmost child is a word, OR
* b) the index of the leaf of its' rightmost is a word AND is the last in the yield (AND this leaf is the last word - optional, as this condition breeches incrementality).
* @param analysisTree
* @return
*/
private List<Tree> getListOfRightMostCompleteNonTerminals(Tree tree)
{
List<Tree> list = new ArrayList();
List<Tree> leaves = tree.getLeaves();
// check if the last leaf is a word.
Tree currentWord = leaves.get(leaves.size() - 1);
if(currentWord.nodeString().endsWith("<>"))
{
Tree parent = currentWord.parent(tree);
while(parent != tree)
{
if(parent.isPhrasal())
{
list.add(parent);
}
parent = parent.parent(tree);
}
list.add(tree);
}
return list;
}
示例2: getLeavesOfRoot
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
public Clause getLeavesOfRoot(Tree tree)
{
ArrayList<Word> retList = new ArrayList<Word>();
for(Tree t: tree.getLeaves())
retList.add(new Word(t.label().value(), t.parent(tree).label().value()));
return new Clause(retList, tree.label().value());
}
示例3: getWordList
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
public ArrayList<Word> getWordList(Tree t)
{
ArrayList<Word> retList = new ArrayList<Word>();
for(Tree tree:t.getLeaves())
{
retList.add(new Word(tree.label().value(), tree.parent(t).label().value()));
}
return retList;
}
示例4: fillVectorWithYield
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
static void fillVectorWithYield(String[] vector, TregexMatcher tregexMatcher) {
while (tregexMatcher.find()) {
Tree match = tregexMatcher.getMatch();
List<Tree> leaves = match.getLeaves();
if (leaves.size() == 1) continue;
boolean seenStart = false;
for (Tree leaf : leaves) {
int index = ((HasIndex) leaf.label()).index() - 1;
if ( ! vector[index].equals("O")) break;
vector[index] = seenStart ? "I" : "B";
seenStart = true;
}
}
}
示例5: computeIncrementalTrees
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
public static Map<Integer, String> computeIncrementalTrees(String treeStr)
{
Map<Integer, String> map = new TreeMap<Integer, String>();
Tree tree = Tree.valueOf(treeStr);
List<Tree> leaves = tree.getLeaves();
Tree firstLeaf = leaves.get(0);
// first prefix tree by default is the sub-tree rooted on the preterminal (don't add, as we compute evalb for words>1)
// map.put(0, firstLeaf.parent(tree).toString());
for(int i = 1; i < leaves.size(); i++)
{
Tree lastLeaf = leaves.get(i);
map.put(i, getMinimalConnectedStructure(tree, firstLeaf, lastLeaf, i).toString());
}
return map;
}
示例6: computeIncrementalTree
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
public static String computeIncrementalTree(String treeStr)
{
Tree tree = Tree.valueOf(treeStr);
List<Tree> leaves = tree.getLeaves();
leaves.get(leaves.size() - 1);
return computeIncrementalTree(treeStr, leaves.size() - 1).toString();
}
示例7: getMinimalConnectedStructure
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
public static Tree getMinimalConnectedStructure(Tree tree, Tree firstLeaf, Tree lastLeaf, int lastLeafIndex)
{
// find common ancestor node by traversing the tree bottom-up from the last leaf and up
Tree commonAncestorNode = lastLeaf.parent(tree);
while(!commonAncestorNode.getLeaves().get(0).equals(firstLeaf))
{
commonAncestorNode = commonAncestorNode.parent(tree);
}
// found the common ancestor, now we need to clone the tree and chop the children non-terminals the span of which is outwith the last leaf
Tree result = commonAncestorNode.deepCopy();
List<Tree> leaves = result.getLeaves();
lastLeaf = leaves.get(lastLeafIndex);
Tree p = lastLeaf.parent(result);
Tree d = lastLeaf;
while(p != null)
{
if(p.numChildren() > 1)
{
// remove siblings to the right of d
int index = indexOfChild(p, d.nodeNumber(result), result);
pruneChildrenAfter(p, index);
}
d = p;
p = p.parent(result);
}
return result;
}
示例8: removeSubtreesAfterWord
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
public static String removeSubtreesAfterWord(String inputTree, int numOfLeaves)
{
Tree tree = Tree.valueOf(inputTree);
List<Tree> leaves = tree.getLeaves();
if(leaves.size() > numOfLeaves)
{
// find common ancestor between last valid leaf and extraneous leaf
Tree firstLeaf = leaves.get(numOfLeaves - 1);
Tree lastLeaf = leaves.get(leaves.size() - 1);
Tree commonAncestorNode = lastLeaf.parent(tree);
while(!commonAncestorNode.getLeaves().contains(firstLeaf))
{
commonAncestorNode = commonAncestorNode.parent(tree);
}
// found the common ancestor, now we need to chop the children nodes the span of which is outwith the last valid leaf
Tree p = lastLeaf.parent(tree);
while(p != commonAncestorNode)
{
int numOfChildren = p.numChildren();
for(int i = 0; i < numOfChildren; i++)
p.removeChild(0);
p = p.parent(tree);
}
// remove last leftover parent node of the invalid leaf
commonAncestorNode.removeChild(commonAncestorNode.numChildren() - 1);
return tree.toString();
}
else
{
return inputTree;
}
}
示例9: getChunkVector
import edu.stanford.nlp.trees.Tree; //導入方法依賴的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;
}