From 43bbf3f5a38568961fb0f3321aa2a8c3e3bf0a4d Mon Sep 17 00:00:00 2001 From: aarneranta Date: Wed, 12 May 2021 12:51:24 +0200 Subject: [PATCH] May 5 files to myproject --- lab2/grammar/myproject/MicroLangEng.gf | 56 ++++++++-- lab2/grammar/myproject/MicroResEng.gf | 138 +++++++++++++++++++++---- lab2/grammar/myproject/MicroResSwe.gf | 33 ++++-- 3 files changed, 188 insertions(+), 39 deletions(-) diff --git a/lab2/grammar/myproject/MicroLangEng.gf b/lab2/grammar/myproject/MicroLangEng.gf index ac747de..3473244 100644 --- a/lab2/grammar/myproject/MicroLangEng.gf +++ b/lab2/grammar/myproject/MicroLangEng.gf @@ -2,14 +2,56 @@ concrete MicroLangEng of MicroLang = open MicroResEng in { -lincat N = MicroResEng.N ; +lincat + Utt = {s : Str} ; + S = {s : Str} ; -lin baby_N = mkN "baby" ; -lin dog_N = mkN "dog" ; -lin man_N = mkN "man" "men" ; -lin car_N = mkN "car" ; -lin city_N = mkN "city" ; -lin boy_N = mkN "boy" ; + VP = {verb : MicroResEng.V ; compl : Str} ; + + + CN = MicroResEng.N ; + AP = MicroResEng.A ; + + NP = MicroResEng.Pron ; + Pron = MicroResEng.Pron ; + + N = MicroResEng.N ; + A = MicroResEng.A ; + V = MicroResEng.V ; + V2 = MicroResEng.V2 ; + +lin + + PredVPS np vp = {s = np.s ! Nom ++ selectVerb vp.verb np.n ++ vp.compl} ; + + UseV v = {verb = v ; compl = []} ; + ComplV2 v np = {verb = v ; compl = np.s ! Acc} ; + + AdjCN ap cn = {s = \\n => ap.s ++ cn.s ! n} ; + + + UsePron p = p ; + + UseN n = n ; + PositA a = a ; + + + he_Pron = mkPron "he" "him" Sg ; + she_Pron = mkPron "she" "her" Sg ; + they_Pron = mkPron "they" "them" Pl ; + + + book_N = {s = table {Sg => "book" ; Pl => "books"}} ; + grammar_N = mkN "grammar" ; + woman_N = mkN "woman" "women" ; + child_N = mkN "child" "children" ; + boy_N = mkN "boy" ; + + big_A = mkA "big" ; + good_A = mkA "good" ; + live_V = mkV "live" ; + love_V2 = mkV2 "love" ; + } \ No newline at end of file diff --git a/lab2/grammar/myproject/MicroResEng.gf b/lab2/grammar/myproject/MicroResEng.gf index 8949a32..166785a 100644 --- a/lab2/grammar/myproject/MicroResEng.gf +++ b/lab2/grammar/myproject/MicroResEng.gf @@ -1,30 +1,124 @@ -resource MicroResEng = { +resource MicroResEng = open Prelude in { -param Number = Sg | Pl ; +param + Number = Sg | Pl ; + Case = Nom | Acc ; + + + Agreement = Agr Number ; ---s Person to be added + + -- all forms of normal Eng verbs, although not yet used in MiniGrammar + VForm = Inf | PresSg3 | Past | PastPart | PresPart ; oper - N = {s : Number => Str} ; + N : Type = {s : Number => Str} ; - worstN : Str -> Str -> N - = \x,y -> {s = table {Sg => x ; Pl => y}} ; - - regN : Str -> N - = \x -> worstN x (x + "s") ; - - smartN : Str -> N - = \x -> case x of - { - b + ("ay"|"oy"|"uy") => regN x ; - bab + "y" => worstN x (bab + "ies") ; - _ => regN x - } ; - - mkN = overload { - mkN : (dog : Str) -> N - = smartN ; - mkN : (man,men : Str) -> N - = worstN + worstN : Str -> Str -> N = \sg,pl -> { + s = table {Sg => sg ; Pl => pl} } ; + regN : Str -> N = \sg -> worstN sg (sg + "s") ; + + -- smart paradigm + smartN : Str -> N = \sg -> case sg of { + _ + ("ay"|"ey"|"oy"|"uy") => regN sg ; + x + "y" => worstN sg (x + "ies") ; + _ + ("ch"|"sh"|"s"|"o") => worstN sg (sg + "es") ; + _ => regN sg + } ; + + A : Type = {s : Str} ; + + V : Type = {s : VForm => Str} ; + + mkVerb : (inf,pres,past,pastpart,prespart : Str) -> V + = \inf,pres,past,pastpart,prespart -> { + s = table { + Inf => inf ; + PresSg3 => pres ; + Past => past ; + PastPart => pastpart ; + PresPart => prespart + } + } ; + + regV : (inf : Str) -> V = \inf -> + mkVerb inf (inf + "s") (inf + "ed") (inf + "ed") (inf + "ing") ; + + -- regular verbs with predictable variations + smartV : Str -> V = \inf -> case inf of { + pl + ("a"|"e"|"i"|"o"|"u") + "y" => regV inf ; + cr + "y" => mkVerb inf (cr + "ies") (cr + "ied") (cr + "ied") (inf + "ing") ; + lov + "e" => mkVerb inf (inf + "s") (lov + "ed") (lov + "ed") (lov + "ing") ; + kis + ("s"|"sh"|"x"|"o") => mkVerb inf (inf + "es") (inf + "ed") (inf + "ed") (inf + "ing") ; + _ => regV inf + } ; + + -- normal irregular verbs e.g. drink,drank,drunk + irregV : (inf,past,pastpart : Str) -> V = + \inf,past,pastpart -> + let verb = smartV inf + in mkVerb inf (verb.s ! PresSg3) past pastpart (verb.s ! PresPart) ; + + -- two-place verb with "case" as preposition; for transitive verbs, c=[] + V2 : Type = V ** {c : Str} ; + + be_V : V = mkVerb "are" "is" "was" "been" "being" ; ---s to be generalized + + +---s a very simplified verb agreement function for Micro + agr2vform : Agreement -> VForm = \a -> case a of { + Agr Sg => PresSg3 ; + Agr Pl => Inf + } ; + + Pron : Type = {s : Case => Str ; n : Number} ; + + mkPron : Str -> Str -> Number -> Pron = \nom,acc,n -> {s = table {Nom => nom ; Acc => acc} ; n = n} ; + + selectVerb : V -> Number -> Str = \v,n -> case n of { + Sg => v.s ! PresSg3 ; + Pl => v.s ! Inf + } ; + +--------------------------- +-- Paradigms part --------- +--------------------------- + +oper + mkN = overload { + mkN : Str -> N -- predictable noun, e.g. car-cars, boy-boys, fly-flies, bush-bushes + = \n -> lin N (smartN n) ; + mkN : Str -> Str -> N -- irregular noun, e.g. man-men + = \sg,pl -> lin N (worstN sg pl) ; + } ; + + mkA : Str -> A + = \s -> {s = s} ; + + mkV = overload { + mkV : (inf : Str) -> V -- predictable verb, e.g. play-plays, cry-cries, wash-washes + = \s -> lin V (smartV s) ; + mkV : (inf,pres,part : Str) -> V -- irregular verb, e.g. drink-drank-drunk + = \inf,pres,part -> lin V (irregV inf pres part) ; + } ; + + mkV2 = overload { + mkV2 : Str -> V2 -- predictable verb with direct object, e.g. "wash" + = \s -> lin V2 (smartV s ** {c = []}) ; + mkV2 : Str -> Str -> V2 -- predictable verb with preposition, e.g. "wait - for" + = \s,p -> lin V2 (smartV s ** {c = p}) ; + mkV2 : V -> V2 -- any verb with direct object, e.g. "drink" + = \v -> lin V2 (v ** {c = []}) ; + mkV2 : V -> Str -> V2 -- any verb with preposition + = \v,p -> lin V2 (v ** {c = p}) ; + } ; + +-- mkAdv : Str -> Adv + -- = \s -> lin Adv {s = s} ; + +-- mkPrep : Str -> Prep + -- = \s -> lin Prep {s = s} ; + } diff --git a/lab2/grammar/myproject/MicroResSwe.gf b/lab2/grammar/myproject/MicroResSwe.gf index 209fec1..07d2d11 100644 --- a/lab2/grammar/myproject/MicroResSwe.gf +++ b/lab2/grammar/myproject/MicroResSwe.gf @@ -1,23 +1,36 @@ -resource MicroResSwe = { +resource MicroResSwe = open Prelude in { param Number = Sg | Pl ; Species = Indef | Def ; Gender = Utr | Neutr ; - + oper - N = {s : Number => Species => Str ; g : Gender} ; + N : Type = {s : Number => Species => Str ; g : Gender} ; worstN : Str -> Str -> Str -> Str -> Gender -> N - = \man,mannen,män,männen,gen -> { + = \man,mannen,män,männen,g -> { s = table { - Sg => table {Indef => man ; Def => mannen} ; - Pl => table {Indef => män ; Def => männen} - } ; - g = gen + Sg => table {Indef => man ; Def => mannen} ; + Pl => table {Indef => män ; Def => männen} + } ; + g = g } ; +-- https://en.wikipedia.org/wiki/Swedish_grammar + + decl1 : Str -> N + = \apa -> + let ap = init apa in + worstN apa (apa + "n") (ap + "or") (ap + "orna") Utr ; decl2 : Str -> N - = \bil -> worstN bil (bil + "en") (bil + "ar") (bil + "arna") Utr ; + = \bil -> case bil of { + pojk + "e" => worstN bil (bil + "en") (pojk + "ar") (pojk + "arna") Utr ; + _ => worstN bil (bil + "en") (bil + "ar") (bil + "arna") Utr + } ; -} + + + + +} \ No newline at end of file