nltk.grammar.Nonterminal

class nltk.grammar.Nonterminal[source]

Bases: object

A non-terminal symbol for a context free grammar. Nonterminal is a wrapper class for node values; it is used by Production objects 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

CFG, Production

Variables

_symbol – The node value corresponding to this Nonterminal. This value must be immutable and hashable.

__init__(symbol)[source]

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.

symbol()[source]

Return the node value corresponding to this Nonterminal.

Return type

(any)