Example usage for edu.stanford.nlp.trees TreeFunctions getLabeledToDescriptiveCoreLabelTreeFunction

List of usage examples for edu.stanford.nlp.trees TreeFunctions getLabeledToDescriptiveCoreLabelTreeFunction

Introduction

In this page you can find the example usage for edu.stanford.nlp.trees TreeFunctions getLabeledToDescriptiveCoreLabelTreeFunction.

Prototype

public static Function<Tree, Tree> getLabeledToDescriptiveCoreLabelTreeFunction() 

Source Link

Document

Returns a function which takes a tree with any label class where the labels might have an interesting description, such as a CategoryWordTag which goes "cat [T/W]", and returns a new tree with CoreLabels which contain the toString() of each of the input labels.

Usage

From source file:org.ets.research.nlp.stanford_thrift.parser.StanfordParserThrift.java

License:Open Source License

/** If one were to call any of these other methods to get a parse tree for some input sentence
 * with the -outputFormatOptions flag of "lexicalize", they would receive their parse tree,
 * in the -outputFormat of their choice, with every leaf marked with it's head word.
 * This function does exactly that on an existing parse tree.
 * NOTE that this WILL re-lexicalize a pre-lexicalized tree, so don't pass in a tree that
 * has been lexicalized and expect to get back the same thing as what you passed in.
 *//*from   w w w  . ja  v a  2s .c o m*/
public String lexicalize_parse_tree(String tree) throws TApplicationException {
    try {
        Tree parseTree = Tree.valueOf(tree);
        Tree lexicalizedTree = Trees.lexicalize(parseTree, tlp.headFinder());
        treePrinter = ParserUtil.setOptions(null, tlp); // use defaults
        Function<Tree, Tree> a = TreeFunctions.getLabeledToDescriptiveCoreLabelTreeFunction();
        lexicalizedTree = a.apply(lexicalizedTree);
        return ParserUtil.TreeObjectToString(lexicalizedTree, treePrinter);
    } catch (Exception e) {
        // FIXME
        throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.getMessage());
    }
}