-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema-postproc-ttt-rules.lisp
388 lines (336 loc) · 6.35 KB
/
schema-postproc-ttt-rules.lisp
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
(load "ll-load.lisp")
(ll-load "ll-util.lisp")
(ll-load "schema-postproc-utils.lisp")
(defun implicature? (x)
(contains '(
BEGIN.V
START.V
DECIDE.V
) x)
)
(defparameter *SCHEMA-CLEANUP-RULES* (curry-ttt-rules '(
; The case with only one argument
; (/ (KA (L _!1 (_!1 _!2)))
; (KA _!2))
; The case with unbracketed serial arguments
; (/ (KA (L _!1 (_!1 _!2 _+3)))
; (KA _!2 _+3))
; NOT.ADV, with or without index tags, should
; just be NOT.
(/
(ll-curry eq-no-idx-tags? NOT.ADV)
NOT
)
; Get rid of monadic lambda predicates.
(/ (_*1 (L _!.2 (_!.2 _+3)) _*4)
(_*1 (_+3) _*4)
)
; Fix wrongly reified THAT.P
(/
(K (THAT.P _*1))
(THAT _*1)
)
; Split out conjoined verb predications w/
; the same subject, and fix their "nested"
; episode characterizations.
(/
(_*6 (( ((_!. _+2) AND.CC (_!. _+3)) [**] _!4) [**] _!5) _*7)
(_*6 ((_!. _+2) ** _!5) ((_!. _+3) ** _!4) _*7)
)
; Kill :O
(/
(:O _+)
(_+)
)
; Fix weird DO.V
(/
(pred-vp? mono-lam? _*)
(DO.V _*)
)
; s/TO/KA/g
(/
TO
KA
)
; N'T is NOT
(/
|N'T.ADV|
NOT
)
; N'T with explicit bars is also NOT
; (I'm not sure why this happens)
(/
|\|N'T.ADV\||
NOT
)
; :R can just be ADV-A
(/
(:R _+)
(ADV-A _+)
)
; Strip narrative structures
(/
((SPEAKER TELL.V HEARER (THAT _!1)) [**] _!2)
; (_!1 [**] _!2)
_!1
)
; Flatten lists of modifiers to float,
; so they can be unfloated by another
; rule.
(/
(_*1 ((!2 canon-mod?) (+ canon-mod?)) _*3)
(_*1 !2 + _*3)
)
; Turn parallel kind and PP arguments inside PP
; phrases into a valid, conjunctive construction,
; e.g.,
; (in.p ((k front.n) (of.p billy.name)))
; becomes
; (in.p (k (l x (and (x front.n) (x (of.p billy.name))))))
(/
((!1 lex-p?) ((K (!2 canon-pred?)) (!3 canon-prep?)))
(!1 (K (lambdify-preds! (!2 !3))))
)
; Strip unnecessary parens from predicates.
(/
((!1 canon-pred?))
!1
)
; Un-flatten stacked predicates.
(/
((* ~ AND.CC) ((+ nonverb-pred?)))
(* (lambdify-preds! (+)))
)
(/
((* ~ AND) ((+ nonverb-pred?)))
(* (lambdify-preds! (+)))
)
; CAN should usually be CAN.MD.
(/
CAN
CAN.MD
)
; We prefer MDs in this family
(/
WILL.AUX
WILL.MD
)
; Floating prepositions in verb predicates should be mods.
(/
(_*1 (!2 canon-pred?) _*3 (!4 canon-prep?) _*5)
(_*1 ((adv-a !4) !2) _*3 _*5)
)
(/
(_*1 (!2 canon-prep?) _*3 (!4 canon-pred?) _*5)
(_*1 ((adv-a !2) !4) _*3 _*5)
)
; Naked predicates as PP objects should be
; reified, for lack of anything else to do.
(/
((!1 lex-p?) (!2 verb-pred?))
(!1 (KA !2))
)
(/
((!1 lex-p?) (!2 canon-pred?))
(!1 (K !2))
)
; We don't need "such", "so", etc.
; until we can figure out what to
; do with them. (TODO)
;(/
;(_*1 SUCH.D _*2)
;(_*1 _*2)
;)
; Un-flatten composite predicates.
(/
(<> (!2 canon-pred?) (+ canon-pred?))
(lambdify-preds! (!2 +))
)
; Lambdify conjunctive predicates.
(/
(AND (+ canon-pred?))
(lambdify-preds! (+))
)
(/
(AND.CC (+ canon-pred?))
(lambdify-preds! (+))
)
; Conjunctions of individuals are
; actually sets.
(/
(AND (+ canon-individual?))
(SET-OF +)
)
(/
((!1 canon-individual?) AND (!2 canon-individual?))
(SET-OF !1 !2)
)
(/
((!1 canon-individual?) AND.CC (!2 canon-individual?))
(SET-OF !1 !2)
)
; Unwrap singleton individual lists.
(/
((!1 canon-individual?))
!1
)
; Unwrap singleton propositions.
(/
((!1 canon-prop?))
!1
)
; Stacked lex-preds can be split like conjunctions,
; for now, BUT, TODO:
; 1. make them proper predicate modifiers
; 2. figure out if/when it's OK to do this with
; composite, non-lexical preds?
(/
((!1 canon-individual?) (+ lex-pred?))
(!1 (AND (+)))
)
; Auxiliary "be" can always be a copula,
; for now (Gene says it's OK!). Change when
; Len adds aux-identification back into parser.
(/
; BE.AUX
; BE.V
(!1 be-aux?)
(verbify! !1)
)
; Auxiliary "have" without a verb predicate
; after it can be a verb.
(/
(_*1 (!2 have-aux?) (!3 ~ verb-pred?))
(_*1 (verbify! !2) !3)
)
; To BE.V, or not to BE.V?
(/
; ((!1 ~ THERE.PRO) ((!2 be-verb?) (!3 probably-pred?)))
((!1 ~ (ll-curry equal? THERE.PRO)) ((!2 be-verb?) (!3 probably-pred?)))
(!1 !3)
)
; comma-and becomes and
(/
(_*1 (!2 is-comma?) AND _*3)
(_*1 AND _*3)
)
; "There is X" => "X is"
(/
(THERE.PRO ((!1 be-verb?) (= _!2)))
(_!2 !1)
)
; Fix non-auxiliary HAVE.AUX
(/
(HAVE.AUX (!1 ~ canon-ka?))
(HAVE.V !1)
)
; Fix weird type-shifters
(/
(!1 modif-advp?)
ADV-A
)
; HAVE.V with ADV-A TO.P KA
; should be MUST.AUX
(/
((ADV-A (FOR.P (KA _*1))) HAVE.V)
(MUST.AUX-S _*1)
)
; Skolem-name pairs should take
; an NP+PREDS form to be fixed
; by a Lisp rule.
(/
((!1 lex-skolem?) (!2 lex-name?))
(NP+PREDS !1 (= !2))
)
; Kill PRED****.VP
;(/
; ((!1 vp-shifter?) _+)
; (_+)
;)
; Unflatten post-args
(/
((!1 canon-individual?) (!2 canon-pred?) (+ canon-individual?))
(!1 (!2 +))
)
; Remove progressive indicators
(/
((<> prog _*1 (!2 canon-pred?)))
(_*1 !2)
)
; "Get <adj>" is valid, but kind-ify the adjective?
(/
(GET.V (!1 adj-pred?))
(GET.V (KJ !1))
)
; Strip out some coordinating conjunctions.
(/
(_*1 (!1 (ll-curry eq-no-idx-tags? BUT.CC)) _*2)
(AND _*1 _*2)
)
(/
((!1 (ll-curry eq-no-idx-tags? SO.CC)) _*2)
(_*2)
)
; Strip off "decide to"
(/
(_*1 (implicature? (KA _*2)))
(_*1 _*2)
)
; Remove any commas left
(/
((<> _*1 (!2 is-comma?) _*2))
(_*1 _*2)
)
; Adverbs paired up with prep-preds,
; e.g. "(late.adv (at.p (k night.n)))",
; should be split up & have the prep-
; pred turned into an adverb as well.
(/
(_*1 ((!2 canon-adv?) (!3 canon-prep?)) _*4)
(_*1 !2 (ADV-A !3) _*4)
)
; (= (a.d pred)) should just be pred
(/
(_*1 (= ((ll-curry eq-no-idx-tags? a.d) (!2 canon-pred?))))
(_*1 !2)
)
; Noun "type" predications shouldn't be
; fluent.
(/
((_*1 (!2 noun-pred?)) [**] _!3)
(_*1 !2)
)
; Infix ANDs with probably-preds should be
; normalized to prefix AND lists.
(/
((!1 probably-pred?) AND (!2 probably-pred?))
(AND !1 !2)
)
(/
((!1 probably-pred?) AND.CC (!2 probably-pred?))
(AND !1 !2)
)
; *.PS -> *.P
(/
(!1 lex-ps?)
((ll-curry-imper retag-as "P") !1)
)
; Fix FIN modals
(/
(FIN WOULD.AUX)
WILL.MD
)
(/
(FIN COULD.AUX)
CAN.MD
)
(/
(FIN SHOULD.AUX)
SHOULD.MD
)
; Flatten post-arg lists
(/
((!1 canon-pred?) ((+ canon-individual?)))
(!1 +)
)
)))