From a6f89fefef9ae755875c8b14c4b4c1513727cb16 Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 22 Oct 2007 15:56:11 +0000 Subject: [PATCH] polished the syntax grammar for the book --- examples/tutorial/syntax/Grammar.gf | 28 ++++++--- examples/tutorial/syntax/GrammarEng.gf | 85 ++++++++++++++++++-------- examples/tutorial/syntax/GrammarIta.gf | 37 ++++++++--- 3 files changed, 105 insertions(+), 45 deletions(-) diff --git a/examples/tutorial/syntax/Grammar.gf b/examples/tutorial/syntax/Grammar.gf index 5484321ee..c48e89a21 100644 --- a/examples/tutorial/syntax/Grammar.gf +++ b/examples/tutorial/syntax/Grammar.gf @@ -6,12 +6,15 @@ abstract Grammar = { Phr ; -- any complete sentence e.g. "Is this pizza good?" S ; -- declarative sentence e.g. "this pizza is good" QS ; -- question sentence e.g. "is this pizza good" + Cl ; -- declarative clause e.g. "this pizza is good" + QCl ; -- question clause e.g. "is this pizza good" NP ; -- noun phrase e.g. "this pizza" IP ; -- interrogative phrase e.g "which pizza" CN ; -- common noun phrase e.g. "very good pizza" Det ; -- determiner e.g. "this" IDet ; -- interrog. determiner e.g. "which" AP ; -- adjectival phrase e.g. "very good" + Adv ; -- adverb e.g. "today" AdA ; -- adadjective e.g. "very" VP ; -- verb phrase e.g. "is good" N ; -- noun e.g. "pizza" @@ -20,24 +23,31 @@ abstract Grammar = { V2 ; -- two-place verb e.g. "eat" Pol ; -- polarity (pos or neg) Conj ; -- conjunction e.g. "and" + Subj ; -- conjunction e.g. "because" fun PhrS : S -> Phr ; PhrQS : QS -> Phr ; - PredVP : Pol -> NP -> VP -> S ; - QuestVP : Pol -> NP -> VP -> QS ; + UseCl : Pol -> Cl -> S ; + UseQCl : Pol -> QCl -> QS ; - IPPredVP : Pol -> IP -> VP -> QS ; - IPPredV2 : Pol -> IP -> NP -> V2 -> QS ; + QuestCl : Cl -> QCl ; + + SubjS : Subj -> S -> Adv ; + + PredVP : NP -> VP -> Cl ; + + QuestVP : IP -> VP -> QCl ; + QuestV2 : IP -> NP -> V2 -> QCl ; ComplV2 : V2 -> NP -> VP ; ComplAP : AP -> VP ; DetCN : Det -> CN -> NP ; - ModCN : AP -> CN -> CN ; - + ModCN : AP -> CN -> CN ; + AdVP : Adv -> VP -> VP ; AdAP : AdA -> AP -> AP ; IDetCN : IDet -> CN -> IP ; @@ -63,12 +73,12 @@ abstract Grammar = { indef_Det : Det ; plur_Det : Det ; two_Det : Det ; - which_IDet : IDet ; - + today_Adv : Adv ; very_AdA : AdA ; - and_Conj : Conj ; + because_Subj : Subj ; + -- polarities PPos, PNeg : Pol ; diff --git a/examples/tutorial/syntax/GrammarEng.gf b/examples/tutorial/syntax/GrammarEng.gf index d35b33fff..8a4dace8d 100644 --- a/examples/tutorial/syntax/GrammarEng.gf +++ b/examples/tutorial/syntax/GrammarEng.gf @@ -6,12 +6,15 @@ concrete GrammarEng of Grammar = open Prelude, MorphoEng in { Phr = {s : Str} ; S = {s : Str} ; QS = {s : Str} ; + Cl = {s : Order => Bool => Str} ; + QCl = {s : Order => Bool => Str} ; NP = NounPhrase ; IP = NounPhrase ; CN = Noun ; Det = {s : Str ; n : Number} ; IDet = {s : Str ; n : Number} ; AP = {s : Str} ; + Adv = {s : Str} ; AdA = {s : Str} ; VP = VerbPhrase ; N = Noun ; @@ -19,36 +22,59 @@ concrete GrammarEng of Grammar = open Prelude, MorphoEng in { V = Verb ; V2 = Verb2 ; Conj = {s : Str} ; + Subj = {s : Str} ; Pol = {s : Str ; p : Bool} ; lin - PhrS = postfixSS "." ; + PhrS = postfixSS "." ; PhrQS = postfixSS "?" ; - - PredVP = predVP True ; - QuestVP = predVP False ; - IPPredVP = predVP True ; - IPPredV2 p ip np v2 = { - s = let + UseCl pol cl = {s = pol.s ++ cl.s ! Dir ! pol.p} ; + UseQCl pol qcl = {s = pol.s ++ qcl.s ! Inv ! pol.p} ; + + QuestCl cl = cl ; + + SubjS subj s = {s = subj.s ++ s.s} ; + + PredVP = predVP ; + + QuestVP ip vp = let cl = predVP ip vp in {s = \\_ => cl.s ! Dir}; + + QuestV2 ip np v2 = { + s = \\ord,pol => + let vp : VerbPhrase = {s = \\q,b,n => predVerb v2 q b n} ; in - bothWays (ip.s ++ (predVP False p np vp).s) v2.c - } ; - - - ComplV2 v2 np = { - s = \\q,b,n => - let vp = predVerb v2 q b n in - + bothWays (ip.s ++ (predVP np vp).s ! ord ! pol) v2.c } ; - ComplAP ap = {s = \\_,b,n => } ; + ComplV2 v2 np = { + s = \\q,b,n => + let vp = predVerb v2 q b n in { + fin = vp.fin ; + inf = vp.inf ++ v2.c ++ np.s + } + } ; + + ComplAP ap = { + s = \\_,b,n => { + fin = copula b n ; + inf = ap.s + } + } ; DetCN det cn = {s = det.s ++ cn.s ! det.n ; n = det.n} ; ModCN ap cn = {s = \\n => ap.s ++ cn.s ! n} ; + AdVP adv vp = { + s = \\o,b,n => + let vps = vp.s ! o ! b ! n in { + fin = vps.fin ; + inf = vps.inf ++ adv.s + } + } ; + AdAP ada ap = {s = ada.s ++ ap.s} ; IDetCN det cn = {s = det.s ++ cn.s ! det.n ; n = det.n} ; @@ -70,26 +96,30 @@ concrete GrammarEng of Grammar = open Prelude, MorphoEng in { indef_Det = {s = artIndef ; n = Sg} ; plur_Det = {s = [] ; n = Pl} ; two_Det = {s = "two" ; n = Pl} ; - + today_Adv = {s = "today"} ; very_AdA = {s = "very"} ; - which_IDet = {s = "which" ; n = Sg} ; and_Conj = {s = "and"} ; + because_Subj = {s = "because"} ; PPos = {s = [] ; p = True} ; PNeg = {s = [] ; p = False} ; + param + Order = Dir | Inv ; + oper NounPhrase = {s : Str ; n : Number} ; - VerbPhrase = {s : Bool => Bool => Number => Str * Str} ; -- decl, pol + VerbPhrase = {s : Order => Bool => Number => {fin,inf : Str}} ; - predVP : Bool -> {s : Str ; p : Bool} -> NounPhrase -> VerbPhrase -> SS = - \q,p,np,vp -> { - s = let vps = vp.s ! q ! p.p ! np.n + predVP : NounPhrase -> VerbPhrase -> {s : Order => Bool => Str} = + \np,vp -> { + s = \\q,p => + let vps = vp.s ! q ! p ! np.n in case q of { - True => p.s ++ np.s ++ vps.p1 ++ vps.p2 ; - False => p.s ++ vps.p1 ++ np.s ++ vps.p2 + Dir => np.s ++ vps.fin ++ vps.inf ; + Inv => vps.fin ++ np.s ++ vps.inf } } ; @@ -101,15 +131,16 @@ concrete GrammarEng of Grammar = open Prelude, MorphoEng in { do : Bool -> Number -> Str = \b,n -> posneg b ((mkV "do").s ! n) ; - predVerb : Verb -> Bool -> Bool -> Number -> Str * Str = \verb,q,b,n -> + predVerb : Verb -> Order -> Bool -> Number -> {fin,inf : Str} = + \verb,q,b,n -> let inf = verb.s ! Pl ; fin = verb.s ! n ; aux = do b n in case of { - => <[],fin> ; - _ => + => {fin = [] ; inf = fin} ; + _ => {fin = aux ; inf = inf} } ; posneg : Bool -> Str -> Str = \b,do -> case b of { diff --git a/examples/tutorial/syntax/GrammarIta.gf b/examples/tutorial/syntax/GrammarIta.gf index e24372e39..04b112ed9 100644 --- a/examples/tutorial/syntax/GrammarIta.gf +++ b/examples/tutorial/syntax/GrammarIta.gf @@ -6,32 +6,45 @@ concrete GrammarIta of Grammar = open Prelude, MorphoIta in { Phr = {s : Str} ; S = {s : Str} ; QS = {s : Str} ; - NP = {s : Str ; g : Gender ; n : Number} ; - IP = {s : Str ; g : Gender ; n : Number} ; + Cl = Clause ; + QCl = Clause ; + NP = NounPhrase ; + IP = NounPhrase ; CN = Noun ; Det = {s : Gender => Str ; n : Number} ; IDet = {s : Gender => Str ; n : Number} ; AP = {s : Gender => Number => Str} ; AdA = {s : Str} ; - VP = {s : Bool => Gender => Number => Str} ; + VP = VerbPhrase ; N = Noun ; A = Adjective ; V = Verb ; V2 = Verb2 ; Conj = {s : Str} ; + Subj = {s : Str} ; Pol = {s : Str ; p : Bool} ; - + oper + Clause : Type = {s : Bool => Str} ; + NounPhrase : Type = {s : Str ; g : Gender ; n : Number} ; + VerbPhrase : Type = {s : Bool => Gender => Number => Str} ; lin PhrS = postfixSS "." ; PhrQS = postfixSS "?" ; - PredVP p np vp = {s = np.s ++ p.s ++ vp.s ! p.p ! np.g ! np.n} ; - QuestVP p np vp = {s = np.s ++ p.s ++ vp.s ! p.p ! np.g ! np.n} ; - IPPredVP p np vp = {s = np.s ++ p.s ++ vp.s ! p.p ! np.g ! np.n} ; + UseCl pol cl = {s = pol.s ++ cl.s ! pol.p} ; + UseQCl pol qcl = {s = pol.s ++ qcl.s ! pol.p} ; - IPPredV2 p ip np v2 = - {s = v2.c ++ ip.s ++ p.s ++ posneg p.p ++ v2.s ! np.n ++ np.s} ; + QuestCl cl = cl ; + + SubjS subj s = {s = subj.s ++ s.s} ; + + PredVP = predVP ; + + QuestVP = predVP ; + + QuestV2 ip np v2 = + {s = \\b => v2.c ++ ip.s ++ posneg b ++ v2.s ! np.n ++ np.s} ; ComplV2 v2 np = {s = \\b,_,n => posneg b ++ v2.s ! n ++ v2.c ++ np.s} ; ComplAP ap = {s = \\b,g,n => posneg b ++ copula n ++ ap.s ! g ! n} ; @@ -40,6 +53,7 @@ concrete GrammarIta of Grammar = open Prelude, MorphoIta in { ModCN ap cn = {s = \\n => cn.s ! n ++ ap.s ! cn.g ! n ; g = cn.g} ; + AdVP adv vp = {s = \\p,n,g => vp.s ! p ! n ! g ++ adv.s} ; AdAP ada ap = {s = \\n,g => ada.s ++ ap.s ! n ! g} ; IDetCN det cn = {s = det.s ! cn.g ++ cn.s ! det.n ; g = cn.g ; n = det.n} ; @@ -61,14 +75,19 @@ concrete GrammarIta of Grammar = open Prelude, MorphoIta in { indef_Det = {s = artIndef ; n = Sg} ; plur_Det = {s = \\_ => [] ; n = Pl} ; two_Det = {s = \\_ => "due" ; n = Pl} ; + today_Adv = {s = "oggi"} ; very_AdA = {s = "molto"} ; which_IDet = {s = \\_ => "quale" ; n = Sg} ; and_Conj = {s = "e"} ; + because_Subj = {s = "perché"} ; PPos = {s = [] ; p = True} ; PNeg = {s = [] ; p = False} ; oper + predVP : NounPhrase -> VerbPhrase -> Clause = \np,vp -> + {s = \\b => np.s ++ vp.s ! b ! np.g ! np.n} ; + copula : Number -> Str = \n -> case n of { Sg => "è" ; Pl => "sono"