Creating a mini resource grammar
Inari Listenmaa
University of Gothenburg
2017-08-16, Riga
Recap on earlier lectures
Computational Syntax, spring 2023
GF resource grammar
Inari Listenmaa
Recap on GF syntax
Functions
fun Hello : Noun -> Greeting ;
lin Hello x = "hello" ++ x ;
oper glue : Str -> Str -> Str = \x,y -> x ++ y ;
Categories
cat Noun ;
lincat Noun = Str ;
Recap on GF syntax
Records
lincat Det = {s : Str ; n : Number} ;
lin a_Det = {s = "a" ; n = Sg} ;
a_Det.s ; -- has value “a”
Tables
lincat Noun = Number => Str ;
car_N = table {Sg => "car" ;� Pl => "cars" } ;
car_N ! Sg; -- has value “car”
Difference between records and tables
Records have named fields that can be of any type.
When projecting a field from a record, you must know the exact name:
{s = "hello" ; compl = "world"}.s ;
Tables are associations from key to value. Keys can only be of finite types (param).
When selecting a value from a table, you can use variables, wildcards, computation:
table {Sg => "car" ; Pl => "cars" } ! Sg ;
s = \\x => noun ! x ++ “foo” ++ adj ! x ;
Recap on GF syntax
Tuples
Str*Str ;
{p1 : Str ; p2 : Str} ;
<"hello","world">
Parameters
param Number = Sg | Pl ;�param Case = Nom | Acc | Dat ;
lincat Noun = Number => Str ;�lincat Det = {s : Str ; g : Number} ;
Motivation for RGL
abstract Hello = {� flags startcat = Greeting ;� cat
Greeting ; Recipient ;�� fun� Hello : Recipient -> Greeting ;� World : Recipient ;� Mum : Recipient ;� Friends : Recipient ;
}
concrete HelloEng of Hello = {
lincat
Greeting, Recipient = {s : Str} ;�� lin� Hello rec = {s = "hello" ++ rec.s} ;� World = {s = "world"} ;� Mum = {s = "mum"} ;� Friends = {s = "friends"} ;��}
Motivation for RGL
concrete HelloIce of Hello = {�� lincat � Greeting = {s : Str} ;
Recipient = {s : Str ; n : Number ;� g : Gender} ;�
param� Gender = Fem | Masc | Neutr ;� Number = Sg | Pl ;�
lin� Hello rec = {s = case <rec.g,rec.n> of� <Sg,Masc> => "sæll" ++ rec.s ;� <Sg,_> => "sæl" ++ rec.s ;� <Pl,Masc> => "sælir" ++ rec.s ;� <Pl,_> => "sælar" ++ rec.s } ;
� World = {s = "heimur" ; g=Masc ; n=Sg} ;� Mum = {s = "mamma" ; g=Fem ; n=Sg} ;� Friends = {s = "vinir" ; g=Masc ; n=Pl} ;�}�
Hello with resource grammar
concrete HelloIce of Hello = open ParadigmsIce, SyntaxIce in {�� lincat � Greeting = Utt ; � Recipient = N ;� lin
Hello r = mkGreeting hello_Interj r ; � World = mkN "heimur" ; � Mum = mkN "mamma" ;� Friends = mkN "vinir" ; � oper � hello_Interj = mkInterj "sæll" ; � mkGreeting = ...
concrete HelloKaz of Hello = open ParadigmsKaz, SyntaxKaz in {�� lincat � Greeting = Utt ; � Recipient = N ;� lin
Hello r = mkGreeting hello_Interj r ; � World = mkN "әлем" ; � Mum = mkN "ана" ;� Friends = mkN "достар" ; � oper � hello_Interj = mkInterj "сәлем" ; � mkGreeting = ...
Resource Grammar Library
(You can always write application grammars without RGL too!)
Now write your own!
Piece of cake right?
Mini resource grammar
Miniresource in words (1/6)
Sentence & Utterance
Polarity
Tense
Miniresource in words (2/6)
Clause
Verb phrase
Verb & Two-place verb
Miniresource in words (3/6)
Noun phrase
Common noun
Noun
Miniresource in words (4/6)
Adjective phrase
Adjective
Miniresource in words (5/6)
Adverb
Preposition
Miniresource in words (6/6)
Conjunction
Determiner
Pronoun
Where to start?
Lexical categories / Morphology
Syntax
Both
Test your grammar regularly
Morphology & lexical categories
Nouns: what
What distinctions do I need?
English
Finnish
What distinctions do I need?
German
Nouns: what
What distinctions do I need?
English
Finnish
What distinctions do I need?
German
Nouns: how
English: Noun : Type = { s : Number => Str } ;
car_N = { s = table { Sg => “car” ; Pl => “cars” } ;
bus_N = { s = table { Sg => “bus” ; Pl => “buses” } ;
baby_N = { s = table { Sg => “baby” ; Pl => “babies” } ;
Nouns: paradigms
oper carNoun : Str -> Noun ;
carNoun car = { s = table { Sg => car ; Pl => car + “s” } ;
oper busNoun : Str -> Noun ;
busNoun bus = { s = table { Sg => bus ; Pl => bus + “es” } ;
oper babyNoun : Str -> Noun ;
babyNoun baby = { s = table { Sg => baby ; Pl => init baby + “ies” } ;
Nouns: smart paradigms
oper regNoun : Str -> Noun = \s -> case s of {
_ + ("s" | "ch") => { s = table { Sg => s ; Pl => s + "es" } ;
_ + ("y") => { s = table { Sg => s ; Pl => init s + "ies" } ;
_ => { s = table { Sg => s ; Pl => s + "s" }
} ;
Smart paradigms: Dutch
regNoun : Str -> Noun = \s -> case s of {
_ + ("a" | "o" | "y" | "u" | "oe" | "é") => mkNoun s (s + "'s") Utr ;
_ + ("oir" | "ion" | "je") => mkNoun s (s + "s") Neutr ;
? + ? + ? + _ +
("el" | "em" | "en" | "er" | "erd" | "aar" | "aard" | "ie") -- unstressed
=> mkNoun s (s + "s") Utr ;
_ + ("i"|"u") => mkNoun s (endCons s + "en") Utr ;
b + v@("aa"|"ee"|"oo"|"uu") + c@? => mkNoun s (b + shortVoc v c + "en") Utr ;
b + ("ei"|"eu"|"oe"|"ou"|"ie"|"ij"|"ui") + ? => mkNoun s (endCons s + "en") Utr ;
_ + "ie" => mkNoun s (s + "ën") Utr ;
b + v@("a"|"e"|"i"|"o"|"u") + c@? => mkNoun s (b + v + c + c + "en") Utr ;
_ => mkNoun s (endCons s + "en") Utr
} ;
Applying smart paradigms
> regNoun "meisje"� s . NF Sg Nom => meisje� s . NF Sg Gen => meisjes� s . NF Pl Nom => meisjes� s . NF Pl Gen => meisjes� g . Neutr
> regNoun "muis"� s . NF Sg Nom => muis� s . NF Sg Gen => muis� s . NF Pl Nom => muizen� s . NF Pl Gen => muizens� g . Utr
(later: how about the nice mkN function?)
Verbs (Italian)
Phrases
Phrasal categories
AP
cat AP ;
fun UseA : A -> AP ;
CN and NP
cat CN ;
fun UseN : N -> CN ;
fun AdjCN : AP -> CN -> CN ;
cat NP ;
fun DetCN : Det -> CN -> NP ;
fun ConjNP : Conjunction -> NP -> NP -> NP ;
VP
cat VP ;
fun UseV : V -> VP ;
fun ComplV2 : V2 -> NP -> VP ;
fun CompAP : AP -> VP ;
Syntax
Clauses
cat S, Cl, Pol ;
fun PredVP : NP -> VP -> Cl ;
fun UsePresCl : Pol -> Cl -> S ;
fun ConjS : Conjunction -> S -> S -> S ;
Demo
Is this useful for more than exercise?
Effort
Full resource grammar: months
Mini resource grammar:
days to weeks
RGL
Wide-coverage
Wide-coverage grammar:
days if we have RGL
Mini
Effort
RGL
Wide-coverage
Mini
Conclusion
Writing miniresources is…
Kiitos!
Paldies!
Thank you!