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

Class 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=TD_STRATEGY, trace=0)
Create a new chart parser, that uses grammar to parse texts.
source code
 
grammar(self)
Returns: The grammar used by this parser.
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

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

    Deprecated

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, grammar, strategy=TD_STRATEGY, trace=0)
(Constructor)

source code 

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

Parameters:
  • grammar (cfg.Grammar) - 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.
Overrides: object.__init__

grammar(self)

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

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)