ENIAMwalRenderer.ml
26.3 KB
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
(*
* ENIAMlexSemantics is a library that assigns tokens with lexicosemantic information.
* Copyright (C) 2016-2017 Wojciech Jaworski <wjaworski atSPAMfree mimuw dot edu dot pl>
* Copyright (C) 2016-2017 Institute of Computer Science Polish Academy of Sciences
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
open ENIAM_LCGtypes
open ENIAMwalTypes
let arg_of_ctype = function
Int -> Atom "int"
| Rel -> Atom "rel"
(* | Sub -> LCGtypes.Atom "sub"
| Coord -> LCGtypes.Atom "coord" *)
| CompTypeUndef -> Top
(* | CompTypeAgr -> LCGtypes.AVar "ctype" *)
let render_number = function
Number n -> Atom n
| NumberUndef -> Top
| NumberAgr -> Top
let render_negation = function
Negation -> Atom "neg"
| Aff -> Atom "aff"
| NegationUndef -> Top
let render_pos_entry = function
"subst" -> [Atom "subst"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]
| "ppron12" -> [Atom "ppron12"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]
| "ppron3" -> [Atom "ppron3"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]
| "siebie" -> [Atom "siebie"; AVar "case"]
| "num" -> [Atom "num"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]
| "intnum" -> [Atom "num"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]
| "prep" -> [Atom "prep"; AVar "case"]
| "adj" -> [Atom "adj"; AVar "number"; AVar "case"; AVar "gender"; AVar "grad"]
| "adv" -> [Atom "adv"; AVar "grad"]
| "ger" -> [Atom "ger"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"; AVar "negation"]
| "pact" -> [Atom "pact"; AVar "number"; AVar "case"; AVar "gender"; AVar "negation"]
| "ppas" -> [Atom "ppas"; AVar "number"; AVar "case"; AVar "gender"; AVar "negation"]
| "inf" -> [Atom "inf"; AVar "aspect"; AVar "negation"]
| "qub" -> [Atom "qub"]
| "compar" -> [Atom "compar"; AVar "case"]
| "comp" -> [Atom "comp"; AVar "ctype"]
| "fin" -> [Atom "pers"; AVar "negation"]
| "praet" -> [Atom "pers"; AVar "negation"]
| "pred" -> [Atom "pers"; AVar "negation"]
| "winien" -> [Atom "pers"; AVar "negation"]
| "bedzie" -> [Atom "pers"; AVar "negation"]
| s -> failwith ("render_pos_entry: " ^ s)
let render_pos = function (* wprowadzam uzgodnienia a nie wartości cech, bo wartości cech są wprowadzane przez leksem a uzgodnienia wiążą je z wartościami u nadrzędnika *)
| SUBST(number,Case case) -> [Atom "subst"; render_number number; Atom case; Top; Top]
| SUBST(_,NomAgr) -> [Atom "subst"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
| SUBST(_,GenAgr) -> [Atom "subst"; AVar "number"; Atom "gen"; AVar "gender"; AVar "person"]
| SUBST(_,AllAgr) -> [Atom "subst"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]
| SUBST(number,CaseAgr) -> [Atom "subst"; render_number number; AVar "case"; Top; Top]
| SUBST(_,CaseUndef) -> [Atom "subst"; Top; Top; Top; Top]
| PPRON12(number,Case case) -> [Atom "ppron12"; render_number number; Atom case; Top; Top]
| PPRON3(number,Case case) -> [Atom "ppron3"; render_number number; Atom case; Top; Top]
| SIEBIE(Case case) -> [Atom "siebie"; Atom case]
| NUM(Case case,_) -> [Atom "num"; Top; Atom case; Top; Top]
| NUM(NomAgr,_) -> [Atom "num"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
(* | NUM(CaseAgr,_) -> [Atom "num"; Top; AVar "case"; Top; Top]
| NUM(CaseUndef,_) -> [Atom "num"; Top; Top; Top; Top]*)
| PREP(Case case) -> [Atom "prep"; Atom case]
| ADJ(_,Case case,_,Grad grad) -> [Atom "adj"; Top; Atom case; Top; Atom grad]
(* | ADJ(_,NomAgr,_,_) -> [Atom "adj"; AVar "number"; Atom "nom"; AVar "gender"]
| ADJ(_,CaseAgr,_,_) -> [Atom "adj"; Top; AVar "case"; Top]*)
| ADJ(_,CaseUndef,_,Grad grad) -> [Atom "adj"; Top; Top; Top; Atom grad]
| ADJ(_,AllAgr,_,Grad grad) -> [Atom "adj"; AVar "number"; AVar "case"; AVar "gender"; Atom grad]
| ADJ(_,AllAgr,_,GradUndef) -> [Atom "adj"; AVar "number"; AVar "case"; AVar "gender"; Top]
| ADV (Grad grad) -> [Atom "adv"; Atom grad]
| ADV GradUndef -> [Atom "adv"; Top]
| GER(_,Case case,_,_,neg) -> [Atom "ger"; Top; Atom case; Top; Top; render_negation neg]
(* | GER(_,NomAgr,_,_,_) -> [Atom "ger"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
| GER(_,CaseAgr,_,_,_) -> [Atom "ger"; Top; AVar "case"; Top; Top]
| GER(_,CaseUndef,_,_,_) -> [Atom "ger"; Top; Top; Top; Top]
| PACT(_,Case case,_,_,_) -> [Atom "pact"; Top; Atom case; Top]
| PACT(_,NomAgr,_,_,_) -> [Atom "pact"; AVar "number"; Atom "nom"; AVar "gender"]*)
| PACT(_,AllAgr,_,_,neg) -> [Atom "pact"; AVar "number"; AVar "case"; AVar "gender"; render_negation neg]
(* | PACT(_,CaseAgr,_,_,_) -> [Atom "pact"; Top; AVar "case"; Top]*)
| PPAS(_,Case case,_,_,neg) -> [Atom "ppas"; Top; Atom case; Top; render_negation neg]
| PPAS(_,CaseUndef,_,_,neg) -> [Atom "ppas"; Top; Top; Top; render_negation neg]
(* | PPAS(_,NomAgr,_,_,_) -> [Atom "ppas"; AVar "number"; Atom "nom"; AVar "gender"]*)
| PPAS(_,AllAgr,_,_,neg) -> [Atom "ppas"; AVar "number"; AVar "case"; AVar "gender"; render_negation neg]
(* | PPAS(_,CaseAgr,_,_,_) -> [Atom "ppas"; Top; AVar "case"; Top]*)
| INF(Aspect aspect,neg) -> [Atom "inf"; Atom aspect; render_negation neg]
| INF(AspectUndef,neg) -> [Atom "inf"; Top; render_negation neg]
| QUB -> [Atom "qub"]
| COMPAR (Case case) -> [Atom "compar"; Atom case]
| COMP ctype -> [Atom "comp"; arg_of_ctype ctype]
| PERS neg -> [Atom "pers"; render_negation neg]
| pos -> failwith ("render_pos: " ^ ENIAMwalStringOf.pos pos)
let render_phrase = function
NP(Case case) -> Tensor[Atom "np"; Top; Atom case; Top; Top]
| NP NomAgr -> Tensor[Atom "np"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
(* | NP GenAgr -> Tensor[Atom "np"; AVar "number"; Atom "gen"; AVar "gender"; AVar "person"]
| NP AllAgr -> Tensor[Atom "np"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]*)
| NP CaseAgr -> Tensor[Atom "np"; Top; AVar "case"; Top; Top]
(* | NP CaseUndef -> Tensor[Atom "np"; Top; Top; Top; Top]
| PrepNP("",CaseUndef) -> Tensor[Atom "prepnp"; Top; Top]*)
| PrepNP(prep,Case case) -> Tensor[Atom "prepnp"; Atom prep; Atom case]
| AdjP(Case case) -> Tensor[Atom "adjp"; Top; Atom case; Top]
(* | AdjP NomAgr -> Tensor[Atom "adjp"; AVar "number"; Atom "nom"; AVar "gender"]*)
| AdjP AllAgr -> Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]
(* | AdjP CaseAgr -> Tensor[Atom "adjp"; Top; AVar "case"; Top]
| PrepAdjP("",CaseUndef) -> Tensor[Atom "prepnp"; Top; Top]*)
| PrepAdjP(prep,Case case) -> Tensor[Atom "prepadjp"; Atom prep; Atom case]
(* | NumP(Case case) -> Tensor[Atom "nump"; Top; Atom case; Top; Top]
| NumP NomAgr -> Tensor[Atom "nump"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
| NumP CaseAgr -> Tensor[Atom "nump"; Top; AVar "case"; Top; Top]
| NumP CaseUndef -> Tensor[Atom "nump"; Top; Top; Top; Top]
| PrepNumP(_,"",CaseUndef) -> Tensor[Atom "prepnp"; Top; Top]
| PrepNumP(_,prep,Case case) -> Tensor[Atom "prepnump"; Atom prep; Atom case] *)
(* | ComprepNP("") -> Tensor[Atom "comprepnp"; Top]*)
| ComprepNP(prep) -> Tensor[Atom "comprepnp"; Atom prep]
| ComparP(prep,Case case) -> Tensor[Atom "compar"; Atom prep; Atom case]
(* | ComparPP(_,prep) -> Tensor[Atom "comparpp"; Atom prep] *)
(* | IP -> Tensor[Atom "ip";Top;Top;Top] *)
| CP (ctype,Comp comp) -> Tensor[Atom "cp"; arg_of_ctype ctype; Atom comp]
(* | CP (ctype,CompUndef) -> Tensor[Atom "cp"; arg_of_ctype ctype; Top]*)
| NCP(Case case,ctype,Comp comp) -> Tensor[Atom "ncp"; Top; Atom case; Top; Top; arg_of_ctype ctype; Atom comp]
| NCP(Case case,CompTypeUndef,CompUndef) -> Tensor[Atom "ncp"; Top; Atom case; Top; Top; Top; Top]
| NCP(NomAgr,ctype,Comp comp) -> Tensor[Atom "ncp"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"; arg_of_ctype ctype; Atom comp]
| NCP(NomAgr,CompTypeUndef,CompUndef) -> Tensor[Atom "ncp"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"; Top; Top]
| PrepNCP(prep,Case case,ctype,Comp comp) -> Tensor[Atom "prepncp"; Atom prep; Atom case; arg_of_ctype ctype; Atom comp]
| PrepNCP(prep,Case case,CompTypeUndef,CompUndef) -> Tensor[Atom "prepncp"; Atom prep; Atom case; Top; Top]
| InfP(Aspect aspect) -> Tensor[Atom "infp"; Atom aspect]
| InfP AspectUndef -> Tensor[Atom "infp"; Top]
(* | PadvP -> Tensor[Atom "padvp"] *)
| AdvP "misc" -> Tensor[Atom "advp"; Top] (* FIXME: a może Atom "mod" zamiast Top *)
| AdvP mode -> Tensor[Atom "advp"; Atom mode]
| ColonP -> Tensor[Atom "colonp"]
| FixedP lex -> Tensor[Atom "fixed"; Atom lex]
(* | PrepP -> Tensor[Atom "prepp";Top]
| Prep("",CaseAgr) -> Tensor[Atom "prep"; Top; AVar "case"]
| Prep("",CaseUAgr) -> Tensor[Atom "prep"; Top; AVar "ucase"]
| Num(AllAgr,Acm acm) -> Tensor[Atom "num"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"; Atom acm]
| Measure(AllUAgr) -> Tensor[Atom "measure"; AVar "unumber"; AVar "ucase"; AVar "ugender"; AVar "uperson"] *)
| Or -> Tensor[Atom "or"]
(* | Qub -> Tensor[Atom "qub"]*)
(* | Inclusion -> Tensor[Atom "inclusion"]
| Adja -> Tensor[Atom "adja"]
| Aglt -> Tensor[Atom "aglt"; AVar "number"; AVar "person"]
| AuxPast -> Tensor[Atom "aux-past"; AVar "number"; AVar "gender"; AVar "person"]
| AuxFut -> Tensor[Atom "aux-fut"; AVar "number"; AVar "gender"; AVar "person"]
| AuxImp -> Tensor[Atom "aux-imp"]
| Pro -> One
| ProNG -> One *)
| E Or -> Tensor[Atom "or"]
| E (CP(CompTypeUndef,CompUndef)) -> Tensor[Atom "cp"; Top; Top]
| E (NCP(NomAgr,CompTypeUndef,CompUndef)) -> Tensor[Atom "ncp"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"; Top; Top]
| E (NP(NomAgr)) -> Tensor[Atom "np"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
| E (PrepNP(prep,Case case)) -> Tensor[Atom "prepnp"; Atom prep; Atom case]
| E (NP(Case case)) -> Tensor[Atom "np"; Top; Atom case; Top; Top]
| E (NCP(Case case,CompTypeUndef,CompUndef)) -> Tensor[Atom "ncp"; Top; Atom case; Top; Top; Top; Top]
| E (PrepNCP(prep,Case case,CompTypeUndef,CompUndef)) -> Tensor[Atom "prepncp"; Atom prep; Atom case; Top; Top]
| phrase -> failwith ("render_phrase: " ^ ENIAMwalStringOf.phrase phrase)
let render_phrase_cat cat = function
NP(Case case) -> Tensor[Atom "np"; Atom cat; Top; Atom case; Top; Top]
| NP NomAgr -> Tensor[Atom "np"; Atom cat; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
(* | NP GenAgr -> Tensor[Atom "np"; Atom cat; AVar "number"; Atom "gen"; AVar "gender"; AVar "person"]
| NP AllAgr -> Tensor[Atom "np"; Atom cat; AVar "number"; AVar "case"; AVar "gender"; AVar "person"]*)
| NP CaseAgr -> Tensor[Atom "np"; Atom cat; Top; AVar "case"; Top; Top]
| NP CaseUndef -> Tensor[Atom "np"; Atom cat; Top; Top; Top; Top]
| PrepNP("",CaseUndef) -> Tensor[Atom "prepnp"; Atom cat; Top; Top]
| PrepNP("_",CaseUndef) -> Tensor[Atom "prepnp"; Atom cat; Top; Top]
| PrepNP(prep,Case case) -> Tensor[Atom "prepnp"; Atom cat; Atom prep; Atom case]
| AdjP(Case case) -> Tensor[Atom "adjp"; Atom cat; Top; Atom case; Top]
(* | AdjP NomAgr -> Tensor[Atom "adjp"; AVar "number"; Atom "nom"; AVar "gender"]*)
| AdjP AllAgr -> Tensor[Atom "adjp"; Atom cat; AVar "number"; AVar "case"; AVar "gender"]
(* | AdjP CaseAgr -> Tensor[Atom "adjp"; Top; AVar "case"; Top]
| PrepAdjP("",CaseUndef) -> Tensor[Atom "prepnp"; Top; Top]*)
| PrepAdjP(prep,Case case) -> Tensor[Atom "prepadjp"; Atom cat; Atom prep; Atom case]
(* | NumP(Case case) -> Tensor[Atom "nump"; Top; Atom case; Top; Top]
| NumP NomAgr -> Tensor[Atom "nump"; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
| NumP CaseAgr -> Tensor[Atom "nump"; Top; AVar "case"; Top; Top]
| NumP CaseUndef -> Tensor[Atom "nump"; Top; Top; Top; Top]
| PrepNumP(_,"",CaseUndef) -> Tensor[Atom "prepnp"; Top; Top]
| PrepNumP(_,prep,Case case) -> Tensor[Atom "prepnump"; Atom prep; Atom case] *)
(* | ComprepNP("") -> Tensor[Atom "comprepnp"; Top]*)
| ComprepNP(prep) -> Tensor[Atom "comprepnp"; Atom cat; Atom prep]
| ComparP(prep,Case case) -> Tensor[Atom "compar"; Atom cat; Atom prep; Atom case]
(* | ComparPP(_,prep) -> Tensor[Atom "comparpp"; Atom prep] *)
(* | IP -> Tensor[Atom "ip";Top;Top;Top] *)
| CP (ctype,Comp comp) -> Tensor[Atom "cp"; Atom cat; arg_of_ctype ctype; Atom comp]
(* | CP (ctype,CompUndef) -> Tensor[Atom "cp"; arg_of_ctype ctype; Top]*)
| NCP(Case case,ctype,Comp comp) -> Tensor[Atom "ncp"; Atom cat; Top; Atom case; Top; Top; arg_of_ctype ctype; Atom comp]
| NCP(Case case,CompTypeUndef,CompUndef) -> Tensor[Atom "ncp"; Atom cat; Top; Atom case; Top; Top; Top; Top]
| NCP(NomAgr,ctype,Comp comp) -> Tensor[Atom "ncp"; Atom cat; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"; arg_of_ctype ctype; Atom comp]
| NCP(NomAgr,CompTypeUndef,CompUndef) -> Tensor[Atom "ncp"; Atom cat; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"; Top; Top]
| PrepNCP(prep,Case case,ctype,Comp comp) -> Tensor[Atom "prepncp"; Atom cat; Atom prep; Atom case; arg_of_ctype ctype; Atom comp]
| PrepNCP(prep,Case case,CompTypeUndef,CompUndef) -> Tensor[Atom "prepncp"; Atom cat; Atom prep; Atom case; Top; Top]
| InfP(Aspect aspect) -> Tensor[Atom "infp"; Atom cat; Atom aspect]
| InfP AspectUndef -> Tensor[Atom "infp"; Atom cat; Top]
(* | PadvP -> Tensor[Atom "padvp"] *)
| AdvP "misc" -> Tensor[Atom "advp"; Atom cat; Top] (* FIXME: a może Atom "mod" zamiast Top *)
| AdvP mode -> Tensor[Atom "advp"; Atom cat; Atom mode]
| ColonP -> Tensor[Atom "colonp"; Atom cat]
(* | PrepP -> Tensor[Atom "prepp";Top]
| Prep("",CaseAgr) -> Tensor[Atom "prep"; Top; AVar "case"]
| Prep("",CaseUAgr) -> Tensor[Atom "prep"; Top; AVar "ucase"]
| Num(AllAgr,Acm acm) -> Tensor[Atom "num"; AVar "number"; AVar "case"; AVar "gender"; AVar "person"; Atom acm]
| Measure(AllUAgr) -> Tensor[Atom "measure"; AVar "unumber"; AVar "ucase"; AVar "ugender"; AVar "uperson"] *)
(* | Qub -> Tensor[Atom "qub"]*)
(* | Inclusion -> Tensor[Atom "inclusion"]
| Adja -> Tensor[Atom "adja"]
| Aglt -> Tensor[Atom "aglt"; AVar "number"; AVar "person"]
| AuxPast -> Tensor[Atom "aux-past"; AVar "number"; AVar "gender"; AVar "person"]
| AuxFut -> Tensor[Atom "aux-fut"; AVar "number"; AVar "gender"; AVar "person"]
| AuxImp -> Tensor[Atom "aux-imp"]
| Pro -> One
| ProNG -> One *)
| E (CP(CompTypeUndef,CompUndef)) -> Tensor[Atom "cp"; Atom cat; Top; Top]
| E (NCP(NomAgr,CompTypeUndef,CompUndef)) -> Tensor[Atom "ncp"; Atom cat; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"; Top; Top]
| E (NP(NomAgr)) -> Tensor[Atom "np"; Atom cat; AVar "number"; Atom "nom"; AVar "gender"; AVar "person"]
| E (PrepNP(prep,Case case)) -> Tensor[Atom "prepnp"; Atom cat; Atom prep; Atom case]
| E (NP(Case case)) -> Tensor[Atom "np"; Atom cat; Top; Atom case; Top; Top]
| E (NCP(Case case,CompTypeUndef,CompUndef)) -> Tensor[Atom "ncp"; Atom cat; Top; Atom case; Top; Top; Top; Top]
| E (PrepNCP(prep,Case case,CompTypeUndef,CompUndef)) -> Tensor[Atom "prepncp"; Atom cat; Atom prep; Atom case; Top; Top]
| phrase -> failwith ("render_phrase_cat: " ^ ENIAMwalStringOf.phrase phrase)
let render_morf = function
| Null -> One
(* | X -> Tensor[Atom "X"]
| Lex lex -> Tensor[Atom lex] *)
| LexArg(id,lex,pos) -> Tensor([Atom "lex";Atom (string_of_int id);Atom lex] @ render_pos pos)
| SimpleLexArg(lex,pos) -> Tensor([Atom "lex";Atom lex] @ render_pos pos)
| phrase -> render_phrase phrase
let render_morf_cat cats = function
| Null -> [One]
| Pro -> [One]
| ProNG -> [One]
| FixedP lex -> [Tensor[Atom "fixed"; Atom lex]]
| Or -> [Tensor[Atom "or"]]
| E Or -> [Tensor[Atom "or"]]
(* | X -> Tensor[Atom "X"]
| Lex lex -> Tensor[Atom lex] *)
| LexArg(id,lex,pos) -> [Tensor([Atom "lex";Atom (string_of_int id);Atom lex] @ render_pos pos)]
| SimpleLexArg(lex,pos) -> [Tensor([Atom "lex";Atom lex] @ render_pos pos)]
| phrase -> Xlist.map cats (fun cat -> render_phrase_cat cat phrase)
let extract_sel_prefs sel_prefs =
Xlist.map sel_prefs (function
SynsetName s -> s
| _ -> failwith "extract_sel_prefs")
let render_schema schema =
Xlist.map schema (fun p ->
match Xlist.map p.morfs render_morf with
[] -> failwith "render_schema"
| [s] -> Both,s
| l -> Both,Plus l)
let render_schema_cat schema =
Xlist.map schema (fun p ->
match List.flatten (Xlist.map p.morfs (render_morf_cat (extract_sel_prefs p.sel_prefs))) with
[] -> failwith "render_schema"
| [s] -> Both,s
| l -> Both,Plus l)
let render_simple_schema schema =
Xlist.map schema (fun morfs ->
Both,Plus(One :: Xlist.map morfs render_morf))
let render_connected_schema schema =
Xlist.map schema (fun p ->
{p with morfs=Xlist.map p.morfs (fun morf -> LCG (render_morf morf))})
let render_connected_schema_cat schema =
Xlist.map schema (fun p ->
{p with morfs=Xlist.map (List.flatten (Xlist.map p.morfs (render_morf_cat (extract_sel_prefs p.sel_prefs)))) (fun morf -> LCG morf)})
(* FIXME: tu trzeba by dodać zwykłe reguły dla czasowników dotyczące ich negacji, aglutynatu itp. *)
let render_lex_entry = function
SimpleLexEntry(lemma,pos) -> Tensor([Atom "lex";Atom lemma] @ render_pos_entry pos)
| LexEntry(id,lemma,pos,NoRestr,schema) ->
ImpSet(Tensor([Atom "lex";Atom (string_of_int id);Atom lemma] @ render_pos_entry pos),render_schema schema)
(*Xlist.map (transform_entry pos lemma NegationUndef PredFalse AspectUndef schema) (fun (sel,schema) ->
sel,LexEntry(id,lemma,pos,NoRestr,schema))*)
| ComprepNPEntry(prep,NoRestr,schema) -> ImpSet(Tensor[Atom "comprepnp"; Atom prep],render_schema schema)
(*Xlist.map (transform_entry "comprep" s NegationUndef PredFalse AspectUndef schema) (fun (sel,schema) ->
sel,ComprepNPEntry(s,NoRestr,schema))*)
| LexEntry(id,lemma,pos,_,[]) (*as entry*) ->
ImpSet(Tensor([Atom "lex";Atom (string_of_int id);Atom lemma] @ render_pos_entry pos),[Both,Tensor[AVar "schema"]])
| entry -> failwith ("render_entry:" ^ ENIAMwalStringOf.lex_entry entry)
(* let schemata,entries = ENIAMvalence.prepare_all_valence ENIAMwalParser.phrases ENIAMwalParser.schemata ENIAMwalParser.entries *)
(* let _ =
(* Entries.map schemata (fun pos lemma (selectors,schema) ->
(* Printf.printf "%s %s %s\n" pos lemma (ENIAMwalStringOf.schema schema); *)
render_schema schema) *)
Entries.map entries (fun pos lemma (selectors,entry) ->
(* Printf.printf "%s %s %s\n" pos lemma (ENIAMwalStringOf.schema schema); *)
selectors,render_lex_entry entry) *)
let adjunct morfs = {empty_position with gf=ADJUNCT; is_necessary=Opt; morfs=Xlist.map morfs (fun morf -> LCG morf)}
let adjunct_multi dir morfs = {empty_position with gf=ADJUNCT; is_necessary=Multi; dir=dir; morfs=Xlist.map morfs (fun morf -> LCG morf)}
let adjunct_dir dir morfs = {empty_position with gf=ADJUNCT; is_necessary=Opt; dir=dir; morfs=Xlist.map morfs (fun morf -> LCG morf)}
let adjunct_ce ce morfs = {empty_position with gf=ADJUNCT; ce=[ce]; is_necessary=Opt; morfs=Xlist.map morfs (fun morf -> LCG morf)}
let render_comprep prep = Both,Plus[One;Tensor[Atom "comprepnp"; Atom prep]]
let render_connected_comprep prep = adjunct [Tensor[Atom "comprepnp"; Atom prep]]
let render_prepnp prep cases =
Both,Plus(One :: List.flatten (Xlist.map cases (fun case ->
[Tensor[Atom "prepnp"; Atom prep; Atom case];
Tensor[Atom "prepncp"; Atom prep; Atom case; Top; Top]])))
let render_connected_prepnp prep cases =
adjunct (List.flatten (Xlist.map cases (fun case ->
[Tensor[Atom "prepnp"; Atom prep; Atom case];
Tensor[Atom "prepncp"; Atom prep; Atom case; Top; Top]])))
let render_prepadjp prep cases =
let postp = if prep = "z" || prep = "po" || prep = "na" then [Tensor[Atom "prepadjp"; Atom prep; Atom "postp"]] else [] in
Both,Plus(One :: postp @ (Xlist.map cases (fun case ->
Tensor[Atom "prepadjp"; Atom prep; Atom case])))
let render_connected_prepadjp prep cases =
let postp = if prep = "z" || prep = "po" || prep = "na" then [Tensor[Atom "prepadjp"; Atom prep; Atom "postp"]] else [] in
adjunct (postp @ (Xlist.map cases (fun case ->
Tensor[Atom "prepadjp"; Atom prep; Atom case])))
let render_compar prep = Both,Plus[One;Tensor[Atom "compar"; Atom prep; Top]]
let render_connected_compar prep = adjunct [Tensor[Atom "compar"; Atom prep; Top]]
let verb_adjuncts_simp = [
Both, Plus[One;Tensor[Atom "advp"; Atom "pron"]];
Both, Plus[One;Tensor[Atom "advp"; Atom "locat"]];
Both, Plus[One;Tensor[Atom "advp"; Atom "abl"]];
Both, Plus[One;Tensor[Atom "advp"; Atom "adl"]];
Both, Plus[One;Tensor[Atom "advp"; Atom "perl"]];
Both, Plus[One;Tensor[Atom "advp"; Atom "temp"]];
Both, Plus[One;Tensor[Atom "advp"; Atom "dur"]];
Both, Plus[One;Tensor[Atom "advp"; Atom "mod"]];
Both, Plus[One;Tensor[Atom "np";Top;Atom "dat"; Top; Top];Tensor[Atom "ncp"; Top; Atom "dat"; Top; Top; Top; Top]];
Both, Plus[One;Tensor[Atom "np";Top;Atom "inst"; Top; Top];Tensor[Atom "ncp"; Top; Atom "inst"; Top; Top; Top; Top]];
Both, Plus[One;Tensor[Atom "date"];Tensor[Atom "day-lex"];Tensor[Atom "day-month"];Tensor[Atom "day"]];
Forward, Plus[One;Tensor[Atom "cp";Top; Top]]; (* FIXME: to powinno być jako ostatnia lista argumentów *)
Both, Plus[One;Tensor[Atom "or"]];
Both, Plus[One;Tensor[Atom "lex";Atom "się";Atom "qub"]];
Both, Plus[One;Tensor[Atom "padvp"]];
]
let verb_connected_adjuncts_simp = [
adjunct [Tensor[Atom "advp"; Atom "pron"]];
adjunct [Tensor[Atom "advp"; Atom "locat"]];
adjunct [Tensor[Atom "advp"; Atom "abl"]];
adjunct [Tensor[Atom "advp"; Atom "adl"]];
adjunct [Tensor[Atom "advp"; Atom "perl"]];
adjunct [Tensor[Atom "advp"; Atom "temp"]];
adjunct [Tensor[Atom "advp"; Atom "dur"]];
adjunct [Tensor[Atom "advp"; Atom "mod"]];
adjunct [Tensor[Atom "np";Top;Atom "dat"; Top; Top];Tensor[Atom "ncp"; Top; Atom "dat"; Top; Top; Top; Top]];
adjunct [Tensor[Atom "np";Top;Atom "inst"; Top; Top];Tensor[Atom "ncp"; Top; Atom "inst"; Top; Top; Top; Top]];
adjunct [Tensor[Atom "date"];Tensor[Atom "day-lex"];Tensor[Atom "day-month"];Tensor[Atom "day"]];
adjunct_dir Forward_ [Tensor[Atom "cp";Top; Top]];
adjunct [Tensor[Atom "or"]];
adjunct [Tensor[Atom "lex";Atom "się";Atom "qub"]];
adjunct_ce "3" [Tensor[Atom "padvp"]];
]
let proper_noun_adjuncts_simp = [
Both, Plus[One;Tensor[Atom "np";Top;Atom "gen"; Top; Top];Tensor[Atom "ncp"; Top; Atom "gen"; Top; Top; Top; Top]];
Forward, Plus[One;Tensor[Atom "np";Top;Atom "nom"; Top; Top];Tensor[Atom "np";Top;AVar "case"; Top; Top]];
Backward, Maybe(Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]);
Forward, Plus[One;Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
]
let proper_noun_connected_adjuncts_simp = [
adjunct [Tensor[Atom "np";Top;Atom "gen"; Top; Top];Tensor[Atom "ncp"; Top; Atom "gen"; Top; Top; Top; Top]];
adjunct_dir Forward_ [Tensor[Atom "np";Top;Atom "nom"; Top; Top];Tensor[Atom "np";Top;AVar "case"; Top; Top]];
adjunct_multi Backward_ [Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
adjunct_dir Forward_ [Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
]
let common_noun_adjuncts_simp = [
Both, Plus[One;Tensor[Atom "np";Top;Atom "gen"; Top; Top];Tensor[Atom "ncp"; Top; Atom "gen"; Top; Top; Top; Top]];
Forward, Plus[One;Tensor[Atom "np";Top;Atom "nom"; Top; Top];Tensor[Atom "np";Top;AVar "case"; Top; Top]];
Backward, Maybe(Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]);
Forward, Plus[One;Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
]
let common_noun_connected_adjuncts_simp = [
adjunct [Tensor[Atom "np";Top;Atom "gen"; Top; Top];Tensor[Atom "ncp"; Top; Atom "gen"; Top; Top; Top; Top]];
adjunct_dir Forward_ [Tensor[Atom "np";Top;Atom "nom"; Top; Top];Tensor[Atom "np";Top;AVar "case"; Top; Top]];
adjunct_multi Backward_ [Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
adjunct_dir Forward_ [Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
]
let measure_noun_adjuncts_simp = [
Backward, Maybe(Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]);
Forward, Plus[One;Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
]
let measure_noun_connected_adjuncts_simp = [
adjunct_multi Backward_ [Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
adjunct_dir Forward_ [Tensor[Atom "adjp"; AVar "number"; AVar "case"; AVar "gender"]];
]
let adj_adjuncts_simp = [
Both, Plus[One;Tensor[Atom "advp"; Top]];
]
let adj_connected_adjuncts_simp = [
adjunct [Tensor[Atom "advp"; Top]];
]
let adv_adjuncts_simp = [
Both, Plus[One;Tensor[Atom "advp"; Top]];
]
let adv_connected_adjuncts_simp = [
adjunct [Tensor[Atom "advp"; Top]];
]
let assing_prep_morfs = function
"po","postp" -> [
LCG(Tensor[Atom "adjp"; Atom "sg"; Atom "dat"; Atom "m1"]);
LCG(Tensor[Atom "adjp"; Top; Atom "postp"; Top])]
| "z","postp" -> [LCG(Tensor[Atom "adjp"; Atom "sg"; Atom "nom"; Atom "f"])]
| "na","postp" -> [LCG(Tensor[Atom "advp"; Top])]
| _,case -> [
LCG(Tensor[Atom "np"; Top; Atom case; Top; Top]);
LCG(Tensor[Atom "adjp"; Top; Atom case; Top])]
let prep_morfs = [
LCG(Tensor[Atom "np"; Top; Atom "case"; Top; Top]);
LCG(Tensor[Atom "adjp"; Top; Atom "case"; Top]);
LCG(Tensor[Atom "adjp"; Atom "sg"; Atom "dat"; Atom "m1"]);
LCG(Tensor[Atom "adjp"; Atom "sg"; Atom "nom"; Atom "f"]);
LCG(Tensor[Atom "advp"; Top]);
LCG(Tensor[Atom "year"]);
LCG(Tensor[Atom "hour-minute"]);
LCG(Tensor[Atom "day-month"]);
LCG(Tensor[Atom "hour"]);
LCG(Tensor[Atom "day"]);
LCG(Tensor[Atom "date"]);
]
let compar_morfs = [
LCG(Tensor[Atom "np"; Top; Atom "case"; Top; Top]);
LCG(Tensor[Atom "adjp"; Top; Atom "case"; Top]);
LCG(Tensor[Atom "prepnp"; Top; Top]);
LCG(Tensor[Atom "prepadjp"; Top; Top]);
]