class SteppingChartParser(ChartParser): (source)
Constructor: SteppingChartParser(grammar, strategy, trace)
A ChartParser that allows you to step through the parsing process, adding a single edge at a time. It also allows you to change the parser's strategy or grammar midway through parsing a text.
The initialize method is used to start parsing a text. step adds a single edge to the chart. set_strategy changes the strategy used by the chart parser. parses returns the set of parses that has been found by the chart parser.
Method | __init__ |
Create a new chart parser, that uses grammar to parse texts. |
Method | chart |
Return the chart that is used by this parser. |
Method | current |
Return the chart rule used to generate the most recent edge. |
Method | grammar |
Return the grammar used by this parser. |
Method | initialize |
Begin parsing the given tokens. |
Method | parse |
When possible this list is sorted from most likely to least likely. |
Method | parses |
Return the parse trees currently contained in the chart. |
Method | set |
Load a given chart into the chart parser. |
Method | set |
Change the grammar used by the parser. |
Method | set |
Change the strategy that the parser uses to decide which edges to add to the chart. |
Method | step |
Return a generator that adds edges to the chart, one at a time. Each time the generator is resumed, it adds a single edge and yields that edge. If no more edges can be added, then it yields None. |
Method | strategy |
Return the strategy used by this parser. |
Method | _parse |
A generator that implements the actual parsing algorithm. step iterates through this generator, and restarts it whenever the parser's strategy, grammar, or chart is modified. |
Instance Variable | _chart |
Undocumented |
Instance Variable | _current |
Undocumented |
Instance Variable | _grammar |
Undocumented |
Instance Variable | _restart |
Records whether the parser's strategy, grammar, or chart has been changed. If so, then step must restart the parsing algorithm. |
Instance Variable | _strategy |
Undocumented |
Inherited from ChartParser
:
Method | chart |
Return the final parse Chart from which all possible parse trees can be extracted. |
Method | _trace |
Undocumented |
Instance Variable | _axioms |
Undocumented |
Instance Variable | _chart |
Undocumented |
Instance Variable | _inference |
Undocumented |
Instance Variable | _trace |
Undocumented |
Instance Variable | _trace |
Undocumented |
Instance Variable | _use |
Undocumented |
Inherited from ParserI
(via ChartParser
):
Method | parse |
No summary |
Method | parse |
No summary |
Method | parse |
Apply self.parse() to each element of sents. :rtype: iter(iter(Tree)) |
nltk.parse.chart.ChartParser.__init__
Create a new chart parser, that uses grammar to parse texts.
Parameters | |
grammar:CFG | The grammar used to parse texts. |
strategy:list(ChartRuleI) | A list of rules that should be used to decide what edges to add to the chart (top-down strategy by default). |
trace:int | The level of tracing that should be used when parsing a text. 0 will generate no tracing output; and higher numbers will produce more verbose tracing output. |
trace | The default total width reserved for the chart in trace output. The remainder of each line will be used to display edges. |
use | Use an optimized agenda-based algorithm, if possible. |
chart | The class that should be used to create the parse charts. |
nltk.parse.chart.ChartParser.parse
When possible this list is sorted from most likely to least likely.
Parameters | |
tokens | Undocumented |
tree | Undocumented |
sent:list(str) | The sentence to be parsed |
Returns | |
iter(Tree) | An iterator that generates parse trees for the sentence. |
Change the strategy that the parser uses to decide which edges to add to the chart.
Parameters | |
strategy:list(ChartRuleI) | A list of rules that should be used to decide what edges to add to the chart. |
Return a generator that adds edges to the chart, one at a time. Each time the generator is resumed, it adds a single edge and yields that edge. If no more edges can be added, then it yields None.
If the parser's strategy, grammar, or chart is changed, then the generator will continue adding edges using the new strategy, grammar, or chart.
Note that this generator never terminates, since the grammar or strategy might be changed to values that would add new edges. Instead, it yields None when no more edges can be added with the current strategy and grammar.
A generator that implements the actual parsing algorithm. step iterates through this generator, and restarts it whenever the parser's strategy, grammar, or chart is modified.