std.grammar.ccg.semantics¶
Combinatory categorial grammar with meanings: the combinators of std.grammar.ccg over items that carry a meaning.
A chart item span(I, J, X, M) says that the words from I up to J derive
the category X with the meaning M. Categories are std.grammar.ccg's,
result first. Meanings are lambda terms with constants: application
builds App(F, A). A grammar extending Binding may abstract in a
lexical meaning or a rule as Lam(x, App(bark, x)). A type-raising
rule builds Lam(f, App(f, M)) itself. Composition of degree n builds the
combinator B^n applied to the two meanings, λz1 ... zn. F (G z1 ... zn),
as the rule Lam(z ... n, App(F, G |App z ... n)): the name sequence
binds the n arguments the spine applies G to, harmonic and crossed
composition alike. meaning gives a meaning its term in
std.syntax.lambda, where Lambda.Term.normalize computes its normal
form:
App(F, A)isF A, andLam(x, B)and a bare boundxare an abstraction and its variable;- an atom
cis the constantc, of unknown type.
Use Reified to quote application-only meanings and ReifiedBinding
to quote meanings with binders. Composition already includes Binding.
A grammar with its own explicit variable constructor may quote it as
Variable, which meaning reads as the bound variable it contains.
The signatures mirror std.grammar.ccg's, and a grammar over them derives exactly the items the same grammar derives over std.grammar.ccg once their meanings are forgotten, with the same number of derivations: each rule here is a rule there with a meaning added that its premises determine.
The examples on this page run in this module, which opens std.grammar.ccg.semantics with the imports and opens the module itself makes:
import std.grammar.ccg.semantics
open std.grammar.ccg.semantics
import std.data as D
import std.syntax.lambda as L
import std.grammar.ccg as C
The rules of its deduction signatures are pinned by the specification module, which declares grammars over them and tests the sentences each derives.
Imports: std.data, std.syntax.lambda, std.grammar.ccg
Application (deduction signature)¶
deduction signature Application
Forward and backward application, whose meaning applies the functor's meaning to the argument's.
Binding (deduction signature)¶
deduction signature Binding
Abstraction and variables in meanings, for grammars with binders.
Composition (deduction signature)¶
deduction signature Composition
Harmonic and crossed composition together.
CrossedComposition (deduction signature)¶
deduction signature CrossedComposition
Crossed composition of degree one to three, whose meaning composes.
HarmonicComposition (deduction signature)¶
deduction signature HarmonicComposition
Harmonic composition of degree one to three, whose meaning composes.
Reified (deduction signature)¶
deduction signature Reified deriving (Quote[Sign via semantic_quote])
Quote chart items with application-only meanings as Sign values. The
extending deduction gives a clause for each atom it adds.
ReifiedBinding (deduction signature)¶
deduction signature ReifiedBinding deriving (Quote[Sign via binding_quote])
Quote chart items with abstractions and their variables as Sign values.
Semantic (deduction signature)¶
deduction signature Semantic
The sentence category, slashes, chart items, and application of meanings.
Sign (family)¶
family Sign : Type deriving (Eq, Show)
Constructors:
Abstract:constructor Abstract : Sign * Sign -> SignApply:constructor Apply : Sign * Sign -> SignAtom:constructor Atom : String -> SignBound:constructor Bound : Int -> SignOver:constructor Over : Sign * Sign -> SignSpanned:constructor Spanned : Sign * Sign -> SignUnder:constructor Under : Sign * Sign -> SignVariable:constructor Variable : Sign -> Sign
A chart item written out: a category or a meaning by its parts, and an item as the category it spans and its meaning.
Example: an item.
expect sign_category(s=Spanned(Over(Atom("S"), Atom("NP")), Atom("sees"))) == D.Some(C.Over(C.Atom("S"), C.Atom("NP")))
atom (computation)¶
meta define atom(constructor : String, label : String) : MorphClause !{}
The clause quoting the item constructor constructor as Atom(label).
atoms (computation)¶
meta define atoms(owner : String, labels : Seq[String]) : Seq[MorphClause] !{}
The clauses quoting each atom label that owner declares as
Atom(label).
meaning (computation)¶
define meaning(s : Sign) : D.Option[L.Lambda.Term] !{}
The lambda term of a meaning: its applications, its abstractions with
their variables, each Bound(k) the variable of the
k-th abstraction out (a de Bruijn index), and each atom a constant of
unknown type; an item's meaning is the meaning it spans. None for a
sign that is no meaning: a category, or a variable no abstraction binds.
Example: application.
expect meaning(s=Spanned(Atom("S"), Apply(Atom("sleeps"), Atom("kim")))) == D.Some(L.App(L.Const("sleeps", L.Unknown("sleeps")), L.Const("kim", L.Unknown("kim"))))
expect meaning(s=Under(Atom("S"), Atom("NP"))) == D.None
normal_meaning (computation)¶
define normal_meaning(s : Sign) : D.Option[L.Lambda.Term] !{}
The normal form of a meaning, by Lambda.Term.normalize.
Example: composition and type raising.
expect normal_meaning(s=Apply(Abstract(Bound(0), Apply(Atom("not"), Apply(Atom("sleeps"), Bound(0)))), Atom("kim"))) == D.Some(L.App(L.Const("not", L.Unknown("not")), L.App(L.Const("sleeps", L.Unknown("sleeps")), L.Const("kim", L.Unknown("kim")))))
expect normal_meaning(s=Apply(Abstract(Bound(0), Apply(Variable(Bound(0)), Atom("kim"))), Atom("sleeps"))) == D.Some(L.App(L.Const("sleeps", L.Unknown("sleeps")), L.Const("kim", L.Unknown("kim"))))
Example: degree two composition takes two arguments in order.
expect normal_meaning(s=Apply(Apply(Abstract(Bound(0), Abstract(Bound(0), Apply(Atom("f"), Apply(Apply(Atom("g"), Bound(1)), Bound(0))))), Atom("a")), Atom("b"))) == D.Some(L.App(L.Const("f", L.Unknown("f")), L.App(L.App(L.Const("g", L.Unknown("g")), L.Const("a", L.Unknown("a"))), L.Const("b", L.Unknown("b")))))
Example: an abstraction.
expect normal_meaning(s=Apply(Abstract(Bound(0), Apply(Atom("bark"), Variable(Bound(0)))), Atom("rex"))) == D.Some(L.App(L.Const("bark", L.Unknown("bark")), L.Const("rex", L.Unknown("rex"))))
expect normal_meaning(s=Abstract(Bound(0), Abstract(Bound(0), Variable(Bound(1))))) == D.Some(L.Lam(L.Lam(L.Lambda.Term.var(1))))
expect normal_meaning(s=Variable(Bound(0))) == D.None
sign_category (computation)¶
define sign_category(s : Sign) : D.Option[C.Category] !{}
The category of a sign: an atom or a slash of categories, or the
category an item spans; None for a meaning.
Example: categories.