class documentation

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_chartrule 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_chart Load a given chart into the chart parser.
Method set_grammar Change the grammar used by the parser.
Method set_strategy 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_chartrule 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_parse Return the final parse Chart from which all possible parse trees can be extracted.
Method _trace_new_edges Undocumented
Instance Variable _axioms Undocumented
Instance Variable _chart_class Undocumented
Instance Variable _inference_rules Undocumented
Instance Variable _trace Undocumented
Instance Variable _trace_chart_width Undocumented
Instance Variable _use_agenda Undocumented

Inherited from ParserI (via ChartParser):

Method parse_all No summary
Method parse_one No summary
Method parse_sents Apply self.parse() to each element of sents. :rtype: iter(iter(Tree))
def __init__(self, grammar, strategy=[], trace=0): (source)

Create a new chart parser, that uses grammar to parse texts.

Parameters
grammar:CFGThe 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:intThe 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_chart_width:intThe default total width reserved for the chart in trace output. The remainder of each line will be used to display edges.
use_agenda:boolUse an optimized agenda-based algorithm, if possible.
chart_classThe class that should be used to create the parse charts.
def chart(self): (source)

Return the chart that is used by this parser.

def current_chartrule(self): (source)

Return the chart rule used to generate the most recent edge.

def grammar(self): (source)

Return the grammar used by this parser.

def initialize(self, tokens): (source)

Begin parsing the given tokens.

def parse(self, tokens, tree_class=Tree): (source)

When possible this list is sorted from most likely to least likely.

Parameters
tokensUndocumented
tree_classUndocumented
sent:list(str)The sentence to be parsed
Returns
iter(Tree)An iterator that generates parse trees for the sentence.
def parses(self, tree_class=Tree): (source)

Return the parse trees currently contained in the chart.

def set_chart(self, chart): (source)

Load a given chart into the chart parser.

def set_grammar(self, grammar): (source)

Change the grammar used by the parser.

def set_strategy(self, strategy): (source)

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.
def step(self): (source)

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.

def strategy(self): (source)

Return the strategy used by this parser.

def _parse(self): (source)

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.

Undocumented

_current_chartrule = (source)

Undocumented

_restart: bool = (source)

Records whether the parser's strategy, grammar, or chart has been changed. If so, then step must restart the parsing algorithm.