edu.stanford.nlp.parser.prefixparser
Class PrefixProbabilityParser

java.lang.Object
  extended by edu.stanford.nlp.parser.prefixparser.PrefixProbabilityParser

public class PrefixProbabilityParser
extends java.lang.Object

An implementation of the Stolcke 1995 chart parsing algorithm that calculates the prefix probability of a string S with respect to a probabilistic context-free grammar G. The prefix probability is defined as the total probability of the set of all trees T such that S is a prefix of T. As a side effect, the parser also calculates the total probability of S being a complete sentence in G.

The intended usage is as follows: a PrefixProbabilityParser is vended by the PrefixProbabilityParserGenerator.getParser() method of a a PrefixProbabilityParserGenerator generator instance, which in turn is obtained by training a generator on a collection of context-free trees (see the PrefixProbabilityParserGenerator.getGenerator(edu.stanford.nlp.trees.Treebank, java.lang.String) method). Then use the loadSentence(java.util.List) method to load a sentence (a List of words (Strings)) into the parser. The parse chart for the string can then be incrementally constructed with the parseNextWord() method. At any time, the current prefix probability and string probability of the words parsed so far can be accessed with the prefixProbability() and stringProbability() methods respectively. See the source code of the main method of this class for further details of use.


Method Summary
 boolean hasNextWord()
          returns true iff there is another word in the loaded sentence that has not been parsed yet
 void loadSentence(java.util.List<java.lang.String> sentence)
          Loads a sentence (a List of Strings) into the parser for parsing.
static void main(java.lang.String[] args)
           
 void parseNextWord()
          call this method to read in the next word from the input and build the corresponding chart entries
 void parseSentences(java.io.Reader r)
          Parse a list of pre-tokenized sentences, one per line, from a Reader.
 double prefixProbability()
          Returns the total probability for prefix parses of the string prefix parsed so far.
 java.lang.String previousWord()
          returns the previous word parsed.
 double stringProbability()
          Returns the total probability of complete parses for the string prefix parsed so far.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadSentence

public void loadSentence(java.util.List<java.lang.String> sentence)
Loads a sentence (a List of Strings) into the parser for parsing.


hasNextWord

public boolean hasNextWord()
returns true iff there is another word in the loaded sentence that has not been parsed yet


previousWord

public java.lang.String previousWord()
returns the previous word parsed.


parseNextWord

public void parseNextWord()
call this method to read in the next word from the input and build the corresponding chart entries


stringProbability

public double stringProbability()
Returns the total probability of complete parses for the string prefix parsed so far.


prefixProbability

public double prefixProbability()
Returns the total probability for prefix parses of the string prefix parsed so far.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

parseSentences

public void parseSentences(java.io.Reader r)
                    throws java.io.IOException
Parse a list of pre-tokenized sentences, one per line, from a Reader.

Throws:
java.io.IOException