Package nltk :: Package parse :: Module chart :: Class ChartParser
[hide private]
[frames] | no frames]

type ChartParser

source code

 object --+    
          |    
api.ParserI --+
              |
             ChartParser
Known Subclasses:

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

Instance Methods [hide private]
 
__init__(self, grammar, strategy=[LeafInitRule(), EmptyPredictRule(), BottomUpPredictCombineRul..., trace=0, trace_chart_width=50, use_agenda=True, chart_class=<class 'nltk.parse.chart.Chart'>)
Create a new chart parser, that uses grammar to parse texts.
source code
 
grammar(self)
Returns: The grammar used by this parser.
source code
 
_trace_new_edges(self, chart, rule, new_edges, trace, edge_width) source code
Chart
chart_parse(self, tokens, trace=None)
Returns: The final parse Chart, from which all possible parse trees can be extracted.
source code
list of Tree
nbest_parse(self, tokens, n=None, tree_class=<class 'nltk.tree.Tree'>)
Returns: A list of parse trees that represent possible structures for the given sentence.
source code

Inherited from api.ParserI: batch_iter_parse, batch_nbest_parse, batch_parse, batch_prob_parse, iter_parse, parse, prob_parse

    Deprecated

Inherited from api.ParserI: batch_test, get_parse, get_parse_dict, get_parse_list, get_parse_prob

Method Details [hide private]

__init__(self, grammar, strategy=[LeafInitRule(), EmptyPredictRule(), BottomUpPredictCombineRul..., trace=0, trace_chart_width=50, use_agenda=True, chart_class=<class 'nltk.parse.chart.Chart'>)
(Constructor)

source code 

Create a new chart parser, that uses grammar to parse texts.

Parameters:
  • grammar (ContextFreeGrammar) - The grammar used to parse texts.
  • strategy (list of ChartRuleI) - A list of rules that should be used to decide what edges to add to the chart (top-down strategy by default).
  • 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.
  • use_agenda (bool) - Use an optimized agenda-based algorithm, if possible.
  • chart_class - The class that should be used to create the parse charts.
Overrides: object.__init__

grammar(self)

source code 
Returns:
The grammar used by this parser.
Overrides: api.ParserI.grammar
(inherited documentation)

chart_parse(self, tokens, trace=None)

source code 
Parameters:
  • tokens (list of string) - The sentence to be parsed
Returns: Chart
The final parse Chart, from which all possible parse trees can be extracted.

nbest_parse(self, tokens, n=None, tree_class=<class 'nltk.tree.Tree'>)

source code 
Parameters:
  • sent - The sentence to be parsed
  • n - The maximum number of trees to return.
Returns: list of Tree
A list of parse trees that represent possible structures for the given sentence. When possible, this list is sorted from most likely to least likely. If n is specified, then the returned list will contain at most n parse trees.
Overrides: api.ParserI.nbest_parse
(inherited documentation)