Search in sources :

Example 1 with BinaryHeadFinder

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;
}
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)

Example 2 with BinaryHeadFinder

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

Example 3 with BinaryHeadFinder

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;
}
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) ArrayList(java.util.ArrayList) Tree(edu.stanford.nlp.trees.Tree) CompositeTreeTransformer(edu.stanford.nlp.trees.CompositeTreeTransformer)

Aggregations

BinaryHeadFinder (edu.stanford.nlp.parser.lexparser.BinaryHeadFinder)3 HeadFinder (edu.stanford.nlp.trees.HeadFinder)3 Tree (edu.stanford.nlp.trees.Tree)3 TreeBinarizer (edu.stanford.nlp.parser.lexparser.TreeBinarizer)2 BasicCategoryTreeTransformer (edu.stanford.nlp.trees.BasicCategoryTreeTransformer)2 CompositeTreeTransformer (edu.stanford.nlp.trees.CompositeTreeTransformer)2 Options (edu.stanford.nlp.parser.lexparser.Options)1 ArrayList (java.util.ArrayList)1