MyNixOS website logo
Description

DisCoCat implementation.

An educational implementation of the DisCoCat framework.

discokitty

Version

An educational implementation of the DisCoCat framework as described in "Mathematical Foundations for a Compositional Distributional Model of Meaning" (link) by Coecke, Sadrzadeh and Clark.

Sunglasses Kitty by Rikki Lorie, licensed under Creative Commons

Usage example

Please note that this library is work in progress and it is possible that substantial changes will be made. In the following example we work in the category of relations declaring the meaning and grammar type of some words and then we evaluate an example sentence.

module Discokitty.Examples.AliceAndBob where

import           Discokitty
import           Discokitty.Models.Diagrams
import           Discokitty.Models.Rel

-- We first declare an universe with all the possible basis words,
-- both nouns and sentences.  The rest of the types are parameterized
-- by this universe.
data Universe = Alice | Bob | IsTrue | IsFalse deriving (Eq, Ord, Show)

-- We choose to use the category of relations for this example, and we
-- declare a term to be a word in the category of relations for our
-- given universe.
type Term = Words (Rel Universe)

-- We give meaning to some terms.  Relations are described as subsets using
-- "relation", and the Lambek grammatical type must be written at the end.
alice :: Term
alice = Words
  { meaning = relation [ [ Alice ] ]
  , grammar = [N]
  , text = "Alice"
  }

bob :: Term
bob = Words
  { meaning = relation [ [ Bob ] ]
  , grammar = [N]
  , text = "Bob"
  }

loves :: Term
loves = Words
  { meaning = relation [ [ Alice , IsTrue , Bob ] ]
  , grammar = [ L N , S , R N ]
  , text = "loves"
  }


-- In our example sentence, we evaluate "Alice loves Bob".
-- This produces the following output:
--   > [[IsTrue]] of grammar type [S]
example :: [Term]
example = sentence [alice , loves , bob] @@@ [S]


-- We can also generate Tikz diagrams.
exampleDiagram :: String
exampleDiagram = tikzDiagrams [alice , loves , bob]

The generated tikz diagram looks as follows.

Metadata

Version

0.1.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows