Lexicon

Lexicon#

class discopy.grammar.abstract.Lexicon(ob_map=None, ar_map=None, dom=None, cod=None, colour_map=None)[source]#

Bases: Functor

A lexicon is a functor from one vocabulary to another, i.e. between two free closed categories: it sends atomic types to types and constants to terms of the image of their types, section 2.2 of de Groote’s Towards abstract categorial grammars (2001).

Parameters:
  • ob_map (Mapping[Ty, Ty]) – Map from atomic types to types.

  • ar_map (Mapping[Constant, Term]) – Map from constants to terms.

Lexicons compose: first >> second sends a constant c to second(first(c)), with the target vocabulary of the first lexicon serving as the source vocabulary of the second.

Example

>>> x, y, z = map(Ty, "xyz")
>>> first = Lexicon(ob_map={x: y}, ar_map={x("a"): y("b")})
>>> second = Lexicon(ob_map={y: z}, ar_map={y("b"): z("c")})
>>> assert first(x("a")) == y("b") and (first >> second)(x("a")) == z("c")
>>> Lexicon(ob_map={x: y}, ar_map={x("a"): (y >> y)("b")})(x("a"))
Traceback (most recent call last):
    ...
discopy.utils.AxiomError: Expected a term of type y for a, got ...
dom#

alias of Diagram

cod#

alias of Diagram