mirror of
https://github.com/GrammaticalFramework/comp-syntax-gu-mlt.git
synced 2026-05-04 15:22:50 -06:00
lecture 4 code
This commit is contained in:
105
lectures/lecture04/MicroLangMyeng.gf
Normal file
105
lectures/lecture04/MicroLangMyeng.gf
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
--# -path=.:../abstract
|
||||||
|
|
||||||
|
concrete MicroLangMyeng of MicroLang = open MicroResMyeng, Prelude in {
|
||||||
|
|
||||||
|
lincat
|
||||||
|
V = Verb ;
|
||||||
|
V2 = Verb2 ;
|
||||||
|
A = Adjective ;
|
||||||
|
N = Noun ;
|
||||||
|
Adv = Adverb ;
|
||||||
|
|
||||||
|
-----------------------------------------------------
|
||||||
|
---------------- Lexicon part -----------------------
|
||||||
|
-----------------------------------------------------
|
||||||
|
|
||||||
|
lin already_Adv = mkAdv "already" ;
|
||||||
|
lin animal_N = mkN "animal" ;
|
||||||
|
lin apple_N = mkN "apple" ;
|
||||||
|
lin baby_N = mkN "baby" ;
|
||||||
|
lin bad_A = mkA "bad" ;
|
||||||
|
lin beer_N = mkN "beer" ;
|
||||||
|
lin big_A = mkA "big" ;
|
||||||
|
lin bike_N = mkN "bike" ;
|
||||||
|
lin bird_N = mkN "bird" ;
|
||||||
|
lin black_A = mkA "black" ;
|
||||||
|
lin blood_N = mkN "blood" ;
|
||||||
|
lin blue_A = mkA "blue" ;
|
||||||
|
lin boat_N = mkN "boat" ;
|
||||||
|
lin book_N = mkN "book" ;
|
||||||
|
lin boy_N = mkN "boy" ;
|
||||||
|
lin bread_N = mkN "bread" ;
|
||||||
|
lin break_V2 = mkV2 (mkV "break" "broke" "broken") ;
|
||||||
|
lin buy_V2 = mkV2 (mkV "buy" "bought" "bought") ;
|
||||||
|
lin car_N = mkN "car" ;
|
||||||
|
lin cat_N = mkN "cat" ;
|
||||||
|
lin child_N = mkN "child" "children" ;
|
||||||
|
lin city_N = mkN "city" ;
|
||||||
|
lin clean_A = mkA "clean" ;
|
||||||
|
lin clever_A = mkA "clever" ;
|
||||||
|
lin cloud_N = mkN "cloud" ;
|
||||||
|
lin cold_A = mkA "cold" ;
|
||||||
|
lin come_V = mkV "come" "came" "come" ;
|
||||||
|
lin computer_N = mkN "computer" ;
|
||||||
|
lin cow_N = mkN "cow" ;
|
||||||
|
lin dirty_A = mkA "dirty" ;
|
||||||
|
lin dog_N = mkN "dog" ;
|
||||||
|
lin drink_V2 = mkV2 (mkV "drink" "drank" "drunk") ;
|
||||||
|
lin eat_V2 = mkV2 (mkV "eat" "ate" "eaten") ;
|
||||||
|
lin find_V2 = mkV2 (mkV "find" "found" "found") ;
|
||||||
|
lin fire_N = mkN "fire" ;
|
||||||
|
lin fish_N = mkN "fish" "fish" ;
|
||||||
|
lin flower_N = mkN "flower" ;
|
||||||
|
lin friend_N = mkN "friend" ;
|
||||||
|
lin girl_N = mkN "girl" ;
|
||||||
|
lin good_A = mkA "good" ;
|
||||||
|
lin go_V = mkV "go" "goes" "went" "gone" "going" ;
|
||||||
|
lin grammar_N = mkN "grammar" ;
|
||||||
|
lin green_A = mkA "green" ;
|
||||||
|
lin heavy_A = mkA "heavy" ;
|
||||||
|
lin horse_N = mkN "horse" ;
|
||||||
|
lin hot_A = mkA "hot" ;
|
||||||
|
lin house_N = mkN "house" ;
|
||||||
|
-- lin john_PN = mkPN "John" ;
|
||||||
|
lin jump_V = mkV "jump" ;
|
||||||
|
lin kill_V2 = mkV2 "kill" ;
|
||||||
|
-- lin know_VS = mkVS (mkV "know" "knew" "known") ;
|
||||||
|
lin language_N = mkN "language" ;
|
||||||
|
lin live_V = mkV "live" ;
|
||||||
|
lin love_V2 = mkV2 (mkV "love") ;
|
||||||
|
lin man_N = mkN "man" "men" ;
|
||||||
|
lin milk_N = mkN "milk" ;
|
||||||
|
lin music_N = mkN "music" ;
|
||||||
|
lin new_A = mkA "new" ;
|
||||||
|
lin now_Adv = mkAdv "now" ;
|
||||||
|
lin old_A = mkA "old" ;
|
||||||
|
-- lin paris_PN = mkPN "Paris" ;
|
||||||
|
lin play_V = mkV "play" ;
|
||||||
|
lin read_V2 = mkV2 (mkV "read" "read" "read") ;
|
||||||
|
lin ready_A = mkA "ready" ;
|
||||||
|
lin red_A = mkA "red" ;
|
||||||
|
lin river_N = mkN "river" ;
|
||||||
|
lin run_V = mkV "run" "runs" "ran" "run" "running" ;
|
||||||
|
lin sea_N = mkN "sea" ;
|
||||||
|
lin see_V2 = mkV2 (mkV "see" "saw" "seen") ;
|
||||||
|
lin ship_N = mkN "ship" ;
|
||||||
|
lin sleep_V = mkV "sleep" "slept" "slept" ;
|
||||||
|
lin small_A = mkA "small" ;
|
||||||
|
lin star_N = mkN "star" ;
|
||||||
|
lin swim_V = mkV "swim" "swims" "swam" "swum" "swimming" ;
|
||||||
|
lin teach_V2 = mkV2 (mkV "teach" "taught" "taught") ;
|
||||||
|
lin train_N = mkN "train" ;
|
||||||
|
lin travel_V = mkV "travel" ;
|
||||||
|
lin tree_N = mkN "tree" ;
|
||||||
|
lin understand_V2 = mkV2 (mkV "understand" "understood" "understood") ;
|
||||||
|
lin wait_V2 = mkV2 "wait" "for" ;
|
||||||
|
lin walk_V = mkV "walk" ;
|
||||||
|
lin warm_A = mkA "warm" ;
|
||||||
|
lin water_N = mkN "water" ;
|
||||||
|
lin white_A = mkA "white" ;
|
||||||
|
lin wine_N = mkN "wine" ;
|
||||||
|
lin woman_N = mkN "woman" "women" ;
|
||||||
|
lin yellow_A = mkA "yellow" ;
|
||||||
|
lin young_A = mkA "young" ;
|
||||||
|
|
||||||
|
}
|
||||||
115
lectures/lecture04/MicroResMyeng.gf
Normal file
115
lectures/lecture04/MicroResMyeng.gf
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
resource MicroResMyeng = {
|
||||||
|
|
||||||
|
------------------------------
|
||||||
|
-- API: overloaded paradigms
|
||||||
|
|
||||||
|
oper
|
||||||
|
mkN = overload {
|
||||||
|
mkN : (baby : Str) -> Noun
|
||||||
|
= \baby -> smartNoun baby ;
|
||||||
|
mkN : (man, men : Str) -> Noun
|
||||||
|
= \man, men -> mkNoun man men ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
mkA : Str -> Adjective
|
||||||
|
= \adj -> {s = adj} ;
|
||||||
|
|
||||||
|
mkAdv : Str -> Adverb
|
||||||
|
= \adv -> {s = adv} ;
|
||||||
|
|
||||||
|
mkV = overload {
|
||||||
|
mkV : (try : Str) -> Verb
|
||||||
|
= \try -> smartVerb try ;
|
||||||
|
mkV : (go, went, gone : Str) -> Verb
|
||||||
|
= \go, went, gone -> irregVerb go went gone ;
|
||||||
|
mkV : (sing, sings, sang, sung, singing : Str) -> Verb
|
||||||
|
= \sing, sings, sang, sung, singing ->
|
||||||
|
mkVerb sing sings sang sung singing ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
mkV2 = overload {
|
||||||
|
mkV2 : (kill : Str) -> Verb2
|
||||||
|
= \kill -> mkV kill ** {prep = ""} ;
|
||||||
|
mkV2 : (wait, for : Str) -> Verb2
|
||||||
|
= \wait, for -> mkV wait ** {prep = for} ;
|
||||||
|
mkV2 : Verb -> Verb2
|
||||||
|
= \verb -> verb ** {prep = ""} ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------------------------------
|
||||||
|
param
|
||||||
|
Number = Sg | Pl ;
|
||||||
|
|
||||||
|
VerbForm = Inf | Pres3Sg | Past | PastPart | PresPart ;
|
||||||
|
|
||||||
|
oper
|
||||||
|
Noun : Type = {s : Number => Str} ;
|
||||||
|
|
||||||
|
-- constructor
|
||||||
|
mkNoun : (dog, dogs : Str) -> Noun
|
||||||
|
= \dog, dogs -> {
|
||||||
|
s = table {Sg => dog ; Pl => dogs}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
regNoun : (dog : Str) -> Noun
|
||||||
|
= \dog -> mkNoun dog (dog + "s") ;
|
||||||
|
|
||||||
|
smartNoun : (noun : Str) -> Noun
|
||||||
|
= \noun -> case noun of {
|
||||||
|
b + ("a" | "e" | "o" | "u") + "y" => regNoun noun ;
|
||||||
|
bab + "y" => mkNoun noun (bab + "ies") ;
|
||||||
|
_ => regNoun noun
|
||||||
|
} ;
|
||||||
|
|
||||||
|
Adjective : Type = {s : Str} ;
|
||||||
|
|
||||||
|
Adverb : Type = {s : Str} ;
|
||||||
|
|
||||||
|
Verb : Type = {s : VerbForm => Str} ;
|
||||||
|
|
||||||
|
-- constructor; worst case paradigm
|
||||||
|
mkVerb : (sing, sings, sang, sung, singing : Str) -> Verb
|
||||||
|
= \sing, sings, sang, sung, singing -> {
|
||||||
|
s = table {
|
||||||
|
Inf => sing ;
|
||||||
|
Pres3Sg => sings ;
|
||||||
|
Past => sang ;
|
||||||
|
PastPart => sung ;
|
||||||
|
PresPart => singing
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
regVerb : (walk : Str) -> Verb
|
||||||
|
= \walk ->
|
||||||
|
mkVerb walk (walk + "s") (walk + "ed")
|
||||||
|
(walk + "ed") (walk + "ing") ;
|
||||||
|
|
||||||
|
smartVerb : (verb : Str) -> Verb
|
||||||
|
= \verb -> case verb of {
|
||||||
|
b + ("a" | "e" | "o" | "u") + "y" => regVerb verb ;
|
||||||
|
cr + "y" => mkVerb verb (cr + "ies")
|
||||||
|
(cr + "ied") (cr + "ied") (cr + "ying") ;
|
||||||
|
refer + "ee" => let refereed = refer + "eed" in
|
||||||
|
mkVerb verb (verb + "s") refereed refereed (verb + "ing") ;
|
||||||
|
us + "e" => let used = us + "ed" in
|
||||||
|
mkVerb verb (verb + "s") used used (us + "ing") ;
|
||||||
|
wa + ("ch" | "sh" | "s" | "z" | "x") =>
|
||||||
|
mkVerb verb (verb + "es") (verb + "ed") (verb + "ed")
|
||||||
|
(verb + "ing") ;
|
||||||
|
_ => regVerb verb
|
||||||
|
} ;
|
||||||
|
|
||||||
|
irregVerb : (sing, sang, sung : Str) -> Verb
|
||||||
|
= \sing, sang, sung -> {s =
|
||||||
|
table {
|
||||||
|
Past => sang ;
|
||||||
|
PastPart => sung ;
|
||||||
|
x => (smartVerb sing).s ! x
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
Verb2 : Type = {s : VerbForm => Str ; prep : Str} ;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user