edu.stanford.nlp.parser.lexparser
Class BiLexPCFGParser

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

public class BiLexPCFGParser
extends java.lang.Object
implements KBestViterbiParser

Implements Eisner and Satta style algorithms for bilexical PCFG parsing. The basic class provides O(n4) parsing, with the passed in PCFG and dependency parsers providing outside scores in an efficient A* search.

Author:
Dan Klein

Nested Class Summary
static class BiLexPCFGParser.N5BiLexPCFGParser
           
 
Field Summary
protected  Heap<Item> agenda
           
protected  BinaryGrammar bg
           
protected  long builtEdges
           
protected  long builtHooks
           
protected  edu.stanford.nlp.parser.lexparser.HookChart chart
           
protected  DependencyGrammar dg
           
protected  ExhaustiveDependencyParser dparser
           
protected  long extractedEdges
           
protected  long extractedHooks
           
protected  ExhaustivePCFGParser fscorer
           
protected  Edge goal
           
protected  edu.stanford.nlp.parser.lexparser.Interner interner
           
protected  Edge iTemp
           
protected  int length
           
protected  Lexicon lex
           
protected  java.util.List<Edge> nGoodTrees
           
protected  Options op
           
protected  CoreLabel[] originalLabels
           
protected  Edge oTemp
           
protected  GrammarProjection projection
           
protected  long relaxHook1
           
protected  long relaxHook2
           
protected  long relaxHook3
           
protected  long relaxHook4
           
protected  Scorer scorer
           
protected  Numberer stateNumberer
           
protected  java.util.List<IntTaggedWord>[] taggedWordList
           
protected  Numberer tagNumberer
           
protected  Edge tempEdge
           
protected  Hook tempHook
           
protected  TreeFactory tf
           
protected  UnaryGrammar ug
           
protected static boolean VERBOSE
           
protected static boolean VERY_VERBOSE
           
protected  Numberer wordNumberer
           
protected  int[] words
           
 
Constructor Summary
BiLexPCFGParser(Scorer scorer, ExhaustivePCFGParser fscorer, ExhaustiveDependencyParser dparser, BinaryGrammar bg, UnaryGrammar ug, DependencyGrammar dg, Lexicon lex, Options op)
           
 
Method Summary
protected static boolean better(double x, double y)
           
protected  double buildOScore(Hook hook)
           
protected  void combine(Edge edge, Hook hook)
           
protected  void discoverEdge(Edge edge)
           
protected  void discoverHook(Hook hook)
           
protected  void discoverItem(Item item)
           
protected  Tree extractParse(Edge edge)
           
 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 k "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.
protected  void initialize(java.util.List<? extends HasWord> words)
           
protected static Item makeInitialItem(int pos, int tag, int state, double iScore)
           
protected  java.util.List<Item> makeInitialItems(java.util.List<? extends HasWord> wordList)
           
 boolean parse(java.util.List<? extends HasWord> words)
          Parse a Sentence.
protected  void postMortem()
           
protected  void processEdge(Edge edge)
           
protected  void processHook(Hook hook)
           
protected  void processItem(Item item)
           
protected  int project(int state)
           
protected  void projectHooks(Edge edge)
           
protected  void projectUnaries(Edge edge)
           
protected  void registerReal(Edge real)
           
protected  void relaxTempEdge()
           
protected  void relaxTempHook()
           
protected  void scoreDependencies()
           
protected  void setGoal(int length)
           
protected  void triggerAllHooks(Edge edge)
           
protected  void triggerHooks(Edge edge)
           
 
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

VERY_VERBOSE

protected static final boolean VERY_VERBOSE
See Also:
Constant Field Values

chart

protected edu.stanford.nlp.parser.lexparser.HookChart chart

agenda

protected Heap<Item> agenda

length

protected int length

words

protected int[] words

goal

protected Edge goal

interner

protected edu.stanford.nlp.parser.lexparser.Interner interner

scorer

protected Scorer scorer

fscorer

protected ExhaustivePCFGParser fscorer

dparser

protected ExhaustiveDependencyParser dparser

projection

protected GrammarProjection projection

bg

protected BinaryGrammar bg

ug

protected UnaryGrammar ug

dg

protected DependencyGrammar dg

lex

protected Lexicon lex

op

protected Options op

taggedWordList

protected java.util.List<IntTaggedWord>[] taggedWordList

wordNumberer

protected Numberer wordNumberer

tagNumberer

protected Numberer tagNumberer

stateNumberer

protected Numberer stateNumberer

originalLabels

protected CoreLabel[] originalLabels

tf

protected TreeFactory tf

relaxHook1

protected long relaxHook1

relaxHook2

protected long relaxHook2

relaxHook3

protected long relaxHook3

relaxHook4

protected long relaxHook4

builtHooks

protected long builtHooks

builtEdges

protected long builtEdges

extractedHooks

protected long extractedHooks

extractedEdges

protected long extractedEdges

nGoodTrees

protected java.util.List<Edge> nGoodTrees

tempEdge

protected Edge tempEdge

iTemp

protected Edge iTemp

oTemp

protected Edge oTemp

tempHook

protected Hook tempHook
Constructor Detail

BiLexPCFGParser

public BiLexPCFGParser(Scorer scorer,
                       ExhaustivePCFGParser fscorer,
                       ExhaustiveDependencyParser dparser,
                       BinaryGrammar bg,
                       UnaryGrammar ug,
                       DependencyGrammar dg,
                       Lexicon lex,
                       Options op)
Method Detail

better

protected static boolean better(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.

extractParse

protected Tree extractParse(Edge edge)

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

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 k "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 k best trees

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

combine

protected void combine(Edge edge,
                       Hook hook)

relaxTempEdge

protected void relaxTempEdge()

discoverEdge

protected void discoverEdge(Edge edge)

discoverHook

protected void discoverHook(Hook hook)

buildOScore

protected double buildOScore(Hook hook)

projectHooks

protected void projectHooks(Edge edge)

registerReal

protected void registerReal(Edge real)

triggerHooks

protected void triggerHooks(Edge edge)

triggerAllHooks

protected void triggerAllHooks(Edge edge)

relaxTempHook

protected void relaxTempHook()

projectUnaries

protected void projectUnaries(Edge edge)

processEdge

protected void processEdge(Edge edge)

processHook

protected void processHook(Hook hook)

processItem

protected void processItem(Item item)

discoverItem

protected void discoverItem(Item item)

makeInitialItem

protected static Item makeInitialItem(int pos,
                                      int tag,
                                      int state,
                                      double iScore)

makeInitialItems

protected java.util.List<Item> makeInitialItems(java.util.List<? extends HasWord> wordList)

scoreDependencies

protected void scoreDependencies()

setGoal

protected void setGoal(int length)

initialize

protected void initialize(java.util.List<? extends HasWord> words)

parse

public boolean parse(java.util.List<? extends HasWord> words)
Parse a Sentence.

Specified by:
parse in interface Parser
Parameters:
words - A List<HasWord> to be parsed
Returns:
true iff it could be parsed

postMortem

protected void postMortem()

project

protected int project(int state)


Stanford NLP Group