nltk.BottomUpProbabilisticChartParser

class nltk.BottomUpProbabilisticChartParser(grammar, beam_size=0, trace=0)[source]

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.

Variables:
  • _grammar – The grammar used to parse sentences.
  • _trace – The level of tracing output that should be generated when parsing a text.

Methods

__init__(grammar[, beam_size, trace]) Create a new BottomUpProbabilisticChartParser, that uses grammar to parse texts.
grammar()
parse(tokens)
parse_all(sent, *args, **kwargs)
rtype:list(Tree)
parse_one(sent, *args, **kwargs)
rtype:Tree or None
parse_sents(sents, *args, **kwargs) Apply self.parse() to each element of sents.
sort_queue(queue, chart) Sort the given queue of Edge objects, placing the edge that should be tried first at the beginning of the queue.
trace([trace]) Set the level of tracing output that should be generated when parsing a text.