Package nltk_lite :: Package contrib :: Package mit :: Package six863 :: Package parse :: Module chart :: Class SteppingChartParse
[hide private]
[frames] | no frames]

Class SteppingChartParse

source code

        object --+            
                 |            
   __init__.ParseI --+        
                     |        
__init__.AbstractParse --+    
                         |    
                ChartParse --+
                             |
                            SteppingChartParse

A ChartParse 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_lite.parse.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
get_parse_list(self, token, tree_class=<class 'nltk_lite.parse.tree.Tree'>)
Returns: A list of the parse trees for the sentence.
source code

Inherited from __init__.AbstractParse: batch_test, get_parse, parse

Inherited from __init__.ParseI: get_parse_dict, get_parse_probs

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

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.

Overrides: ChartParse.__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: __init__.AbstractParse.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_lite.parse.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.

get_parse_list(self, token, tree_class=<class 'nltk_lite.parse.tree.Tree'>)

source code 
Returns: list of Tree
A list of the parse trees for the sentence. When possible, this list should be sorted from most likely to least likely.
Overrides: ChartParse.get_parse_list

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.