grammar.pregroup#

Implements pregroup grammars and distributional compositional models.

>>> from discopy.tensor import Functor
>>> from discopy.rigid import Ty
>>> s, n = Ty('s'), Ty('n')
>>> Alice, Bob = Word('Alice', n), Word('Bob', n)
>>> loves = Word('loves', n.r @ s @ n.l)
>>> grammar = Cup(n, n.r) @ Id(s) @ Cup(n.l, n)
>>> sentence = grammar << Alice @ loves @ Bob
>>> ob = {s: 1, n: 2}
>>> ar = {Alice: [1, 0], loves: [0, 1, 1, 0], Bob: [0, 1]}
>>> F = Functor(ob, ar)
>>> assert F(sentence) == True
>>> draw(sentence, figsize=(4, 2),\
...      path='docs/_static/imgs/grammar/pregroup-example.png')
../_images/pregroup-example.png

discopy.grammar.pregroup.Word(name, cod[, ...])

Word with a discopy.rigid.Ty as codomain.

discopy.grammar.pregroup.eager_parse(*words)

Tries to parse a given list of words in an eager fashion.

discopy.grammar.pregroup.brute_force(*vocab)

Given a vocabulary, search for grammatical sentences.

discopy.grammar.pregroup.draw(diagram, **params)

Draws a pregroup diagram, i.e. of shape :code:`word @ .