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

type Production

source code

object --+
         |
        Production
Known Subclasses:

A grammar production. Each production maps a single symbol on the left-hand side to a sequence of symbols on the right-hand side. (In the case of context-free productions, the left-hand side must be a Nonterminal, and the right-hand side is a sequence of terminals and Nonterminals.) terminals can be any immutable hashable object that is not a Nonterminal. Typically, terminals are strings representing words, such as "dog" or "under".


See Also:
ContextFreeGrammar, DependencyGrammar, 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
integer
__len__(self)
Returns: the length of the right-hand side.
source code
bool
is_nonlexical(self)
Returns: True if the right-hand side only contains Nonterminals
source code
bool
is_lexical(self)
Returns: True if the right-hand contain at least one terminal token
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
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.
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.

__len__(self)
(Length operator)

source code 
Returns: integer
the length of the right-hand side.

is_nonlexical(self)

source code 
Returns: bool
True if the right-hand side only contains Nonterminals

is_lexical(self)

source code 
Returns: bool
True if the right-hand contain at least one terminal token

__str__(self)
(Informal representation operator)

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

__repr__(self)
(Representation operator)

source code 
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 
Returns: int
A hash value for the Production.
Overrides: object.__hash__