-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmt.tdl
376 lines (321 loc) · 11.7 KB
/
tmt.tdl
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
;;; -*- Mode: tdl; Coding: utf-8; -*-
;;;
;;; Copyright (c) 2009 -- 2012 Stephan Oepen (oe@ifi.uio.no);
;;; Copyright (c) 2009 -- 2011 Dan Flickinger (danf@stanford.edu); (ERG)
;;; Copyright (c) 2012 Francis Bond (bond@ieee.org); (Jacy)
;;; Copyright (c) 2014 -- NTU Computational Linguistics Lab; (Zhong)
;;; modified by Sanghoun Song (sanghoun@ntu.edu.sg, 2014-11-24)
;;; see `LICENSE' for conditions.
;;;
relation :+
[ CFROM *top*,
CTO *top* ].
;word :+
lex-item :+
"""
This links the CFROM and CTO to the position in the orthography.
OZ 15-Nov-2022: I am taking out CTO and CFROM constraints for now
because they break compilation.
"""
[ TRAITS #traits,
STEM [ FROM #from,
TO #to ],
;SYNSEM.LKEYS.KEYREL [ CFROM #from,
; CTO #to ],
;SYNSEM.LKEYS.ALTKEYREL [ CFROM #from,
; CTO #to ],
TOKENS tokens &
[ +LIST #traits &
[ FIRST.+FROM #from ],
+LAST.+TO #to ] ].
word-or-lexrule :+
[ TRAITS list ].
lex-rule :+
[ TRAITS #traits,
STEM.TO #to,
DTR [ TRAITS #traits,
STEM.TO #to ] ].
tmt-lex-rule := basic-lex-rule &
[ TRAITS #traits,
STEM.TO #to,
DTR [ TRAITS #traits,
STEM.TO #to ] ].
phrase-or-lexrule :+
[ STEM.FROM #from,
ARGS.FIRST.STEM.FROM #from ].
basic-unary-phrase :+
[ STEM.TO #to,
ARGS.FIRST.STEM.TO #to ].
basic-binary-phrase :+
[ STEM.TO #to,
ARGS.REST.FIRST.STEM.TO #to ].
;;; SSH 2014-11-24: taken from Jacy
;;; for rules with only one thing in their C-CONT, link FROM/TO to CFROM/CTO
c-cont-1 := phrase-or-lexrule &
[ STEM [ FROM #from,
TO #to ],
C-CONT.RELS <! [ CFROM #from,
CTO #to ] !>].
c-cont-2 := phrase-or-lexrule &
[ STEM [ FROM #from,
TO #to ],
C-CONT.RELS <! [ CFROM #from,
CTO #to ],
[ CFROM #from,
CTO #to ] !>].
;================================================================================
; TOKENS
;================================================================================
; Currently only 'native_token_list' and 'generic_token_list' are actually being
; used by the grammar.
; However, EVERY SINGLE lexical entry is being marked as 'native_token_list'
; which seems a horrible waste of space and elegance.
;
; maybe we should create two types: 'generic-token-lex' and 'native-token-lex'
; and ambiguate things like 'v_trans-verb-lex' into two:
; 'v_trans-verb-lex' and 'v_trans-verb-gen-lex'
; and the same for every other thing.
;================================================================================
tokens := *top* &
[ +LIST list,
+LAST token ].
token_min := avm.
token := token_min &
[ +FORM string,
+CLASS token_class,
+TRAIT token_trait,
+PRED predsort,
+CARG string,
+ID diff-list,
+FROM string,
+TO string,
+POS pos ].
token_trait := sort.
anti_trait := token_trait.
native_trait := token_trait.
generic_trait := token_trait.
native_token_list := list.
native_token_cons := native_token_list & cons &
[ FIRST.+TRAIT native_trait, REST native_token_list ].
native_token_null := native_token_list & null.
generic_token_list := list.
generic_token_cons := generic_token_list & cons &
[ FIRST.+TRAIT generic_trait, REST generic_token_list ].
generic_token_null := generic_token_list & null.
pos := *top* &
[ +TAGS list,
+PRBS list ].
null_pos := pos &
[ +TAGS < >,
+PRBS < > ].
;;
;; in token mapping, it is useful to have available distinct `anti'-strings.
;;
anti_string := string.
non_string := string.
;;;
;;; orthographic classes, used in token mapping and lexical filtering
;;;
token_class := sort.
no_class := token_class.
named_entity := token_class.
proper_ne := named_entity.
file_ne := proper_ne.
url_ne := proper_ne.
email_ne := proper_ne.
phone_ne := proper_ne.
card_or_year_ne := named_entity.
card_or_dom_ne := named_entity.
card_or_time_ne := named_entity.
card_or_meas_ne := named_entity.
card_ne := card_or_year_ne & card_or_dom_ne & card_or_time_ne & card_or_meas_ne.
year_ne := card_or_year_ne.
ord_or_dom_ne := named_entity.
ord_ne := ord_or_dom_ne.
frct_ne := named_entity.
plur_ne := named_entity.
dom_card_ne := card_or_dom_ne.
dom_ord_ne := ord_or_dom_ne.
date_ne := named_entity.
meas_or_time_ne := named_entity.
time_ne := card_or_dom_ne & card_or_time_ne & meas_or_time_ne.
meas_ne := meas_or_time_ne & card_or_meas_ne.
meas_noun_ne := named_entity.
;;; FCB for things that are reduplicated
redup_le := token_class.
;; SSH 2015-04-13 七月 七日
month_ne := date_ne.
day_ne := date_ne.
;; SSH 2015-04-16
percent_ne := card_ne.
;;
;; the following are modeled after POSIX character classes; most have obvious
;; correspondences in terms of (more elaborate) UniCode character properties.
;; essentially, we cross-classify along three dimensions: (a) the combination
;; of characters used, (b) whether or not the first character is capitalized,
;; and (c) whether or not a token appears utterance-initial.
;;
non_ne := token_class &
[ +INITIAL luk ].
non_alphanumeric := non_ne.
apostrophe := non_alphanumeric.
anti_apostrophe := non_alphanumeric.
alphanumeric := non_ne &
[ +CASE token_case ].
alphabetic := alphanumeric.
numeric := alphanumeric.
;;
;; in parsing partially bracketed inputs, we introduce special-purpose bracket
;; tokens, e.g. |the ¦[0 parking lot 0]¦ attendant arrived.| these are parsed
;; in token mapping, using a custom +CLASS value.
;;
bracket := non_ne &
[ +COUNT string ].
left_bracket := bracket.
right_bracket := bracket.
;;
;; at least the fourth time that i revise this hierarchy. `capitalized' or not
;; is a property of the first character (|1A| is not capitalized). `mixed', on
;; the other hand, is only applicable to tokens with at least two characters.
;; both |aB| and |AbC| are mixed, but |A| or |a| are not. finally, `lower' and
;; `upper' reflect the full token string, i.e. |Dan| is neither, |1a| is lower,
;; and |A| is upper.
;;
token_case := sort.
capitalized := token_case.
non_capitalized := token_case.
mixed := token_case.
non_mixed := token_case.
capitalized+mixed := capitalized & mixed.
capitalized+non_mixed := capitalized & non_mixed.
capitalized+lower := capitalized+non_mixed.
capitalized+upper := capitalized+non_mixed.
non_capitalized+mixed := non_capitalized & mixed.
;;
;; we are making a simplifying assumption here, not distinguishing one-token
;; non-capitalized (which could be called 'non_capitalized+non_mixed') from
;; 'non_capitalized+lower'. so far, we just never care about the distinction.
;;
non_capitalized+lower := non_capitalized & non_mixed.
chart_mapping_rule := *top* &
[ +CONTEXT list,
+INPUT list,
+OUTPUT list,
+POSITION string ].
;;;
;;; constructing a sensible hierarchy of token mapping rules is not trivial.
;;; there is variation among many dimensions: (a) arity of input and output,
;;; positioning of LHS and RHS rule elements, (c) which token properties are
;;; copied over, and others.
;;;
;;; following is an attempt to sketch some of the more frequent configurations,
;;; but so far there is hardly any use of inheritance here ...
;;;
token_mapping_rule := chart_mapping_rule.
one_one_tmt := token_mapping_rule &
[ +INPUT < [ +ID #id, +FROM #from, +TO #to ] >,
+OUTPUT < [ +ID #id, +FROM #from, +TO #to ] >,
+POSITION "O1@I1" ].
two_one_tmt := token_mapping_rule &
[ +INPUT < [ +ID [ LIST #front, LAST #middle ], +FROM #from ],
[ +ID [ LIST #middle, LAST #back ], +TO #to ] >,
+OUTPUT < [ +ID [ LIST #front, LAST #back ], +FROM #from, +TO #to ] >,
+POSITION "I1<I2, O1@I1, O1@I2" ].
three_one_tmt := token_mapping_rule &
[ +INPUT < [ +ID [ LIST #front, LAST #fmiddle ], +FROM #from ],
[ +ID [ LIST #fmiddle, LAST #bmiddle ] ],
[ +ID [ LIST #bmiddle, LAST #back ], +TO #to ] >,
+OUTPUT < [ +ID [ LIST #front, LAST #back ], +FROM #from, +TO #to ] >,
+POSITION "I1<I2<I3, O1@I1, O1@I2, O1@I3" ].
one_two_tmt := token_mapping_rule &
[ +INPUT < [ +ID #id, +FROM #from, +TO #to ] >,
+OUTPUT < [ +ID #id, +FROM #from, +TO #to ],
[ +ID #id, +FROM #from, +TO #to ] >,
+POSITION "O1<O2, I1@O1, I1@O2" ].
one_three_tmt := token_mapping_rule &
[ +INPUT < [ +ID #id, +FROM #from, +TO #to ] >,
+OUTPUT < [ +ID #id, +FROM #from, +TO #to ],
[ +ID #id, +FROM #from, +TO #to ],
[ +ID #id, +FROM #from, +TO #to ] >,
+POSITION "O1<O2<O3, I1@O1, I1@O2, I1@O3" ].
one_one_form_tmt := one_one_tmt &
[ +INPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] >,
+OUTPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] > ].
one_one_pos_tmt := one_one_tmt &
[ +INPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +FORM #form ] >,
+OUTPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +FORM #form ] > ].
two_one_initial_form_tmt := two_one_tmt &
[ +INPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ],
[ ] >,
+OUTPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] > ].
two_one_final_form_tmt := two_one_tmt &
[ +INPUT < [ ],
[ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] >,
+OUTPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] > ].
three_one_center_form_tmt := three_one_tmt &
[ +INPUT < [ ],
[ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ],
[ ] >,
+OUTPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] > ].
three_one_final_form_tmt := three_one_tmt &
[ +INPUT < [ ],
[ ],
[ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] >,
+OUTPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] > ].
one_two_all_form_tmt := one_two_tmt &
[ +INPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] >,
+OUTPUT < [ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ],
[ +TRAIT #trait, +CLASS #class,
+PRED #pred, +CARG #carg, +POS #pos ] > ].
;;;
;;; a few relatively specialized token mapping rule types, for configurations
;;; that are instantiated with non-trivial frequency.
;;;
token_class_tmt := one_one_tmt &
[ +INPUT < [ +FORM #form, +TRAIT #trait, +CLASS no_class,
+PRED #pred, +CARG #carg, +POS #pos ] >,
+OUTPUT < [ +FORM #form, +TRAIT #trait, +CLASS non_ne,
+PRED #pred, +CARG #carg, +POS #pos ] > ].
token_case_tmt := token_mapping_rule &
[ +INPUT < [ +FORM #form, +TRAIT #trait, +CLASS #class,
+PRED #pred, +POS #pos ] >,
+OUTPUT < [ +FORM #form, +TRAIT #trait, +CLASS #class,
+PRED #pred, +POS #pos ] > ].
one_one_token_case_tmt := one_one_tmt & token_case_tmt.
;;
;; _fix_me_
;; the NE rules force [ +TRAIT generic_trait ], to prevent NE tokens activating a
;; native entry. there are some digits in the lexicon, hence `4 chairs' could
;; in principle get two analyses. but i see no reason why we should want that?
;; (26-sep-08; oe)
ne_tmt := one_one_tmt &
[ +INPUT < [ +FORM #form, +CLASS non_ne,
+PRED #pred, +CARG #carg ] >,
+OUTPUT < [ +FORM #form, +TRAIT generic_trait, +CLASS named_entity,
+PRED #pred, +CARG #carg, +POS null_pos ] > ].
add_ne_tmt := token_mapping_rule &
[ +CONTEXT < [ +FORM #form, +CLASS non_ne,
+PRED #pred, +CARG #carg,
+ID #id, +FROM #from, +TO #to ] >,
+OUTPUT < [ +FORM #form, +TRAIT generic_trait, +CLASS named_entity,
+PRED #pred, +CARG #carg,
+ID #id, +FROM #from, +TO #to, +POS null_pos ] >,
+POSITION "O1@C1" ].
;;;
;;; lexical filtering rules; not much use of the type hierarchy yet
;;;
lexical_filtering_rule := chart_mapping_rule.