Grammar transformation: making a grammar less strict
When #27 and #28 are solved, we can implement grammar transformations. One particular interest is to make a grammar "less strict" (i.e., make it recognise more sentences), by loosening (or removing) some of the parameter dependencies.
Here is a proposed algorithm
1. (Manually) Decide which parameters should be merged
In this example we want to merge Sg and Pl...
param Num = Sg | Pl;
...into a single parameter:
param Num = Any;
2. Split functions
All functions with a linearisation table involving Sg or Pl...
love = {s = table {Sg => "loves"; Pl => "love"}};
moose = {s = table {Sg => "moose"; Pl => "mooses"}};
deer = {s = table {_ => "deer"}};
love = {s = "älskar"};
moose = {s = table {Sg => "älg"; Pl => "älgar"}; gen = Utr};
deer = {s = table {_ => "rådjur"}; gen = Neu};
...should be split into several functions, one each for Sg and Pl:
love_Sg = {s = table {Sg => "loves"}};
love_Pl = {s = table {Pl => "love"}};
moose_Sg = {s = table {Sg => "moose"}};
moose_Pl = {s = table {Pl => "mooses"}};
deer = {s = table {_ => "deer"}};
love = {s = "älskar"};
moose_Sg = {s = table {Sg => "älg"}; gen = Utr};
moose_Pl = {s = table {Pl => "älgar"}; gen = Utr};
deer = {s = table {_ => "rådjur"}; gen = Neu};
2a. The corresponding functions in the abstract GF grammar should also be split
2b. Some additional functions in a language also have to be split, if they are split in the other language.
E.g., love in Swedish:
love_Sg = {s = "älskar"};
love_Pl = {s = "älskar"};
Note that not all nouns have to be split. E.g., deer does not inflect for Number in either English or Swedish, so it's not necessary to split it.
3. Change all occurrences of Sg and Pl into Any
a = {s = "a"; num = Any};
mooseSg = {s = table {Any => "moose"}};
moosePl = {s = table {Any => "mooses"}};
a = {s = table {Neu => "ett"; Utr => "en"}; num = Any};
mooseSg = {s = table {Any => "älg"}; gen = Utr};
moosePl = {s = table {Any => "älgar"}; gen = Utr};
Example
With these transformations, the grammars would recognise things like
"all deer loves a mooses" == "alla rådjur älskar en älgar"
The example grammar:
abstract Mini = {
cat S; VP; NP; Verb; Det; Noun;
fun
mkS : NP -> VP -> S;
mkVP : Verb -> NP -> VP;
mkNP : Det -> Noun -> NP;
love, hate : Verb;
a, all : Det;
moose, deer : Noun;
}
concrete MiniEng of Mini = {
param
Num = Sg | Pl;
lincat
S = {s : Str};
NP, Det = {s : Str; num : Num};
VP, Verb, Noun = {s : Num => Str};
lin
mkS np vp = {s = np.s ++ vp.s!np.num};
mkVP verb np = {s = \\num => verb.s!num ++ np.s};
mkNP det noun = {s = det.s ++ noun.s!det.num; num = det.num};
love = {s = table {Sg => "loves"; Pl => "love"}};
hate = {s = table {Sg => "hates"; Pl => "hate"}};
a = {s = "a"; num = Sg};
all = {s = "all"; num = Pl};
moose = {s = table {Sg => "moose"; Pl => "mooses"}};
deer = {s = table {Sg => "deer"; Pl => "deer"}};
}
concrete MiniSwe of Mini = {
param
Num = Sg | Pl;
Gen = Neu | Utr;
lincat
S, NP, VP, Verb = {s : Str};
Det = {s : Gen => Str; num : Num};
Noun = {s : Num => Str; gen : Gen};
lin
mkS np vp = {s = np.s ++ vp.s};
mkVP verb np = {s = verb.s ++ np.s};
mkNP det noun = {s = det.s!noun.gen ++ noun.s!det.num};
love = {s = "älskar"};
hate = {s = "hatar"};
a = {s = table {Neu => "ett"; Utr => "en"}; num = Sg};
all = {s = \\_ => "alla"; num = Pl};
moose = {s = table {Sg => "älg"; Pl => "älgar"}; gen = Utr};
deer = {s = \\_ => "rådjur"; gen = Neu};
}
Here is a larger example that I want to be able to handle. The grammar is ExemplumSwe from here:
https://github.com/MUSTE-Project/MULLE/tree/develop/examples/grammars/exemplum
The grammar currently accepts the following examples:
- en stor blå kung läser
- den kalla datorn är god
- ett dåligt hus är kallt
- många goda mödrar läser
- de stora husen är kalla
If we unify CommonScand.Number so that Sg = Pl, we should also accept:
- en stor blå kungar läser
- den kall datorn är god
- många dåligt hus är kallt
- en goda mödrar läser
- de stora husen är kallt
If we instead unify ResSwe.NGender (i.e., Utr = Neutr), we should accept:
- en stort blå kung läser
- den kalla datorn är gott
- ett dåligt pojke är kallt
And if we unify CommonScand.Species (i.e., Indef = Def):
- den stor blå kung läser
- den kall datorn är god
- ett dåliga hus är kallt
- många goda mödrarna läser
- få stora husen är kalla