Class WeightedGrammar
source code
object --+
|
cfg.Grammar --+
|
WeightedGrammar
A probabilistic context-free grammar. A Weighted Grammar consists of
a start state and a set of weighted productions. The set of terminals
and nonterminals is implicitly specified by the productions.
PCFG productions should be WeightedProduction
s.
WeightedGrammar
s impose the constraint that the set of
productions with any given left-hand-side must have probabilities that
sum to 1.
If you need efficient key-based access to productions, you can use a
subclass to implement it.
|
__init__(self,
start,
productions)
Create a new context-free grammar, from the given start state and set
of WeightedProduction s. |
source code
|
|
Inherited from cfg.Grammar :
__repr__ ,
__str__ ,
productions ,
start
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__
|
float
|
EPSILON = 0.01
The acceptable margin of error for checking that productions with a
given left-hand side have probabilities that sum to 1.
|
__init__(self,
start,
productions)
(Constructor)
| source code
|
Create a new context-free grammar, from the given start state and set
of WeightedProduction s.
- Parameters:
start (Nonterminal) - The start symbol
productions (list of Production ) - The list of productions that defines the grammar
- Raises:
ValueError - if the set of productions with any left-hand-side do not have
probabilities that sum to a value within EPSILON of 1.
- Overrides:
cfg.Grammar.__init__
|