use of edu.stanford.nlp.parser.lexparser.BinaryHeadFinder in project CoreNLP by stanfordnlp.
the class ShiftReduceParser method binarizeTreebank.
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;
}
use of edu.stanford.nlp.parser.lexparser.BinaryHeadFinder in project CoreNLP by stanfordnlp.
the class ShiftReduceParserTest method convertTree.
Tree convertTree(String treeText) {
Options op = new Options();
HeadFinder binaryHeadFinder = new BinaryHeadFinder(op.tlpParams.headFinder());
Tree tree = Tree.valueOf(treeText);
Trees.convertToCoreLabels(tree);
tree.percolateHeadAnnotations(binaryHeadFinder);
return tree;
}
use of edu.stanford.nlp.parser.lexparser.BinaryHeadFinder in project CoreNLP by stanfordnlp.
the class ShiftReduceParser method binarizeTreebank.
public static List<Tree> binarizeTreebank(Iterable<Tree> 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);
List<Tree> transformedTrees = new ArrayList<>();
for (Tree tree : treebank) {
transformedTrees.add(transformer.transformTree(tree));
}
HeadFinder binaryHeadFinder = new BinaryHeadFinder(op.tlpParams.headFinder());
List<Tree> binarizedTrees = new ArrayList<>();
for (Tree tree : transformedTrees) {
if (!tree.isBinarized()) {
log.warn("Found a tree which was not properly binarized. So-called binarized tree is as follows:\n" + tree.pennString());
continue;
}
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;
}
Aggregations