liboleg-2010.1.9.0: An evolving collection of Oleg Kiselyov's Haskell modules

Lambda.CFG

Description

Context-free grammars, in the tagless-final style

http://okmij.org/ftp/gengo/NASSLLI10/

Synopsis

Documentation

data S Source

Syntactic categories: non-terminals of CFG

Instances

Show (JA S) 
Show (Sem (D (P C)) S) 
Show (Sem (D C) S) 

data NP Source

data VP Source

data TV Source

class Symantics repr whereSource

This class defines the syntax of our fragment (the grammar, essentially). Its instances will show interpretations of the grammar, or semantics

The names r1, r2, etc. are the labels of CFG rules. These names are evocative of Montague

Methods

john :: repr NPSource

mary :: repr NPSource

like :: repr TVSource

own :: repr TVSource

r2 :: repr TV -> repr NP -> repr VPSource

r1 :: repr NP -> repr VP -> repr SSource

Instances

Symantics EN 
Symantics JA 
Lambda lrepr => Symantics (Sem lrepr) 

data EN a Source

show the inferred types, as well as the inferred types for the phrases like

The first sample sentence, or CFG derivation The inferred type is S. So, sen1 is a derivations of a complete sentence.

We now define the first interpretation of a CFG derivations: We interpret the derivation to give the parsed string. That is, we generate a yield of a CFG derivation, in English.

We represent each node in the derivation tree by an English phrase

Constructors

EN 

Fields

unEN :: String
 

Instances

Symantics EN 
Quantifier EN

Sample sentences (or, CFG derivations) We stress that the inferred type of sen2-sen4 is S. So, these are the derivations of complete sentences.

We extend our EN interpreter (interpreter of derivations as English phrases) to deal with QNP.

Pronoun EN 
Quantifier EN

Sample sentences (or, CFG derivations): compare with those in QCFG.hs We stress that the inferred type of sen2-sen4 is S. So, these are the derivations of complete sentences.

We extend our EN interpreter (interpreter of derivations as English phrases) to deal with quantifiers.

Show (EN a) 

type family Tr a :: *Source

Show the English form of sen1

We now define semantics of a phrase represented by a derivation. It is a different interpretation of the phrase and its types.

We first interpret syntactic types (NP, VP, etc) in terms of the types of the language of logic formulas. The type class Lambda defines the language of logic formulas (STT, or higher-order logic) with types Entity, Bool, and the arrows.

data Sem lrepr a Source

Constructors

Sem 

Fields

unSem :: lrepr (Tr a)
 

Instances

Lambda lrepr => Symantics (Sem lrepr) 
Lambda lrepr => Quantifier (Sem lrepr) 
Dynamics lrepr => Pronoun (Sem lrepr) 
Lambda lrepr => Quantifier (Sem lrepr)

We can now see the English sentences that correspond to the derivations sen2-sen4.

We also extend the semantics interpreter: the interpreter of a derivation into a formula of STT, or Lambda-calculus. We reconstruct Montague's ``pronoun trick''

Show (Sem (P C) a) 
Show (Sem C a) 
Show (Sem (D (P C)) S) 
Show (Sem (D C) S)