/** * Assign sequential integer indices to the leaves of the tree * rooted at this {@code Tree}, starting with 1. * The leaves are traversed from left * to right. If the node is already indexed, then it uses the existing index. * This will only work if the leaves extend CoreMap. */ public void indexLeaves() { indexLeaves(1, false); }
/** * Index the leaves, and optionally overwrite existing IndexAnnotations if they exist. * * @param overWrite Whether to replace an existing index for a leaf. */ public void indexLeaves(boolean overWrite) { indexLeaves(1, overWrite); }
/** * Sets the label of the leaf nodes of a Tree to be the CoreLabels in the given sentence. * The original value() of the Tree nodes is preserved, and otherwise the label of tree * leaves becomes the label from the List. */ // todo [cdm 2015]: This clearly shouldn't be here! Maybe it's not needed at all now since parsing code does this? public static void mergeLabels(Tree tree, List<CoreLabel> sentence) { int idx = 0; for (Tree t : tree.getLeaves()) { CoreLabel cl = sentence.get(idx ++); String value = t.value(); cl.set(CoreAnnotations.ValueAnnotation.class, value); t.setLabel(cl); } tree.indexLeaves(); }
protected static void extractNPorPRP(CoreMap s, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet) { List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class); Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class); tree.indexLeaves(); SemanticGraph dependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class); TregexPattern tgrepPattern = npOrPrpMentionPattern; TregexMatcher matcher = tgrepPattern.matcher(tree); while (matcher.find()) { Tree t = matcher.getMatch(); List<Tree> mLeaves = t.getLeaves(); int beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1; int endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class); if (",".equals(sent.get(endIdx-1).word())) { endIdx--; } // try not to have span that ends with , IntPair mSpan = new IntPair(beginIdx, endIdx); if(!mentionSpanSet.contains(mSpan) && !insideNE(mSpan, namedEntitySpanSet)) { int dummyMentionId = -1; Mention m = new Mention(dummyMentionId, beginIdx, endIdx, dependency, new ArrayList<>(sent.subList(beginIdx, endIdx)), t); mentions.add(m); mentionSpanSet.add(mSpan); } } } /** Extract enumerations (A, B, and C) */
evalGuess.indexLeaves(true); final Tree evalGold = tc.transformTree(goldTree); evalGold.indexLeaves(true);
private static void extractNPorPRP(CoreMap s, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet) { List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class); Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class); tree.indexLeaves(); SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); SemanticGraph enhancedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
public void extractNPorPRP(CoreMap s, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet) { List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class); Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class); tree.indexLeaves(); SemanticGraph basicDependency = s.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); SemanticGraph enhancedDependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
startIndex = kid.indexLeaves(startIndex, overWrite);
Tree indexedTree = outputTree.deepCopy(outputTree.treeFactory(), CoreLabel.factory()); indexedTree.indexLeaves(); Set<Dependency<Label, Label, Object>> depsSet = indexedTree.mapDependencies(dependencyWordFilter, hf); List<Dependency<Label, Label, Object>> sortedDeps = new ArrayList<>(depsSet); indexedTree.indexLeaves(); List<Dependency<Label, Label, Object>> sortedDeps = getSortedDeps(indexedTree, dependencyWordFilter); for (Dependency<Label, Label, Object> d : sortedDeps) { it.indexLeaves(); indexedTree.indexLeaves(); Set<Dependency<Label, Label, Object>> depsSet = null; boolean failed = false;
public static List<Tree> binarizeTreebank(Treebank treebank, Options op) { TreeBinarizer binarizer = TreeBinarizer.simpleTreeBinarizer(op.tlpParams.headFinder(), op.tlpParams.treebankLanguagePack()); BasicCategoryTreeTransformer basicTransformer = new BasicCategoryTreeTransformer(op.langpack()); CompositeTreeTransformer transformer = new CompositeTreeTransformer(); transformer.addTransformer(binarizer); transformer.addTransformer(basicTransformer); treebank = treebank.transform(transformer); HeadFinder binaryHeadFinder = new BinaryHeadFinder(op.tlpParams.headFinder()); List<Tree> binarizedTrees = Generics.newArrayList(); for (Tree tree : treebank) { Trees.convertToCoreLabels(tree); tree.percolateHeadAnnotations(binaryHeadFinder); // Index from 1. Tools downstream expect index from 1, so for // uses internal to the srparser we have to renormalize the // indices, with the result that here we have to index from 1 tree.indexLeaves(1, true); binarizedTrees.add(tree); } return binarizedTrees; }
treePCFGeval.indexLeaves(true); transGoldTree.indexLeaves(true); pcfgDA.evaluate(treePCFGeval, transGoldTree, pwErr); goldTreeEval.indexLeaves(true); goldTreeEval.percolateHeads(op.langpack().headFinder()); depDAEval.indexLeaves(true); depDAEval.percolateHeadIndices(); if (depDA != null) {
/** * Assign sequential integer indices to the leaves of the tree * rooted at this {@code Tree}, starting with 1. * The leaves are traversed from left * to right. If the node is already indexed, then it uses the existing index. * This will only work if the leaves extend CoreMap. */ public void indexLeaves() { indexLeaves(1, false); }
/** * Assign sequential integer indices to the leaves of the tree * rooted at this {@code Tree}, starting with 1. * The leaves are traversed from left * to right. If the node is already indexed, then it uses the existing index. * This will only work if the leaves extend CoreMap. */ public void indexLeaves() { indexLeaves(1, false); }
/** * Index the leaves, and optionally overwrite existing IndexAnnotations if they exist. * * @param overWrite Whether to replace an existing index for a leaf. */ public void indexLeaves(boolean overWrite) { indexLeaves(1, overWrite); }
/** * Assign sequential integer indices to the leaves of the tree * rooted at this <code>Tree</code>, starting with 1. * The leaves are traversed from left * to right. If the node is already indexed, then it uses the existing index. * This will only work if the leaves extend CoreMap. */ public void indexLeaves() { indexLeaves(1); }
/** * Assign sequential integer indices to the leaves of the tree * rooted at this <code>Tree</code>, starting with 1. * The leaves are traversed from left * to right. If the node is already indexed, then it uses the existing index. * This will only work if the leaves extend CoreMap. */ public void indexLeaves() { indexLeaves(1, false); }
/** * Index the leaves, and optionally overwrite existing IndexAnnotations if they exist. * * @param overWrite Whether to replace an existing index for a leaf. */ public void indexLeaves(boolean overWrite) { indexLeaves(1, overWrite); }
/** * Index the leaves, and optionally overwrite existing IndexAnnotations if they exist. * * @param overWrite Whether to replace an existing index for a leaf. */ public void indexLeaves(boolean overWrite) { indexLeaves(1, overWrite); }
public void setTree(Tree tree) { if (!(tree.label() instanceof CoreLabel)) { tree = tree.deepCopy(tree.treeFactory(), CoreLabel.factory()); } tree.indexLeaves(); this.tree = tree; }