edu.stanford.nlp.parser.lexparser
Class ExhaustiveDependencyParser

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

public class ExhaustiveDependencyParser
extends Object
implements Scorer, KBestViterbiParser

An exhaustive O(n4t2) time and O(n2t) space dependency parser. This follows the general picture of the Eisner and Satta dependency parsing papers, but without the tricks in defining items that they use to get an O(n3) dependency parser. The parser is as described in:

Dan Klein and Christopher D. Manning. 2003. Fast Exact Inference with a Factored Model for Natural Language Parsing. In Suzanna Becker, Sebastian Thrun, and Klaus Obermayer (eds), Advances in Neural Information Processing Systems 15 (NIPS 2002). Cambridge, MA: MIT Press, pp. 3-10. http://nlp.stanford.edu/pubs/lex-parser.pdf

Author:
Dan Klein

Constructor Summary
ExhaustiveDependencyParser(DependencyGrammar dg, Lexicon lex, Options op)
           
 
Method Summary
 void displayHeadScores()
          This displays a headScore matrix, which will be valid after parsing a sentence.
 Tree getBestParse()
          Return the best dependency parse for a sentence.
 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.
 List<ScoredObject<Tree>> getKBestParses(int k)
          Get the exact k best parses for the sentence.
 List<ScoredObject<Tree>> getKGoodParses(int k)
          Get k good parses for the sentence.
 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 iPossible(Hook hook)
           
 double iScore(Edge edge)
           
 boolean oPossible(Hook hook)
           
 double oScore(Edge edge)
           
 boolean parse(List<? extends HasWord> sentence)
          Parses the given sentence.
 boolean parse(List<? extends HasWord> sentence, String goal)
          Parses the given sentence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExhaustiveDependencyParser

public ExhaustiveDependencyParser(DependencyGrammar dg,
                                  Lexicon lex,
                                  Options op)
Method Detail

oScore

public double oScore(Edge edge)
Specified by:
oScore in interface Scorer

iScore

public double iScore(Edge edge)
Specified by:
iScore in interface Scorer

oPossible

public boolean oPossible(Hook hook)
Specified by:
oPossible in interface Scorer

iPossible

public boolean iPossible(Hook hook)
Specified by:
iPossible in interface Scorer

parse

public boolean parse(List<? extends HasWord> sentence,
                     String goal)
Description copied from interface: Parser
Parses the given sentence. For any words in the sentence which implement HasTag, the tag will be believed. The return value will be false if the sentence is not parseable. Acceptance is with respect to the given goal category. (Successfully using this method thus depends on having a good understanding of the categories used by the grammar.)

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 the sentence is recognized

parse

public boolean parse(List<? extends HasWord> sentence)
Description copied from interface: Parser
Parses the given sentence. For any words in the sentence which implement HasTag, the tag will be believed. The return value will be false if the sentence is not parseable. Acceptance is with respect to some goal category, which may be specified by the grammar, or may be a parser default (for instance, S).

Specified by:
parse in interface Scorer
Specified by:
parse in interface Parser
Parameters:
sentence - A List<HasWord> to be parsed
Returns:
true iff the sentence is recognized

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

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.

displayHeadScores

public void displayHeadScores()
This displays a headScore matrix, which will be valid after parsing a sentence. Unclear yet whether this is valid/useful [cdm].


getBestParse

public Tree getBestParse()
Return the best dependency parse for a sentence. You must call parse() before a call to this method.

Implementation note: the best parse is recalculated from the chart each time this method is called. It isn't cached.

Specified by:
getBestParse in interface ViterbiParser
Returns:
The best dependency parse for a sentence or null. The returned tree will begin with a binary branching node, the left branch of which is the dependency tree proper, and the right side of which contains a boundary word .$. which heads the sentence.

getKBestParses

public 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 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

getKGoodParses

public List<ScoredObject<Tree>> getKGoodParses(int k)
Get k good parses for the sentence. It is expected that the parses returned approximate the k best parses, but without any guarantee that the exact list of k best parses has been produced. If a class really provides k best parses functionality, it is reasonable to also return this output as the k good parses.

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

getKSampledParses

public 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