Package nltk :: Module cfg :: Class WeightedGrammar
[hide private]
[frames] | no frames]

Class WeightedGrammar

source code

object --+    
         |    
   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 WeightedProductions. WeightedGrammars 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.

Instance Methods [hide private]
 
__init__(self, start, productions)
Create a new context-free grammar, from the given start state and set of WeightedProductions.
source code

Inherited from Grammar: __repr__, __str__, check_coverage, covers, lexicon, productions, start

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

Class Variables [hide private]
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.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, start, productions)
(Constructor)

source code 

Create a new context-free grammar, from the given start state and set of WeightedProductions.

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: Grammar.__init__