Package nltk_lite :: Package parse :: Module sr :: Class SteppingShiftReduce
[show private | hide private]
[frames | no frames]

Type SteppingShiftReduce

object --+            
         |            
    ParseI --+        
             |        
 AbstractParse --+    
                 |    
       ShiftReduce --+
                     |
                    SteppingShiftReduce


A ShiftReduce that allows you to setp through the parsing process, performing a single operation at a time. It also allows you to change the parser's grammar midway through parsing a text.

The initialize method is used to start parsing a text. shift performs a single shift operation, and reduce performs a single reduce operation. step will perform a single reduce operation if possible; otherwise, it will perform a single shift operation. parses returns the set of parses that have been found by the parser.

See Also: nltk.cfg

Method Summary
  __init__(self, grammar, trace)
Create a new ShiftReduce, that uses grammar to parse texts.
  get_parse_list(self, token)
  initialize(self, token)
Start parsing a given text.
list of Tree parses(self)
Return a list of the parses that have been found by this parser so far.
Production or None reduce(self, production)
Use production to combine the rightmost stack elements into a single Tree.
list of Production reducible_productions(self)
Return a list of the productions for which reductions are available for the current parser state.
list of String remaining_text(self)
Return the portion of the text that is not yet covered by the stack.
  set_grammar(self, grammar)
Change the grammar used to parse texts.
boolean shift(self)
Move a token from the beginning of the remaining text to the end of the stack.
list of String and Tree stack(self)
Return the parser's stack.
Production or boolean step(self)
Perform a single parsing operation.
boolean undo(self)
Return the parser to its state before the most recent shift or reduce operation.
Inherited from ShiftReduce: get_parse, trace
Inherited from AbstractParse: grammar, parse
Inherited from ParseI: get_parse_probs
Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Method Details

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

Create a new ShiftReduce, that uses grammar to parse texts.
Parameters:
grammar - The grammar used to parse texts.
           (type=Grammar)
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.
           (type=int)
Overrides:
nltk_lite.parse.sr.ShiftReduce.__init__ (inherited documentation)

initialize(self, token)

Start parsing a given text. This sets the parser's stack to [] and sets its remaining text to token['SUBTOKENS'].

parses(self)

Returns:
A list of the parses that have been found by this parser so far.
           (type=list of Tree)

reduce(self, production=None)

Use production to combine the rightmost stack elements into a single Tree. If production does not match the rightmost stack elements, then do nothing.
Returns:
The production used to reduce the stack, if a reduction was performed. If no reduction was performed, return None.
           (type=Production or None)

reducible_productions(self)

Returns:
A list of the productions for which reductions are available for the current parser state.
           (type=list of Production)

remaining_text(self)

Returns:
The portion of the text that is not yet covered by the stack.
           (type=list of String)

set_grammar(self, grammar)

Change the grammar used to parse texts.
Parameters:
grammar - The new grammar.
           (type=CFG)

shift(self)

Move a token from the beginning of the remaining text to the end of the stack. If there are no more tokens in the remaining text, then do nothing.
Returns:
True if the shift operation was successful.
           (type=boolean)

stack(self)

Returns:
The parser's stack.
           (type=list of String and Tree)

step(self)

Perform a single parsing operation. If a reduction is possible, then perform that reduction, and return the production that it is based on. Otherwise, if a shift is possible, then perform it, and return 1. Otherwise, return 0.
Returns:
0 if no operation was performed; 1 if a shift was performed; and the CFG production used to reduce if a reduction was performed.
           (type=Production or boolean)

undo(self)

Return the parser to its state before the most recent shift or reduce operation. Calling undo repeatedly return the parser to successively earlier states. If no shift or reduce operations have been performed, undo will make no changes.
Returns:
true if an operation was successfully undone.
           (type=boolean)

Generated by Epydoc 2.1 on Tue Sep 5 09:37:21 2006 http://epydoc.sf.net