edu.stanford.nlp.parser.lexparser
Class LexicalizedParserQuery

java.lang.Object
  extended by edu.stanford.nlp.parser.lexparser.LexicalizedParserQuery

public class LexicalizedParserQuery
extends Object


Field Summary
protected  Function<List<? extends HasWord>,ArrayList<TaggedWord>> tagger
          The tagger optionally used before parsing.
 
Method Summary
 Tree getBestParse()
          Return the best parse of the sentence most recently parsed.
 List<ScoredObject<Tree>> getKBestPCFGParses(int k)
          Returns the trees (and scores) corresponding to the k-best derivations of the sentence.
 List<ScoredObject<Tree>> getKGoodFactoredParses(int k)
           
 TreePrint getTreePrint()
          Return a TreePrint for formatting parsed output trees.
 boolean parse(List<? extends HasWord> sentence)
          Parse a sentence represented as a List of tokens.
 void setConstraints(List<ParserConstraint> constraints)
           
 double testOnTreebank(Treebank testTreebank)
          Test the parser on a treebank.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tagger

protected Function<List<? extends HasWord>,ArrayList<TaggedWord>> tagger
The tagger optionally used before parsing.
We keep it here as a function rather than a MaxentTagger so that we can distribute a version of the parser that doesn't include the entire tagger.
TODO: pass this in rather than create it here if we wind up using this in more place. Right now it's only used in testOnTreebank.

Method Detail

setConstraints

public void setConstraints(List<ParserConstraint> constraints)

parse

public boolean parse(List<? extends HasWord> sentence)
Parse a sentence represented as a List of tokens. The text must already have been tokenized and normalized into tokens that are appropriate to the treebank which was used to train the parser. The tokens can be of multiple types, and the list items need not be homogeneous as to type (in particular, only some words might be given tags):

Parameters:
sentence - The sentence to parse
Returns:
true Iff the sentence was accepted by the grammar
Throws:
UnsupportedOperationException - If the Sentence is too long or of zero length or the parse otherwise fails for resource reasons

getBestParse

public Tree getBestParse()
Return the best parse of the sentence most recently parsed. This will be from the factored parser, if it was used and it succeeded else from the PCFG if it was used and succeed, else from the dependency parser.

Returns:
The best tree
Throws:
NoSuchElementException - If no previously successfully parsed sentence

getKGoodFactoredParses

public List<ScoredObject<Tree>> getKGoodFactoredParses(int k)

getKBestPCFGParses

public List<ScoredObject<Tree>> getKBestPCFGParses(int k)
Returns the trees (and scores) corresponding to the k-best derivations of the sentence. This cannot be a Counter because frequently there will be multiple derivations which lead to the same parse tree.

Parameters:
k - The number of best parses to return
Returns:
The list of trees with their scores (log prob).

testOnTreebank

public double testOnTreebank(Treebank testTreebank)
Test the parser on a treebank. Parses will be written to stdout, and various other information will be written to stderr and stdout, particularly if op.testOptions.verbose is true.

Parameters:
testTreebank - The treebank to parse
Returns:
The labeled precision/recall F1 (EVALB measure) of the parser on the treebank.

getTreePrint

public TreePrint getTreePrint()
Return a TreePrint for formatting parsed output trees.

Returns:
A TreePrint for formatting parsed output trees.


Stanford NLP Group