class documentation

An abstract bottom-up parser for PCFG grammars that uses a Chart to record partial results. BottomUpProbabilisticChartParser maintains a queue of edges that can be added to the chart. This queue is initialized with edges for each token in the text that is being parsed. BottomUpProbabilisticChartParser inserts these edges into the chart one at a time, starting with the most likely edges, and proceeding to less likely edges. For each edge that is added to the chart, it may become possible to insert additional edges into the chart; these are added to the queue. This process continues until enough complete parses have been generated, or until the queue is empty.

The sorting order for the queue is not specified by BottomUpProbabilisticChartParser. Different sorting orders will result in different search strategies. The sorting order for the queue is defined by the method sort_queue; subclasses are required to provide a definition for this method.

Method __init__ Create a new BottomUpProbabilisticChartParser, that uses grammar to parse texts.
Method grammar No summary
Method parse When possible this list is sorted from most likely to least likely.
Method sort_queue Sort the given queue of Edge objects, placing the edge that should be tried first at the beginning of the queue. This method will be called after each Edge is added to the queue.
Method trace Set the level of tracing output that should be generated when parsing a text.
Instance Variable beam_size Undocumented
Method _prune Discard items in the queue if the queue is longer than the beam.
Method _setprob Undocumented
Instance Variable _grammar The grammar used to parse sentences.
Instance Variable _trace The level of tracing output that should be generated when parsing a text.

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, beam_size=0, trace=0): (source)

Create a new BottomUpProbabilisticChartParser, that uses grammar to parse texts.

Parameters
grammar:PCFGThe grammar used to parse texts.
beam_size:intThe maximum length for the parser's edge queue.
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.
def grammar(self): (source)
Returns
The grammar used by this parser.
def parse(self, tokens): (source)

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

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

Sort the given queue of Edge objects, placing the edge that should be tried first at the beginning of the queue. This method will be called after each Edge is added to the queue.

Parameters
queue:list(Edge)The queue of Edge objects to sort. Each edge in this queue is an edge that could be added to the chart by the fundamental rule; but that has not yet been added.
chart:ChartThe chart being used to parse the text. This chart can be used to provide extra information for sorting the queue.
Returns
NoneUndocumented
def trace(self, trace=2): (source)

Set the level of tracing output that should be generated when parsing a text.

Parameters
trace:intThe trace level. A trace level of 0 will generate no tracing output; and higher trace levels will produce more verbose tracing output.
Returns
NoneUndocumented
beam_size = (source)

Undocumented

def _prune(self, queue, chart): (source)

Discard items in the queue if the queue is longer than the beam.

def _setprob(self, tree, prod_probs): (source)

Undocumented

_grammar: PCFG = (source)

The grammar used to parse sentences.

_trace: int = (source)

The level of tracing output that should be generated when parsing a text.