-
Notifications
You must be signed in to change notification settings - Fork 0
/
Implementation.html
500 lines (430 loc) · 16.5 KB
/
Implementation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<html>
<body>
<i> Produced by
gfdoc - a rudimentary GF document generator.
(c) Aarne Ranta (aarne@cs.chalmers.se) 2002 under GNU GPL.
</i>
<p>
<h1> Implementation of MOLTO Phrasebook</h1>
<h2> The functor for (mostly) common structures</h2>
<pre>
incomplete concrete SentencesI of Sentences = Numeral **
open
Syntax,
Lexicon,
Symbolic, -- for names as strings
Prelude
in {
lincat
Phrase = Text ;
Sentence = S ;
Question = QS ;
Proposition = Cl ;
Item = NP ;
Kind = CN ;
MassKind = CN ;
Quality = AP ;
Property = A ;
Object = NP ;
PrimObject = NP ;
Place = NPPlace ; -- {name : NP ; at : Adv ; to : Adv} ;
PlaceKind = CNPlace ; -- {name : CN ; at : Prep ; to : Prep} ;
Currency = CN ;
Price = NP ;
Action = Cl ;
Person = NPPerson ; -- {name : NP ; isPron : Bool ; poss : Quant} ;
Nationality = NPNationality ; -- {lang : NP ; country : NP ; prop : A} ;
Language = NP ;
Citizenship = A ;
Country = NP ;
Day = NPDay ; -- {name : NP ; point : Adv ; habitual : Adv} ;
Date = Adv ;
Name = NP ;
Number = Card ;
ByTransport = Adv ;
Transport = {name : CN ; by : Adv} ;
Superlative = Det ;
lin
PSentence s = mkText s | lin Text (mkUtt s) ; -- optional '.'
PQuestion s = mkText s | lin Text (mkUtt s) ; -- optional '?'
PObject x = mkPhrase (mkUtt x) ;
PKind x = mkPhrase (mkUtt x) ;
PMassKind x = mkPhrase (mkUtt x) ;
PQuality x = mkPhrase (mkUtt x) ;
PNumber x = mkPhrase (mkUtt x) ;
PPlace x = mkPhrase (mkUtt x.name) ;
PPlaceKind x = mkPhrase (mkUtt x.name) ;
PCurrency x = mkPhrase (mkUtt x) ;
PPrice x = mkPhrase (mkUtt x) ;
PLanguage x = mkPhrase (mkUtt x) ;
PCountry x = mkPhrase (mkUtt x) ;
PCitizenship x = mkPhrase (mkUtt (mkAP x)) ;
PDay d = mkPhrase (mkUtt d.name) ;
PTransport t = mkPhrase (mkUtt t.name) ;
PByTransport t = mkPhrase (mkUtt t) ;
PYes = mkPhrase yes_Utt ;
PNo = mkPhrase no_Utt ;
PYesToNo = mkPhrase yes_Utt ;
Is = mkCl ;
SProp = mkS ;
SPropNot = mkS negativePol ;
QProp p = mkQS (mkQCl p) ;
WherePlace place = mkQS (mkQCl where_IAdv place.name) ;
WherePerson person = mkQS (mkQCl where_IAdv person.name) ;
PropAction a = a ;
AmountCurrency num curr = mkNP num curr ;
ObjItem i = i ;
ObjNumber n k = mkNP n k ;
ObjIndef k = mkNP a_Quant k ;
ObjPlural k = mkNP aPl_Det k ;
ObjMass k = mkNP k ;
ObjAndObj = mkNP and_Conj ;
OneObj o = o ;
This kind = mkNP this_Quant kind ;
That kind = mkNP that_Quant kind ;
These kind = mkNP this_Quant plNum kind ;
Those kind = mkNP that_Quant plNum kind ;
The kind = mkNP the_Quant kind ;
Thes kind = mkNP the_Quant plNum kind ;
ThisMass kind = mkNP this_Quant kind ;
ThatMass kind = mkNP that_Quant kind ;
TheMass kind = mkNP the_Quant kind ;
SuchKind quality kind = mkCN quality kind ;
SuchMassKind quality kind = mkCN quality kind ;
Very property = mkAP very_AdA (mkAP property) ;
Too property = mkAP too_AdA (mkAP property) ;
PropQuality property = mkAP property ;
ThePlace kind = let dd = if_then_else Det kind.isPl thePl_Det theSg_Det
in placeNP dd kind ;
APlace kind = let dd = if_then_else Det kind.isPl thePl_Det theSg_Det
in placeNP dd kind ;
IMale, IFemale = mkPerson i_Pron ;
YouFamMale, YouFamFemale = mkPerson youSg_Pron ;
YouPolMale, YouPolFemale = mkPerson youPol_Pron ;
LangNat n = n.lang ;
CitiNat n = n.prop ;
CountryNat n = n.country ;
PropCit c = c ;
OnDay d = d.point ;
Today = today_Adv ;
PersonName n =
{name = n ; isPron = False ; poss = mkQuant he_Pron} ; -- poss not used
</pre>
<pre>
NameNN = symb "NN" ;
NNumeral n = mkCard <lin Numeral n : Numeral> ;
SHave p obj = mkS (mkCl p.name have_V2 obj) ;
SHaveNo p k = mkS negativePol (mkCl p.name have_V2 (mkNP aPl_Det k)) ;
SHaveNoMass p m = mkS negativePol (mkCl p.name have_V2 (mkNP m)) ;
QDoHave p obj = mkQS (mkQCl (mkCl p.name have_V2 obj)) ;
AHaveCurr p curr = mkCl p.name have_V2 (mkNP aPl_Det curr) ;
ACitizen p n = mkCl p.name n ;
ABePlace p place = mkCl p.name place.at ;
ByTransp t = t.by ;
oper
</pre>
These operations are used internally in Sentences.
<pre>
mkPhrase : Utt -> Text = \u -> lin Text u ; -- no punctuation
mkPerson : Pron -> {name : NP ; isPron : Bool ; poss : Quant} = \p ->
{name = mkNP p ; isPron = True ; poss = mkQuant p} ;
</pre>
These are used in Words for each language.
<pre>
NPNationality : Type = {lang : NP ; country : NP ; prop : A} ;
mkNPNationality : NP -> NP -> A -> NPNationality = \la,co,pro ->
{lang = la ;
country = co ;
prop = pro
} ;
NPDay : Type = {name : NP ; point : Adv ; habitual : Adv} ;
mkNPDay : NP -> Adv -> Adv -> NPDay = \d,p,h ->
{name = d ;
point = p ;
habitual = h
} ;
NPPlace : Type = {name : NP ; at : Adv ; to : Adv} ;
CNPlace : Type = {name : CN ; at : Prep ; to : Prep; isPl : Bool} ;
mkCNPlace : CN -> Prep -> Prep -> CNPlace = \p,i,t -> {
name = p ;
at = i ;
to = t ;
isPl = False
} ;
mkCNPlacePl : CN -> Prep -> Prep -> CNPlace = \p,i,t -> {
name = p ;
at = i ;
to = t ;
isPl = True
} ;
placeNP : Det -> CNPlace -> NPPlace = \det,kind ->
let name : NP = mkNP det kind.name in {
name = name ;
at = mkAdv kind.at name ;
to = mkAdv kind.to name
} ;
NPPerson : Type = {name : NP ; isPron : Bool ; poss : Quant} ;
relativePerson : GNumber -> CN -> (Num -> NP -> CN -> NP) -> NPPerson -> NPPerson =
\n,x,f,p ->
let num = if_then_else Num n plNum sgNum in {
name = case p.isPron of {
True => mkNP p.poss num x ;
_ => f num p.name x
} ;
isPron = False ;
poss = mkQuant he_Pron -- not used because not pron
} ;
GNumber : PType = Bool ;
sing = False ; plur = True ;
</pre>
for languages without GenNP, use <i>the wife of p</i>
<pre>
mkRelative : Bool -> CN -> NPPerson -> NPPerson = \n,x,p ->
relativePerson n x
(\a,b,c -> mkNP (mkNP the_Quant a c) (Syntax.mkAdv possess_Prep b)) p ;
</pre>
for languages with GenNP, use <i>p's wife</i>
relativePerson n x (\a,b,c -> mkNP (GenNP b) a c) p ;
<pre>
}
</pre>
<h2> Implementations of Words, with English as example</h2>
<pre>
concrete WordsEng of Words = SentencesEng **
open
SyntaxEng,
ParadigmsEng,
(L = LexiconEng),
(P = ParadigmsEng),
IrregEng,
ExtraEng,
Prelude in {
lin
</pre>
Kinds; many of them are in the resource lexicon, others can be built by <tt>mkN</tt>.
<pre>
Apple = mkCN L.apple_N ;
Beer = mkCN L.beer_N ;
Bread = mkCN L.bread_N ;
Cheese = mkCN (mkN "cheese") ;
Chicken = mkCN (mkN "chicken") ;
Coffee = mkCN (mkN "coffee") ;
Fish = mkCN L.fish_N ;
Meat = mkCN (mkN "meat") ;
Milk = mkCN L.milk_N ;
Pizza = mkCN (mkN "pizza") ;
Salt = mkCN L.salt_N ;
Tea = mkCN (mkN "tea") ;
Water = mkCN L.water_N ;
Wine = mkCN L.wine_N ;
</pre>
Properties; many of them are in the resource lexicon, others can be built by <tt>mkA</tt>.
<pre>
Bad = L.bad_A ;
Boring = mkA "boring" ;
Cheap = mkA "cheap" ;
Cold = L.cold_A ;
Delicious = mkA "delicious" ;
Expensive = mkA "expensive" ;
Fresh = mkA "fresh" ;
Good = L.good_A ;
Suspect = mkA "suspect" ;
Warm = L.warm_A ;
</pre>
Places require different prepositions to express location; in some languages
also the directional preposition varies, but in English we use <tt>to</tt>, as
defined by <tt>mkPlace</tt>.
<pre>
Airport = mkPlace "airport" "at" ;
AmusementPark = mkCompoundPlace "amusement" "park" "at" ;
Bank = mkPlace "bank" "at" ;
Bar = mkPlace "bar" "in" ;
Cafeteria = mkPlace "canteen" "in" ;
Center = mkPlace "center" "in" ;
Cinema = mkPlace "cinema" "at" ;
Church = mkPlace "church" "in" ;
Disco = mkPlace "disco" "at" ;
Hospital = mkPlace "hospital" "in" ;
Hotel = mkPlace "hotel" "in" ;
Museum = mkPlace "museum" "at" ;
Park = mkPlace "park" "in" ;
Parking = mkCompoundPlace "car" "park" "in" ;
Pharmacy = mkPlace "pharmacy" "at" ;
PostOffice = mkCompoundPlace "post" "office" "at" ;
Pub = mkPlace "pub" "at" ;
Restaurant = mkPlace "restaurant" "in" ;
School = mkPlace "school" "at" ;
Shop = mkPlace "shop" "at" ;
Station = mkPlace "station" "at" ;
Supermarket = mkPlace "supermarket" "at" ;
Theatre = mkPlace "theatre" "at" ;
Toilet = mkPlace "toilet" "in" ;
University = mkPlace "university" "at" ;
Zoo = mkPlace "zoo" "at" ;
CitRestaurant cit = mkCNPlace (mkCN cit (mkN "restaurant")) in_Prep to_Prep ;
</pre>
Currencies; <tt>crown</tt> is ambiguous between Danish and Swedish crowns.
<pre>
DanishCrown = mkCN (mkA "Danish") (mkN "crown") | mkCN (mkN "crown") ;
Dollar = mkCN (mkN "dollar") ;
Euro = mkCN (mkN "euro" "euros") ; -- to prevent euroes
Lei = mkCN (mkN "leu" "lei") ;
Leva = mkCN (mkN "lev") ;
NorwegianCrown = mkCN (mkA "Norwegian") (mkN "crown") | mkCN (mkN "crown") ;
Pound = mkCN (mkN "pound") ;
Rouble = mkCN (mkN "rouble") ;
SwedishCrown = mkCN (mkA "Swedish") (mkN "crown") | mkCN (mkN "crown") ;
Zloty = mkCN (mkN "zloty" "zloty") ;
</pre>
Nationalities
<pre>
Belgian = mkA "Belgian" ;
Belgium = mkNP (mkPN "Belgium") ;
Bulgarian = mkNat "Bulgarian" "Bulgaria" ;
Catalan = mkNPNationality (mkNP (mkPN "Catalan")) (mkNP (mkPN "Catalonia")) (mkA "Catalonian") ;
Danish = mkNat "Danish" "Denmark" ;
Dutch = mkNPNationality (mkNP (mkPN "Dutch")) (mkNP the_Quant (mkN "Netherlands")) (mkA "Dutch") ;
English = mkNat "English" "England" ;
Finnish = mkNat "Finnish" "Finland" ;
Flemish = mkNP (mkPN "Flemish") ;
French = mkNat "French" "France" ;
German = mkNat "German" "Germany" ;
Italian = mkNat "Italian" "Italy" ;
Norwegian = mkNat "Norwegian" "Norway" ;
Polish = mkNat "Polish" "Poland" ;
Romanian = mkNat "Romanian" "Romania" ;
Russian = mkNat "Russian" "Russia" ;
Spanish = mkNat "Spanish" "Spain" ;
Swedish = mkNat "Swedish" "Sweden" ;
</pre>
Means of transportation
<pre>
Bike = mkTransport L.bike_N ;
Bus = mkTransport (mkN "bus") ;
Car = mkTransport L.car_N ;
Ferry = mkTransport (mkN "ferry") ;
Plane = mkTransport L.airplane_N ;
Subway = mkTransport (mkN "subway") ;
Taxi = mkTransport (mkN "taxi") ;
Train = mkTransport (mkN "train") ;
Tram = mkTransport (mkN "tram") ;
ByFoot = P.mkAdv "by foot" ;
</pre>
Actions: the predication patterns are very often language-dependent.
<pre>
AHasAge p num = mkCl p.name (mkNP (mkNP num L.year_N) (ParadigmsEng.mkAdv "old"));
AHasChildren p num = mkCl p.name have_V2 (mkNP num L.child_N) ;
AHasRoom p num = mkCl p.name have_V2
(mkNP (mkNP a_Det (mkN "room")) (SyntaxEng.mkAdv for_Prep (mkNP num (mkN "person")))) ;
AHasTable p num = mkCl p.name have_V2
(mkNP (mkNP a_Det (mkN "table")) (SyntaxEng.mkAdv for_Prep (mkNP num (mkN "person")))) ;
AHasName p name = mkCl (nameOf p) name ;
AHungry p = mkCl p.name (mkA "hungry") ;
AIll p = mkCl p.name (mkA "ill") ;
AKnow p = mkCl p.name IrregEng.know_V ;
ALike p item = mkCl p.name (mkV2 (mkV "like")) item ;
ALive p co = mkCl p.name (mkVP (mkVP (mkV "live")) (SyntaxEng.mkAdv in_Prep co)) ;
ALove p q = mkCl p.name (mkV2 (mkV "love")) q.name ;
AMarried p = mkCl p.name (mkA "married") ;
AReady p = mkCl p.name (mkA "ready") ;
AScared p = mkCl p.name (mkA "scared") ;
ASpeak p lang = mkCl p.name (mkV2 IrregEng.speak_V) lang ;
AThirsty p = mkCl p.name (mkA "thirsty") ;
ATired p = mkCl p.name (mkA "tired") ;
AUnderstand p = mkCl p.name IrregEng.understand_V ;
AWant p obj = mkCl p.name (mkV2 (mkV "want")) obj ;
AWantGo p place = mkCl p.name want_VV (mkVP (mkVP IrregEng.go_V) place.to) ;
</pre>
miscellaneous
<pre>
QWhatName p = mkQS (mkQCl whatSg_IP (mkVP (nameOf p))) ;
QWhatAge p = mkQS (mkQCl (ICompAP (mkAP L.old_A)) p.name) ;
HowMuchCost item = mkQS (mkQCl how8much_IAdv (mkCl item IrregEng.cost_V)) ;
ItCost item price = mkCl item (mkV2 IrregEng.cost_V) price ;
PropOpen p = mkCl p.name open_Adv ;
PropClosed p = mkCl p.name closed_Adv ;
PropOpenDate p d = mkCl p.name (mkVP (mkVP open_Adv) d) ;
PropClosedDate p d = mkCl p.name (mkVP (mkVP closed_Adv) d) ;
PropOpenDay p d = mkCl p.name (mkVP (mkVP open_Adv) d.habitual) ;
PropClosedDay p d = mkCl p.name (mkVP (mkVP closed_Adv) d.habitual) ;
</pre>
Building phrases from strings is complicated: the solution is to use
mkText : Text -> Text -> Text ;
<pre>
PSeeYouDate d = mkText (lin Text (ss ("see you"))) (mkPhrase (mkUtt d)) ;
PSeeYouPlace p = mkText (lin Text (ss ("see you"))) (mkPhrase (mkUtt p.at)) ;
PSeeYouPlaceDate p d =
mkText (lin Text (ss ("see you")))
(mkText (mkPhrase (mkUtt p.at)) (mkPhrase (mkUtt d))) ;
</pre>
Relations are expressed as <i>my wife</i> or <i>my son's wife</i>, as defined by <tt>xOf</tt>
below. Languages without productive genitives must use an equivalent of
<i>the wife of my son</i> for non-pronouns.
<pre>
Wife = xOf sing (mkN "wife") ;
Husband = xOf sing (mkN "husband") ;
Son = xOf sing (mkN "son") ;
Daughter = xOf sing (mkN "daughter") ;
Children = xOf plur L.child_N ;
</pre>
week days
<pre>
Monday = mkDay "Monday" ;
Tuesday = mkDay "Tuesday" ;
Wednesday = mkDay "Wednesday" ;
Thursday = mkDay "Thursday" ;
Friday = mkDay "Friday" ;
Saturday = mkDay "Saturday" ;
Sunday = mkDay "Sunday" ;
Tomorrow = P.mkAdv "tomorrow" ;
</pre>
modifiers of places
<pre>
TheBest = mkSuperl L.good_A ;
TheClosest = mkSuperl L.near_A ;
TheCheapest = mkSuperl (mkA "cheap") ;
TheMostExpensive = mkSuperl (mkA "expensive") ;
TheMostPopular = mkSuperl (mkA "popular") ;
TheWorst = mkSuperl L.bad_A ;
SuperlPlace sup p = placeNP sup p ;
</pre>
transports
<pre>
HowFar place = mkQS (mkQCl far_IAdv place.name) ;
HowFarFrom x y = mkQS (mkQCl far_IAdv (mkNP y.name (SyntaxEng.mkAdv from_Prep x.name))) ;
HowFarFromBy x y t =
mkQS (mkQCl far_IAdv (mkNP (mkNP y.name (SyntaxEng.mkAdv from_Prep x.name)) t)) ;
HowFarBy y t = mkQS (mkQCl far_IAdv (mkNP y.name t)) ;
WhichTranspPlace trans place =
mkQS (mkQCl (mkIP which_IDet trans.name) (mkVP (mkVP L.go_V) place.to)) ;
IsTranspPlace trans place =
mkQS (mkQCl (mkCl (mkCN trans.name place.to))) ;
</pre>
auxiliaries
<pre>
oper
mkNat : Str -> Str -> NPNationality = \nat,co ->
mkNPNationality (mkNP (mkPN nat)) (mkNP (mkPN co)) (mkA nat) ;
mkDay : Str -> {name : NP ; point : Adv ; habitual : Adv} = \d ->
let day = mkNP (mkPN d) in
mkNPDay day (SyntaxEng.mkAdv on_Prep day)
(SyntaxEng.mkAdv on_Prep (mkNP a_Quant plNum (mkCN (mkN d)))) ;
mkCompoundPlace : Str -> Str -> Str -> {name : CN ; at : Prep ; to : Prep; isPl : Bool} = \comp, p, i ->
mkCNPlace (mkCN (P.mkN comp (mkN p))) (P.mkPrep i) to_Prep ;
mkPlace : Str -> Str -> {name : CN ; at : Prep ; to : Prep; isPl : Bool} = \p,i ->
mkCNPlace (mkCN (mkN p)) (P.mkPrep i) to_Prep ;
open_Adv = P.mkAdv "open" ;
closed_Adv = P.mkAdv "closed" ;
xOf : GNumber -> N -> NPPerson -> NPPerson = \n,x,p ->
relativePerson n (mkCN x) (\a,b,c -> mkNP (GenNP b) a c) p ;
nameOf : NPPerson -> NP = \p -> (xOf sing (mkN "name") p).name ;
mkTransport : N -> {name : CN ; by : Adv} = \n -> {
name = mkCN n ;
by = SyntaxEng.mkAdv by8means_Prep (mkNP n)
} ;
mkSuperl : A -> Det = \a -> SyntaxEng.mkDet the_Art (SyntaxEng.mkOrd a) ;
far_IAdv = ExtraEng.IAdvAdv (ss "far") ;
}
</pre>
</body>
</html>