class documentation

A generic chart parser. A "strategy", or list of ChartRuleI instances, is used to decide what edges to add to the chart. In particular, ChartParser uses the following algorithm to parse texts:

Until no new edges are added:
For each rule in strategy:
Apply rule to any applicable edges in the chart.
Return any complete parses in the chart
Method __init__ Create a new chart parser, that uses grammar to parse texts.
Method chart_parse Return the final parse Chart from which all possible parse trees can be extracted.
Method grammar No summary
Method parse When possible this list is sorted from most likely to least likely.
Method _trace_new_edges Undocumented
Instance Variable _axioms Undocumented
Instance Variable _chart_class Undocumented
Instance Variable _grammar Undocumented
Instance Variable _inference_rules Undocumented
Instance Variable _strategy Undocumented
Instance Variable _trace Undocumented
Instance Variable _trace_chart_width Undocumented
Instance Variable _use_agenda Undocumented

Inherited from ParserI:

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=BU_LC_STRATEGY, trace=0, trace_chart_width=50, use_agenda=True, chart_class=Chart): (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_parse(self, tokens, trace=None): (source)

Return the final parse Chart from which all possible parse trees can be extracted.

Parameters
tokens:list(str)The sentence to be parsed
traceUndocumented
Returns
ChartUndocumented
def grammar(self): (source)
Returns
The grammar used by this parser.
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 _trace_new_edges(self, chart, rule, new_edges, trace, edge_width): (source)

Undocumented

_axioms: list = (source)
_inference_rules: list = (source)
_strategy = (source)

Undocumented

_trace_chart_width = (source)
_use_agenda = (source)

Undocumented