forked from attapol/conll16st
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn_head_mapper.py
executable file
·400 lines (389 loc) · 11.4 KB
/
conn_head_mapper.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class ConnHeadMapper(object):
def __init__(self):
self.mapping = ConnHeadMapper.DEFAULT_MAPPING
def map_raw_connective(self, raw_connective):
if raw_connective in self.mapping:
head_connective = self.mapping[raw_connective]
else:
head_connective = self.mapping.get(raw_connective.lower(), raw_connective)
# find the index of the head connectives
raw_connective_token_list = [x for x in raw_connective.lower().split(' ') if len(x) > 0]
head_connective_token_list = [x for x in head_connective.split(' ') if len(x) > 0]
start_point = 0
indices = []
for head_connective_token in head_connective_token_list:
for i in range(start_point, len(raw_connective_token_list)):
token = raw_connective_token_list[i]
if head_connective_token == token or \
head_connective_token == self.mapping.get(token, token):
indices.append(i)
start_point = i+1
break
assert(len(head_connective_token_list) == len(indices))
return head_connective, indices
DEFAULT_MAPPING = {
"18 months after": "after",
"25 years after": "after",
"29 years and 11 months to the day after": "after",
"A few hours after": "after",
"About six months before": "before",
"Accordingly": "accordingly",
"Additionally": "additionally",
"After": "after",
"Afterward": "afterward",
"Afterwards": "afterward",
"Almost simultaneously": "simultaneously",
"Also": "also",
"Alternatively": "alternatively",
"Although": "although",
"And": "and",
"As": "as",
"As a result": "as a result",
"As an alternative": "as an alternative",
"As if": "as if",
"As long as": "as long as",
"As much as": "much as",
"As soon as": "as soon as",
"As well": "as well",
"At least not when": "when",
"At least when": "when",
"Back when": "when",
"Because": "because",
"Before": "before",
"Besides": "besides",
"But": "but",
"By comparison": "by comparison",
"By contrast": "by contrast",
"By then": "by then",
"Consequently": "consequently",
"Conversely": "conversely",
"Earlier": "earlier",
"Eight months after": "after",
"Either or": "either or",
"Even after": "after",
"Even as": "as",
"Even before": "before",
"Even if": "if",
"Even still": "still",
"Even then": "then",
"Even though": "though",
"Even when": "when",
"Even while": "while",
"Ever since": "since",
"Except": "except",
"Finally": "finally",
"Five minutes before": "before",
"For": "for",
"For example": "for example",
"For instance": "for instance",
"Further": "further",
"Furthermore": "furthermore",
"Hence": "hence",
"However": "however",
"IF": "if",
"If": "if",
"If only": "if",
"If then": "if then",
"In addition": "in addition",
"In contrast": "in contrast",
"In fact": "in fact",
"In other words": "in other words",
"In particular": "in particular",
"In short": "in short",
"In sum": "in sum",
"In the end": "in the end",
"In the first 25 minutes after": "after",
"In the meantime": "meantime",
"In the meanwhile": "meanwhile",
"Indeed": "indeed",
"Insofar as": "insofar as",
"Instead": "instead",
"Just after": "after",
"Just because": "because",
"Just five months after": "after",
"Just when": "when",
"Largely as a result": "as a result",
"Later": "later",
"Later on": "later",
"Likewise": "likewise",
"Meantime": "meantime",
"Meanwhile": "meanwhile",
"Months after": "after",
"Moreover": "moreover",
"Nearly two months after": "after",
"Nevertheless": "nevertheless",
"Next": "next",
"Nonetheless": "nonetheless",
"Nor": "nor",
"Now that": "now that",
"ONCE": "once",
"On the contrary": "on the contrary",
"On the one hand On the other hand": "on the one hand on the other hand",
"On the other hand": "on the other hand",
"Once": "once",
"One day after": "after",
"Only when": "when",
"Or": "or",
"Otherwise": "otherwise",
"Overall": "overall",
"Partly because": "because",
"Perhaps because": "because",
"Plus": "plus",
"Previously": "previously",
"Primarily because": "because",
"Rather": "rather",
"Regardless": "regardless",
"Separately": "separately",
"Shortly after": "after",
"Shortly afterwards": "afterward",
"Shortly before": "before",
"Shortly thereafter": "thereafter",
"Similarly": "similarly",
"Simultaneously": "simultaneously",
"Since": "since",
"So": "so",
"Soon after": "after",
"Specifically": "specifically",
"Still": "still",
"Then": "then",
"Thereafter": "thereafter",
"Therefore": "therefore",
"Though": "though",
"Three months after": "after",
"Thus": "thus",
"Two weeks after": "after",
"Ultimately": "ultimately",
"Unless": "unless",
"Until": "until",
"WHEN": "when",
"When": "when",
"When and if": "when and if",
"Whereas": "whereas",
"While": "while",
"Within minutes after": "after",
"Yet": "yet",
"a day after": "after",
"a day or two before": "before",
"a decade before": "before",
"a few months after": "after",
"a few weeks after": "after",
"a full five minutes before": "before",
"a month after": "after",
"a week after": "after",
"a week before": "before",
"a year after": "after",
"about a week after": "after",
"about three weeks after": "after",
"accordingly": "accordingly",
"additionally": "additionally",
"after": "after",
"afterward": "afterward",
"afterwards": "afterward",
"almost before": "before",
"almost immediately after": "after",
"also": "also",
"alternatively": "alternatively",
"although": "although",
"an average of six months before": "before",
"and": "and",
"apparently because": "because",
"as": "as",
"as a result": "as a result",
"as if": "as if",
"as long as": "as long as",
"as much as": "much as",
"as soon as": "as soon as",
"as though": "as though",
"as well": "as well",
"at least partly because": "because",
"at least until": "until",
"at least when": "when",
"because": "because",
"before": "before",
"before and after": "before and after",
"besides": "besides",
"but": "but",
"by comparison": "by comparison",
"by contrast": "by contrast",
"by then": "by then",
"consequently": "consequently",
"earlier": "earlier",
"either or": "either or",
"else": "else",
"especially after": "after",
"especially as": "as",
"especially because": "because",
"especially if": "if",
"especially since": "since",
"especially when": "when",
"even after": "after",
"even as": "as",
"even before": "before",
"even if": "if",
"even then": "then",
"even though": "though",
"even when": "when",
"even while": "while",
"ever since": "since",
"except": "except",
"except when": "when",
"finally": "finally",
"five years after": "after",
"for": "for",
"for example": "for example",
"for instance": "for instance",
"four days after": "after",
"fully eight months before": "before",
"further": "further",
"furthermore": "furthermore",
"hence": "hence",
"however": "however",
"if": "if",
"if and when": "if and when",
"if only": "if",
"if then": "if then",
"immediately after": "after",
"in addition": "in addition",
"in contrast": "in contrast",
"in fact": "in fact",
"in large part because": "because",
"in other words": "in other words",
"in part because": "because",
"in particular": "in particular",
"in the 3 1/2 years before": "before",
"in the end": "in the end",
"in the meantime": "meantime",
"in turn": "in turn",
"indeed": "indeed",
"instead": "instead",
"just 15 days after": "after",
"just a day after": "after",
"just a month after": "after",
"just after": "after",
"just as": "as",
"just as soon as": "as soon as",
"just because": "because",
"just before": "before",
"just days before": "before",
"just eight days before": "before",
"just minutes after": "after",
"just until": "until",
"just when": "when",
"largely because": "because",
"later": "later",
"later on": "later",
"less than a month after": "after",
"lest": "lest",
"likewise": "likewise",
"long after": "after",
"long before": "before",
"mainly because": "because",
"meanwhile": "meanwhile",
"merely because": "because",
"minutes after": "after",
"more than a year after": "after",
"moreover": "moreover",
"much as": "much as",
"nearly a year and a half after": "after",
"neither nor": "neither nor",
"nevertheless": "nevertheless",
"next": "next",
"nonetheless": "nonetheless",
"nor": "nor",
"not because": "because",
"not only because": "because",
"now that": "now that",
"on the other hand": "on the other hand",
"once": "once",
"one day after": "after",
"only after": "after",
"only as long as": "as long as",
"only because": "because",
"only if": "if",
"only three years after": "after",
"only two weeks after": "after",
"only until": "until",
"only when": "when",
"or": "or",
"otherwise": "otherwise",
"overall": "overall",
"particularly after": "after",
"particularly as": "as",
"particularly because": "because",
"particularly if": "if",
"particularly since": "since",
"particularly when": "when",
"partly because": "because",
"perhaps because": "because",
"presumably because": "because",
"previously": "previously",
"primarily because": "because",
"rather": "rather",
"regardless": "regardless",
"reportedly after": "after",
"right after": "after",
"separately": "separately",
"seven years after": "after",
"several months before": "before",
"shortly after": "after",
"shortly afterward": "afterward",
"shortly before": "before",
"shortly thereafter": "thereafter",
"similarly": "similarly",
"simply because": "because",
"simultaneously": "simultaneously",
"since": "since",
"since before": "before",
"six years after": "after",
"so": "so",
"so much as": "much as",
"so that": "so that",
"some time after": "after",
"sometimes after": "after",
"soon after": "after",
"specifically": "specifically",
"still": "still",
"then": "then",
"thereafter": "thereafter",
"thereby": "thereby",
"therefore": "therefore",
"though": "though",
"thus": "thus",
"till": "till",
"two days after": "after",
"two days before": "before",
"two months before": "before",
"two weeks after": "after",
"two years before": "before",
"typically, if": "if",
"ultimately": "ultimately",
"unless": "unless",
"until": "until",
"usually when": "when",
"when": "when",
"whereas": "whereas",
"while": "while",
"within a year after": "after",
"years after": "after",
"years before": "before",
"yet": "yet",
"Days after": "after",
"In stark contrast": "in contrast",
"hours before": "before",
"in the mean time": "in the mean time",
"particularly": "particularly",
"three years later": "later",
"upon": "upon"
}
if __name__ == '__main__':
chm = ConnHeadMapper()
raw_connective = "29 years and 11 months to the day after"
head_connective, indices = chm.map_raw_connective(raw_connective)
assert(head_connective == "after")
assert(indices == [8])
raw_connective = "Largely as a result"
head_connective, indices = chm.map_raw_connective(raw_connective)
assert(head_connective == "as a result")
assert(indices == [1, 2 ,3])