Example usage for edu.stanford.nlp.parser.lexparser LexicalizedParser parse

List of usage examples for edu.stanford.nlp.parser.lexparser LexicalizedParser parse

Introduction

In this page you can find the example usage for edu.stanford.nlp.parser.lexparser LexicalizedParser parse.

Prototype

@Override
public Tree parse(List<? extends HasWord> lst) 

Source Link

Document

Parses the list of HasWord.

Usage

From source file:cc.vidr.parseviz.ParseViz.java

License:Open Source License

public static Tree parse(String s) {
    if (treeCache.containsKey(s))
        return treeCache.get(s);
    Reader r = new StringReader(s);
    List<? extends HasWord> sentence = tokenizerFactory.getTokenizer(r).tokenize();
    LexicalizedParser parser = new LexicalizedParser(parserData);
    parser.parse(sentence);
    Tree tree = parser.getBestParse();// w  w w .  ja va  2s.com
    tree = debinarizer.transformTree(tree);
    treeCache.put(s, tree);
    return tree;
}

From source file:com.parse.Dependency.java

public static void main(String[] args) {
    LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
    lp.setOptionFlags(new String[] { "-maxLength", "80", "-retainTmpSubcategories", });

    String[] sent = { "This", "is", "an", "easy", "sentence", "." };
    List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent);
    Tree parse = lp.apply(rawWords);/*w w w .j av  a2  s . c  om*/
    parse.pennPrint();
    System.out.println();

    TreebankLanguagePack tlp = new PennTreebankLanguagePack();
    GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
    GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
    List<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
    System.out.println(tdl);
    //System.out.println();

    //TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed");
    // tp.printTree(parse);

    String sentence = "which movies were directed by Christopher Nolan";
    Tree t2 = lp.parse(sentence);
    System.out.println(t2.firstChild().toString());
    gs = gsf.newGrammaticalStructure(t2);
    tdl = gs.typedDependenciesCCprocessed();
    System.out.println(tdl);
    System.out.println(tdl.get(0).dep().nodeString());

}