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

Class Grammar

source code

object --+
         |
        Grammar
Known Subclasses:

A context-free grammar. A Grammar consists of a start state and a set of productions. The set of terminals and nonterminals is implicitly specified by the productions.

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, lexicon=None)
Create a new context-free grammar, from the given start state and set of Productions.
source code
 
start(self) source code
 
productions(self, lhs=None, rhs=None) source code
 
lexicon(self) source code
 
check_coverage(self, tokens)
Check whether the grammar rules cover the given list of tokens.
source code
 
covers(self, tokens)
Check whether the grammar rules cover the given list of tokens.
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, start, productions, lexicon=None)
(Constructor)

source code 

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

Parameters:
  • start (Nonterminal) - The start symbol
  • productions (list of Production) - The list of productions that defines the grammar
Overrides: object.__init__

check_coverage(self, tokens)

source code 

Check whether the grammar rules cover the given list of tokens. If not, then raise an exception.

covers(self, tokens)

source code 

Check whether the grammar rules cover the given list of tokens.

Parameters:
  • tokens (a list of string objects.) - the given list of tokens.
Returns:
True/False

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)