nltk.parse.RandomChartParser¶
- class nltk.parse.RandomChartParser[source]¶
Bases:
BottomUpProbabilisticChartParserA bottom-up parser for
PCFGgrammars that tries edges in random order. This sorting order results in a random search strategy.- sort_queue(queue, chart)[source]¶
Sort the given queue of
Edgeobjects, placing the edge that should be tried first at the beginning of the queue. This method will be called after eachEdgeis added to the queue.- Parameters
queue (list(Edge)) – The queue of
Edgeobjects 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 (Chart) – The chart being used to parse the text. This chart can be used to provide extra information for sorting the queue.
- Return type
None
- __init__(grammar, beam_size=0, trace=0)[source]¶
Create a new
BottomUpProbabilisticChartParser, that usesgrammarto parse texts.- Parameters
grammar (PCFG) – The grammar used to parse texts.
beam_size (int) – The maximum length for the parser’s edge queue.
trace (int) – The level of tracing that should be used when parsing a text.
0will generate no tracing output; and higher numbers will produce more verbose tracing output.
- parse(tokens)[source]¶
- Returns
An iterator that generates parse trees for the sentence. When possible this list is sorted from most likely to least likely.
- Parameters
sent (list(str)) – The sentence to be parsed
- Return type
iter(Tree)