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

Class Production

source code

object --+
         |
        Production
Known Subclasses:

A context-free grammar production. Each production expands a single Nonterminal (the left-hand side) to a sequence of terminals and Nonterminals (the right-hand side). terminals can be any immutable hashable object that is not a Nonterminal. Typically, terminals are strings representing word types, such as "dog" or "under".

Abstractly, a Grammar production indicates that the right-hand side is a possible instantiation of the left-hand side. Grammar productions are context-free, in the sense that this instantiation should not depend on the context of the left-hand side or of the right-hand side.


See Also:
Grammar, Nonterminal
Instance Methods [hide private]
 
__init__(self, lhs, rhs)
Construct a new Production.
source code
Nonterminal
lhs(self)
Returns: the left-hand side of this Production.
source code
sequence of (Nonterminal and (terminal))
rhs(self)
Returns: the right-hand side of this Production.
source code
string
__str__(self)
Returns: A verbose string representation of the Production.
source code
string
__repr__(self)
Returns: A concise string representation of the Production.
source code
boolean
__eq__(self, other)
Returns: true if this Production is equal to other.
source code
 
__ne__(self, other) source code
 
__cmp__(self, other) source code
int
__hash__(self)
Returns: A hash value for the Production.
source code

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

Instance Variables [hide private]
Nonterminal _lhs
The left-hand side of the production.
tuple of (Nonterminal and (terminal)) _rhs
The right-hand side of the production.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, lhs, rhs)
(Constructor)

source code 

Construct a new Production.

Parameters:
  • lhs (Nonterminal) - The left-hand side of the new Production.
  • rhs (sequence of (Nonterminal and (terminal))) - The right-hand side of the new Production.
Overrides: object.__init__

lhs(self)

source code 
Returns: Nonterminal
the left-hand side of this Production.

rhs(self)

source code 
Returns: sequence of (Nonterminal and (terminal))
the right-hand side of this Production.

__str__(self)
(Informal representation operator)

source code 

str(x)

Returns: string
A verbose string representation of the Production.
Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

repr(x)

Returns: string
A concise string representation of the Production.
Overrides: object.__repr__

__eq__(self, other)
(Equality operator)

source code 
Returns: boolean
true if this Production is equal to other.

__hash__(self)
(Hashing function)

source code 

hash(x)

Returns: int
A hash value for the Production.
Overrides: object.__hash__