nltk.parse.generate module

nltk.parse.generate.demo(N=23)[source]
nltk.parse.generate.generate(grammar, start=None, depth=None, n=None)[source]

Generates an iterator of all sentences from a CFG.

Parameters
  • grammar – The Grammar used to generate sentences.

  • start – The Nonterminal from which to start generate sentences.

  • depth – The maximal depth of the generated tree.

  • n – The maximum number of sentences to return.

Returns

An iterator of lists of terminal tokens.