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

Class Nonterminal

source code

object --+
         |
        Nonterminal
Known Subclasses:

A non-terminal symbol for a context free grammar. Nonterminal is a wrapper class for node values; it is used by Productions to distinguish node values from leaf values. The node value that is wrapped by a Nonterminal is known as its symbol. Symbols are typically strings representing phrasal categories (such as "NP" or "VP"). However, more complex symbol types are sometimes used (e.g., for lexicalized grammars). Since symbols are node values, they must be immutable and hashable. Two Nonterminals are considered equal if their symbols are equal.


See Also:
Grammar, Production
Instance Methods [hide private]
 
__init__(self, symbol)
Construct a new non-terminal from the given symbol.
source code
(any)
symbol(self)
Returns: The node value corresponding to this Nonterminal.
source code
boolean
__eq__(self, other)
Returns: True if this non-terminal is equal to other.
source code
boolean
__ne__(self, other)
Returns: True if this non-terminal is not equal to other.
source code
 
__cmp__(self, other) source code
 
__hash__(self)
hash(x)
source code
string
__repr__(self)
Returns: A string representation for this Nonterminal.
source code
string
__str__(self)
Returns: A string representation for this Nonterminal.
source code
Nonterminal
__div__(self, rhs)
Returns: A new nonterminal whose symbol is A/B, where A is the symbol for this nonterminal, and B is the symbol for rhs.
source code

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

Instance Variables [hide private]
(any) _symbol
The node value corresponding to this Nonterminal.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, symbol)
(Constructor)

source code 

Construct a new non-terminal from the given symbol.

Parameters:
  • symbol ((any)) - The node value corresponding to this Nonterminal. This value must be immutable and hashable.
Overrides: object.__init__

symbol(self)

source code 
Returns: (any)
The node value corresponding to this Nonterminal.

__eq__(self, other)
(Equality operator)

source code 
Returns: boolean
True if this non-terminal is equal to other. In particular, return true iff other is a Nonterminal and this non-terminal's symbol is equal to other's symbol.

__ne__(self, other)

source code 
Returns: boolean
True if this non-terminal is not equal to other. In particular, return true iff other is not a Nonterminal or this non-terminal's symbol is not equal to other's symbol.

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: object.__hash__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Returns: string
A string representation for this Nonterminal. The string representation for a Nonterminal whose symbol is s is <s>.
Overrides: object.__repr__

__str__(self)
(Informal representation operator)

source code 

str(x)

Returns: string
A string representation for this Nonterminal. The string representation for a Nonterminal whose symbol is s is s.
Overrides: object.__str__

__div__(self, rhs)

source code 
Parameters:
  • rhs (Nonterminal) - The nonterminal used to form the right hand side of the new nonterminal.
Returns: Nonterminal
A new nonterminal whose symbol is A/B, where A is the symbol for this nonterminal, and B is the symbol for rhs.

Instance Variable Details [hide private]

_symbol

The node value corresponding to this Nonterminal. This value must be immutable and hashable.
Type:
(any)