nltk.parse.IncrementalChartParser¶
- class nltk.parse.IncrementalChartParser[source]¶
Bases:
ChartParser
An incremental chart parser implementing Jay Earley’s parsing algorithm:
For each index end in [0, 1, …, N]:For each edge such that edge.end = end:If edge is incomplete and edge.next is not a part of speech:Apply PredictorRule to edgeIf edge is incomplete and edge.next is a part of speech:Apply ScannerRule to edgeIf edge is complete:Apply CompleterRule to edgeReturn any complete parses in the chart- __init__(grammar, strategy=[<nltk.parse.chart.LeafInitRule object>, <nltk.parse.chart.EmptyPredictRule object>, <nltk.parse.chart.BottomUpPredictCombineRule object>, <nltk.parse.earleychart.CompleteFundamentalRule object>], trace=0, trace_chart_width=50, chart_class=<class 'nltk.parse.earleychart.IncrementalChart'>)[source]¶
Create a new Earley chart parser, that uses
grammar
to parse texts.- Parameters
grammar (CFG) – The grammar used to parse texts.
trace (int) – The 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 (int) – The default total width reserved for the chart in trace output. The remainder of each line will be used to display edges.
chart_class – The class that should be used to create the charts used by this parser.
- chart_parse(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
- Return type