Package nltk :: Package parse :: Module chart
[hide private]
[frames] | no frames]

Module chart

source code

Data classes and parser implementations for "chart parsers", which use dynamic programming to efficiently parse a text. A chart parser derives parse trees for a text by iteratively adding "edges" to a "chart." Each edge represents a hypothesis about the tree structure for a subsequence of the text. The chart is a "blackboard" for composing and combining these hypotheses.

When a chart parser begins parsing a text, it creates a new (empty) chart, spanning the text. It then incrementally adds new edges to the chart. A set of chart rules specifies the conditions under which new edges should be added to the chart. Once the chart reaches a stage where none of the chart rules adds any new edges, parsing is complete.

Charts are encoded with the Chart class, and edges are encoded with the TreeEdge and LeafEdge classes. The chart parser module defines three chart parsers:

Classes [hide private]
EdgeI
A hypothesis about the structure of part of a sentence.
TreeEdge
An edge that records the fact that a tree is (partially) consistent with the sentence.
LeafEdge
An edge that records the fact that a leaf value is consistent with a word in the sentence.
Chart
A blackboard for hypotheses about the syntactic constituents of a sentence.
ChartRuleI
A rule that specifies what new edges are licensed by any given set of existing edges.
AbstractChartRule
An abstract base class for chart rules.
FundamentalRule
A rule that joins two adjacent edges to form a single combined edge.
SingleEdgeFundamentalRule
A rule that joins a given edge with adjacent edges in the chart, to form combined edges.
LeafInitRule
TopDownInitRule
A rule licensing edges corresponding to the grammar productions for the grammar's start symbol.
TopDownPredictRule
A rule licensing edges corresponding to the grammar productions for the nonterminal following an incomplete edge's dot.
CachedTopDownPredictRule
A cached version of TopDownPredictRule.
BottomUpPredictRule
A rule licensing any edge corresponding to a production whose right-hand side begins with a complete edge's left-hand side.
BottomUpPredictCombineRule
A rule licensing any edge corresponding to a production whose right-hand side begins with a complete edge's left-hand side.
EmptyPredictRule
A rule that inserts all empty productions as passive edges, in every position in the chart.
FilteredSingleEdgeFundamentalRule
FilteredBottomUpPredictCombineRule
ChartParser
A generic chart parser.
TopDownChartParser
A ChartParser using a top-down parsing strategy.
BottomUpChartParser
A ChartParser using a bottom-up parsing strategy.
BottomUpLeftCornerChartParser
A ChartParser using a bottom-up left-corner parsing strategy.
LeftCornerChartParser
SteppingChartParser
A ChartParser that allows you to step through the parsing process, adding a single edge at a time.
Functions [hide private]
 
_bottomup_filter(grammar, nexttoken, rhs, dot=0) source code
 
demo_grammar() source code
 
demo(choice=None, should_print_times=True, should_print_grammar=False, should_print_trees=True, trace=2, sent='I saw John with a dog with my cookie', numparses=5)
A demonstration of the chart parsers.
source code
Variables [hide private]
  TD_STRATEGY = [LeafInitRule(), TopDownInitRule(), CachedTopDow...
  BU_STRATEGY = [LeafInitRule(), EmptyPredictRule(), BottomUpPre...
  BU_LC_STRATEGY = [LeafInitRule(), EmptyPredictRule(), BottomUp...
  LC_STRATEGY = [LeafInitRule(), FilteredBottomUpPredictCombineR...
Variables Details [hide private]

TD_STRATEGY

Value:
[LeafInitRule(), TopDownInitRule(), CachedTopDownPredictRule(), Single\
EdgeFundamentalRule()]

BU_STRATEGY

Value:
[LeafInitRule(), EmptyPredictRule(), BottomUpPredictRule(), SingleEdge\
FundamentalRule()]

BU_LC_STRATEGY

Value:
[LeafInitRule(), EmptyPredictRule(), BottomUpPredictCombineRule(), Sin\
gleEdgeFundamentalRule()]

LC_STRATEGY

Value:
[LeafInitRule(), FilteredBottomUpPredictCombineRule(), FilteredSingleE\
dgeFundamentalRule()]