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

Class SteppingChartParser

source code

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

A ChartParser that allows you to step through the parsing process, adding a single edge at a time. It also allows you to change the parser's strategy or grammar midway through parsing a text.

The initialize method is used to start parsing a text. step adds a single edge to the chart. set_strategy changes the strategy used by the chart parser. parses returns the set of parses that has been found by the chart parser.

Instance Methods [hide private]
 
__init__(self, grammar, strategy=None, trace=0)
Create a new chart parser, that uses grammar to parse texts.
source code
 
initialize(self, tokens)
Begin parsing the given tokens.
source code
 
step(self)
Returns: A generator that adds edges to the chart, one at a time.
source code
 
_parse(self)
A generator that implements the actual parsing algorithm.
source code
 
strategy(self)
Returns: The strategy used by this parser.
source code
 
grammar(self)
Returns: The grammar used by this parser.
source code
 
chart(self)
Returns: The chart that is used by this parser.
source code
 
current_chartrule(self)
Returns: The chart rule used to generate the most recent edge.
source code
 
parses(self, tree_class=<class 'nltk.tree.Tree'>)
Returns: The parse trees currently contained in the chart.
source code
 
set_strategy(self, strategy)
Change the startegy that the parser uses to decide which edges to add to the chart.
source code
 
set_grammar(self, grammar)
Change the grammar used by the parser.
source code
 
set_chart(self, chart)
Load a given chart into the chart 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

Instance Variables [hide private]
  _restart
Records whether the parser's strategy, grammar, or chart has been changed.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 

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

Parameters:
  • grammar - The grammar used to parse texts.
  • strategy - A list of rules that should be used to decide what edges to add to the chart (top-down strategy by default).
  • trace - 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: ChartParser.__init__
(inherited documentation)

step(self)

source code 
Returns:
A generator that adds edges to the chart, one at a time. Each time the generator is resumed, it adds a single edge and yields that edge. If no more edges can be added, then it yields None.

If the parser's strategy, grammar, or chart is changed, then the generator will continue adding edges using the new strategy, grammar, or chart.

Note that this generator never terminates, since the grammar or strategy might be changed to values that would add new edges. Instead, it yields None when no more edges can be added with the current strategy and grammar.

_parse(self)

source code 

A generator that implements the actual parsing algorithm. step iterates through this generator, and restarts it whenever the parser's strategy, grammar, or chart is modified.

strategy(self)

source code 
Returns:
The strategy used by this parser.

grammar(self)

source code 
Returns:
The grammar used by this parser.
Overrides: ChartParser.grammar

chart(self)

source code 
Returns:
The chart that is used by this parser.

current_chartrule(self)

source code 
Returns:
The chart rule used to generate the most recent edge.

parses(self, tree_class=<class 'nltk.tree.Tree'>)

source code 
Returns:
The parse trees currently contained in the chart.

set_strategy(self, strategy)

source code 

Change the startegy that the parser uses to decide which edges to add to the chart.

Parameters:
  • strategy (list of ChartRuleI) - A list of rules that should be used to decide what edges to add to the chart.

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: ChartParser.nbest_parse

Instance Variable Details [hide private]

_restart

Records whether the parser's strategy, grammar, or chart has been changed. If so, then step must restart the parsing algorithm.