Search in sources :

Example 1 with BasicCategoryTreeTransformer

use of edu.stanford.nlp.trees.BasicCategoryTreeTransformer 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;
}
Also used : BasicCategoryTreeTransformer(edu.stanford.nlp.trees.BasicCategoryTreeTransformer) BinaryHeadFinder(edu.stanford.nlp.parser.lexparser.BinaryHeadFinder) TreeBinarizer(edu.stanford.nlp.parser.lexparser.TreeBinarizer) HeadFinder(edu.stanford.nlp.trees.HeadFinder) BinaryHeadFinder(edu.stanford.nlp.parser.lexparser.BinaryHeadFinder) Tree(edu.stanford.nlp.trees.Tree) CompositeTreeTransformer(edu.stanford.nlp.trees.CompositeTreeTransformer)

Aggregations

BinaryHeadFinder (edu.stanford.nlp.parser.lexparser.BinaryHeadFinder)1 TreeBinarizer (edu.stanford.nlp.parser.lexparser.TreeBinarizer)1 BasicCategoryTreeTransformer (edu.stanford.nlp.trees.BasicCategoryTreeTransformer)1 CompositeTreeTransformer (edu.stanford.nlp.trees.CompositeTreeTransformer)1 HeadFinder (edu.stanford.nlp.trees.HeadFinder)1 Tree (edu.stanford.nlp.trees.Tree)1