nltk.grammar.Production

class nltk.grammar.Production[source]

Bases: object

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

CFG

See

DependencyGrammar

See

Nonterminal

Variables
  • _lhs – The left-hand side of the production.

  • _rhs – The right-hand side of the production.

__init__(lhs, rhs)[source]

Construct a new Production.

Parameters
  • lhs (Nonterminal) – The left-hand side of the new Production.

  • rhs (sequence(Nonterminal and terminal)) – The right-hand side of the new Production.

lhs()[source]

Return the left-hand side of this Production.

Return type

Nonterminal

rhs()[source]

Return the right-hand side of this Production.

Return type

sequence(Nonterminal and terminal)

is_nonlexical()[source]

Return True if the right-hand side only contains Nonterminals

Return type

bool

is_lexical()[source]

Return True if the right-hand contain at least one terminal token.

Return type

bool