edu.stanford.nlp.parser.lexparser
Class FastFactoredParser

java.lang.Object
  extended by edu.stanford.nlp.parser.lexparser.FastFactoredParser
All Implemented Interfaces:
KBestViterbiParser, Parser, ViterbiParser

public class FastFactoredParser
extends java.lang.Object
implements KBestViterbiParser

Provides a much faster way to realize the factored parsing idea, including easily returning "k good" results at the expense of optimality. Exploiting the k best functionality of the ExhaustivePCFGParser, this model simply gets more than k best PCFG parsers, scores them according to the dependency grammar, and returns them in terms of their product score. No actual parsing is done.

Author:
Christopher Manning

Field Summary
protected  MLEDependencyGrammar dg
           
protected  Options op
           
protected  ExhaustivePCFGParser pparser
           
protected  GrammarProjection projection
           
protected static boolean VERBOSE
           
 
Method Summary
 Tree getBestParse()
          Return the best parse of the sentence most recently parsed.
 java.util.List<ScoredObject<Tree>> getBestParses()
          Get a complete set of the maximally scoring parses for a sentence, rather than one chosen at random.
 double getBestScore()
          Gets the score (typically a log probability) of the best parse of a sentence.
 java.util.List<ScoredObject<Tree>> getKBestParses(int k)
          Get the exact k best parses for the sentence.
 java.util.List<ScoredObject<Tree>> getKGoodParses(int k)
          Return the list of N "good" parses of the sentence most recently parsed.
 java.util.List<ScoredObject<Tree>> getKSampledParses(int k)
          Get k parse samples for the sentence.
 boolean hasParse()
          Does the sentence in the last call to parse() have a parse? In theory this method shouldn't be here, but it seemed a convenient place to put it for our more general parser interface.
 boolean parse(java.util.List<? extends HasWord> words)
          Parse a Sentence.
 boolean parse(java.util.List<? extends HasWord> sentence, java.lang.String goal)
          Parse a Sentence.
protected  int project(int state)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

protected static final boolean VERBOSE
See Also:
Constant Field Values

pparser

protected ExhaustivePCFGParser pparser

projection

protected GrammarProjection projection

dg

protected MLEDependencyGrammar dg

op

protected Options op
Method Detail

project

protected int project(int state)

getBestParse

public Tree getBestParse()
Return the best parse of the sentence most recently parsed.

Specified by:
getBestParse in interface ViterbiParser
Returns:
The best (highest score) tree

getBestScore

public double getBestScore()
Description copied from interface: KBestViterbiParser
Gets the score (typically a log probability) of the best parse of a sentence.

Specified by:
getBestScore in interface KBestViterbiParser
Returns:
The score for the last sentence parsed.

hasParse

public boolean hasParse()
Description copied from interface: KBestViterbiParser
Does the sentence in the last call to parse() have a parse? In theory this method shouldn't be here, but it seemed a convenient place to put it for our more general parser interface.

Specified by:
hasParse in interface KBestViterbiParser
Returns:
Whether the last sentence parsed had a parse

getKGoodParses

public java.util.List<ScoredObject<Tree>> getKGoodParses(int k)
Return the list of N "good" parses of the sentence most recently parsed. (The first is guaranteed to be the best, but later ones are only guaranteed the best subject to the possibilities that disappear because the PCFG/Dep charts only store the best over each span.)

Specified by:
getKGoodParses in interface KBestViterbiParser
Parameters:
k - The number of good parses to return
Returns:
The list of N best trees

parse

public boolean parse(java.util.List<? extends HasWord> sentence,
                     java.lang.String goal)
Parse a Sentence. This hasn't yet been implemented. At present the goal is ignored.

Specified by:
parse in interface Parser
Parameters:
sentence - A Sentence to be parsed
goal - The category to parse the sentence as (e.g., NP, S)
Returns:
true iff it could be parsed

parse

public boolean parse(java.util.List<? extends HasWord> words)
Parse a Sentence. It is assumed that when this is called, the pparser has already been called to parse the sentence.

Specified by:
parse in interface Parser
Parameters:
words - The list of words to parse.
Returns:
true iff it could be parsed

getKBestParses

public java.util.List<ScoredObject<Tree>> getKBestParses(int k)
Get the exact k best parses for the sentence.

Specified by:
getKBestParses in interface KBestViterbiParser
Parameters:
k - The number of best parses to return
Returns:
The exact k best parses for the sentence, with each accompanied by its score (typically a negative log probability).

getBestParses

public java.util.List<ScoredObject<Tree>> getBestParses()
Get a complete set of the maximally scoring parses for a sentence, rather than one chosen at random. This set may be of size 1 or larger.

Specified by:
getBestParses in interface KBestViterbiParser
Returns:
All the equal best parses for a sentence, with each accompanied by its score

getKSampledParses

public java.util.List<ScoredObject<Tree>> getKSampledParses(int k)
Get k parse samples for the sentence. It is expected that the parses are sampled based on their relative probability.

Specified by:
getKSampledParses in interface KBestViterbiParser
Parameters:
k - The number of sampled parses to return
Returns:
A list of k parse samples for the sentence, with each accompanied by its score


Stanford NLP Group