Lexicon#
- class discopy.grammar.abstract.Lexicon(ob_map=None, ar_map=None, dom=None, cod=None, colour_map=None)[source]#
Bases:
FunctorA 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:
Lexicons compose:
first >> secondsends a constantctosecond(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 ...