CFG#

class discopy.grammar.cfg.CFG(*productions)[source]#

Bases: object

Context-free grammar.

property productions#

Production rules, i.e. boxes with discopy.monoidal.Ty as dom and cod.

generate(start, max_sentences, max_depth, max_iter=100, remove_duplicates=False, not_twice=None, seed=None)[source]#

Generate sentences from a context-free grammar. Assumes the only terminal symbol is Ty().

Parameters:
  • start (type) – root of the generated trees.

  • max_sentences (int) – maximum number of sentences to generate.

  • max_depth (int) – maximum depth of the trees.

  • max_iter (int) – maximum number of iterations, set to 100 by default.

  • remove_duplicates (bool) – if set to True only distinct syntax trees will be generated.

  • not_twice (list) – list of productions that you don’t want appearing twice in a sentence, set to the empty list by default