List of usage examples for edu.stanford.nlp.trees Trees lexicalize
public static Tree lexicalize(Tree t, HeadFinder hf)
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. *//* ww w . j av a 2 s. 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()); } }