A simple top-down CFG parser that parses texts by recursively
expanding the fringe of a Tree
, and matching it against a
text.
When the parser begins parsing a text, it constructs a tree containing
only the start symbol, and a frontier containing the location of the
tree's root node. It then extends the tree to cover the text, using the
following recursive procedure:
|
__init__(self,
grammar,
trace=0)
Create a new RecursiveDescentParser , that uses
grammar to parse texts. |
source code
|
|
|
|
list of Tree
|
nbest_parse(self,
tokens,
n=None)
Returns:
A list of parse trees that represent possible structures for the
given sentence. |
source code
|
|
list of Tree
|
_parse(self,
remaining_text,
tree,
frontier)
Recursively expand and match each elements of tree
specified by frontier , to cover
remaining_text . |
source code
|
|
list of Tree
|
_match(self,
rtext,
tree,
frontier)
Returns:
a list of all parses that can be generated by matching the first
element of frontier against the first token in
rtext . |
source code
|
|
list of Tree
|
_expand(self,
remaining_text,
tree,
frontier,
production=None)
Returns:
A list of all parses that can be generated by expanding the first
element of frontier with production . |
source code
|
|
Tree
|
|
None
|
trace(self,
trace=2)
Set the level of tracing output that should be generated when parsing
a text. |
source code
|
|
None
|
|
None
|
_trace_tree(self,
tree,
frontier,
operation)
Print trace output displaying the parser's current state. |
source code
|
|
|
|
|
_trace_expand(self,
tree,
frontier,
production) |
source code
|
|
|
|
|
|
|
_trace_backtrack(self,
tree,
frontier,
toks=None) |
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__
|
Inherited from api.ParserI :
batch_test ,
get_parse ,
get_parse_dict ,
get_parse_list ,
get_parse_prob
|