edu.stanford.nlp.parser.lexparser
Class ExhaustivePCFGParser

java.lang.Object
  extended by edu.stanford.nlp.parser.lexparser.ExhaustivePCFGParser
All Implemented Interfaces:
KBestViterbiParser, Scorer, Parser, ViterbiParser
Direct Known Subclasses:
IterativeCKYPCFGParser

public class ExhaustivePCFGParser
extends Object
implements Scorer, KBestViterbiParser

An exhaustive generalized CKY PCFG parser. Fairly carefully optimized to be fast.

Author:
Dan Klein, Christopher Manning (I seem to maintain it....), Jenny Finkel (N-best and sampling code, former from Liang/Chiang)

Field Summary
protected  int arraySize
           
protected  float bestScore
           
protected  BinaryGrammar bg
           
protected  boolean floodTags
           
protected  String goalStr
           
protected  boolean[][] iPossibleByL
           
protected  boolean[][] iPossibleByR
           
protected  float[][][] iScore
           
protected  boolean[] isTag
           
protected  int length
           
protected  Lexicon lex
           
protected  Lattice lr
           
protected  int myMaxLength
           
protected  int[][] narrowLExtent
           
protected  int[][] narrowRExtent
           
protected  int numStates
           
protected  int[] offsets
           
protected  boolean[][] oFilteredEnd
           
protected  boolean[][] oFilteredStart
           
protected  Options op
           
protected  boolean[][] oPossibleByL
           
protected  boolean[][] oPossibleByR
           
protected  OutsideRuleFilter orf
           
protected  float[][][] oScore
           
protected  List sentence
           
protected  Numberer stateNumberer
           
protected  String stateSpace
           
protected  Numberer tagNumberer
           
protected  boolean[][] tags
           
protected  TreeFactory tf
           
protected  TreebankLanguagePack tlp
           
protected  UnaryGrammar ug
           
protected  int[][] wideLExtent
           
protected  int[][] wideRExtent
           
protected  Numberer wordNumberer
           
protected  int[] words
           
protected  int[][][] wordsInSpan
           
 
Constructor Summary
ExhaustivePCFGParser(BinaryGrammar bg, UnaryGrammar ug, Lexicon lex, Options op)
           
 
Method Summary
protected  void buildOFilter()
           
protected  void createArrays(int length)
           
protected  Tree extractBestParse(int goal, int start, int end)
           
protected  List<Tree> extractBestParses(int goal, int start, int end)
          Return all best parses (except no ties allowed on POS tags?).
 Tree getBestParse()
          Returns a best parse of the last sentence on which parse was called, or null if none exists.
 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.
 double getBestScore(String stateName)
           
 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)
           
 boolean iPossibleL(int state, int start)
           
 boolean iPossibleR(int state, int end)
           
 double iScore(Edge edge)
           
protected static boolean matches(double x, double y)
           
 void nudgeDownArraySize()
           
 boolean oPossible(Hook hook)
           
 boolean oPossibleL(int state, int start)
           
 boolean oPossibleR(int state, int end)
           
 double oScore(Edge edge)
           
 boolean parse(HTKLatticeReader lr)
           
 boolean parse(Lattice lr)
           
 boolean parse(List<? extends HasWord> sentence)
          Parses the given sentence.
 double scoreBinarizedTree(Tree tree, int start)
           
 Tree scoreNonBinarizedTree(Tree tree)
           
 void setGoalString(String goalStr)
           
protected static void tick(String str)
           
 double validateBinarizedTree(Tree tree, int start)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

goalStr

protected String goalStr

stateSpace

protected String stateSpace

stateNumberer

protected Numberer stateNumberer

wordNumberer

protected Numberer wordNumberer

tagNumberer

protected Numberer tagNumberer

tf

protected TreeFactory tf

bg

protected BinaryGrammar bg

ug

protected UnaryGrammar ug

lex

protected Lexicon lex

op

protected Options op

tlp

protected TreebankLanguagePack tlp

orf

protected OutsideRuleFilter orf

iScore

protected float[][][] iScore

oScore

protected float[][][] oScore

bestScore

protected float bestScore

wordsInSpan

protected int[][][] wordsInSpan

oFilteredStart

protected boolean[][] oFilteredStart

oFilteredEnd

protected boolean[][] oFilteredEnd

iPossibleByL

protected boolean[][] iPossibleByL

iPossibleByR

protected boolean[][] iPossibleByR

oPossibleByL

protected boolean[][] oPossibleByL

oPossibleByR

protected boolean[][] oPossibleByR

words

protected int[] words

offsets

protected int[] offsets

length

protected int length

tags

protected boolean[][] tags

myMaxLength

protected int myMaxLength

numStates

protected int numStates

arraySize

protected int arraySize

floodTags

protected boolean floodTags

sentence

protected List sentence

lr

protected Lattice lr

narrowLExtent

protected int[][] narrowLExtent

wideLExtent

protected int[][] wideLExtent

narrowRExtent

protected int[][] narrowRExtent

wideRExtent

protected int[][] wideRExtent

isTag

protected boolean[] isTag
Constructor Detail

ExhaustivePCFGParser

public ExhaustivePCFGParser(BinaryGrammar bg,
                            UnaryGrammar ug,
                            Lexicon lex,
                            Options op)
Method Detail

setGoalString

public void setGoalString(String goalStr)

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

oPossibleL

public boolean oPossibleL(int state,
                          int start)

oPossibleR

public boolean oPossibleR(int state,
                          int end)

iPossibleL

public boolean iPossibleL(int state,
                          int start)

iPossibleR

public boolean iPossibleR(int state,
                          int end)

buildOFilter

protected void buildOFilter()

validateBinarizedTree

public double validateBinarizedTree(Tree tree,
                                    int start)

scoreNonBinarizedTree

public Tree scoreNonBinarizedTree(Tree tree)

scoreBinarizedTree

public double scoreBinarizedTree(Tree tree,
                                 int start)

tick

protected static void tick(String str)

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

parse

public boolean parse(HTKLatticeReader lr)

parse

public boolean parse(Lattice lr)

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

matches

protected static boolean matches(double x,
                                 double y)

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.

getBestScore

public double getBestScore(String stateName)

getBestParse

public Tree getBestParse()
Description copied from interface: ViterbiParser
Returns a best parse of the last sentence on which parse was called, or null if none exists.

Specified by:
getBestParse in interface ViterbiParser
Returns:
The tree for the best parse

extractBestParse

protected Tree extractBestParse(int goal,
                                int start,
                                int end)

extractBestParses

protected List<Tree> extractBestParses(int goal,
                                       int start,
                                       int end)
Return all best parses (except no ties allowed on POS tags?). Even though we parse with the unary-closed grammar, since all the intermediate states in a chain must have been built, we can reconstruct the unary chain as we go using the non-unary-closed grammar.


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.

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

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

nudgeDownArraySize

public void nudgeDownArraySize()

createArrays

protected void createArrays(int length)


Stanford NLP Group