-
Notifications
You must be signed in to change notification settings - Fork 0
/
augment.py
533 lines (463 loc) · 33.1 KB
/
augment.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
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# /////////////// Replaces original words in the training file with random ones generated by the module 'generate'
# /////////////// augments the training file with the new sentences
import csv
import time
import os
import argparse
from tqdm import tqdm
from generate import mainG, mainGacc, mainGintern, mainGsupertag, lG, lGacc, lGIntern, info, color, tags
# //////////////////////////////////////////////////
def sentLengths(linesList, emptyList):
try:
for i in range(len(linesList)):
if len(linesList[i]) == 0:
count = linesList[i-1][0]
emptyList.append(count)
i += 1
#print(emptyList)
except(IndexError):
i += 1
# //////////////////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////////////////////
def checkVowels(i, lines):
try:
if lines[i][1].startswith(('a','A','e','E','i','I','o','O','u','U')) == True:
if lines[i-1][1] == 'a':
if 'OP-DEF <>' in lines[i-1][3]:
lines[i-1][1] = 'an'
if lines[i-1][1] == 'A':
if 'OP-DEF <>' in lines[i-1][3]:
lines[i-1][1] = 'An'
if lines[i][1].startswith(('a','A','e','E','i','I','o','O','u','U')) == False:
if lines[i-1][1] == 'an':
if 'OP-DEF <>' in lines[i-1][3]:
lines[i-1][1] = 'a'
if lines[i-1][1] == 'An':
if 'OP-DEF <>' in lines[i-1][3]:
lines[i-1][1] = 'A'
except(IndexError):
i += 1
# /////////////////////////////////////////////////////////////////////////////////////////////////////
if __name__ == '__main__':
# // commands //////////////////////////////////////////////////////////////////////////////////////////
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-h', '--help', help=info(), action='help')
parser.add_argument('--unimorph0', action='store_true', required=False, help='UniMorph Inaccurate verb replacements with regard to transitivity. In place of --unimorph1, --internal, --supertag, or --original.')
parser.add_argument('--unimorph1', action='store_true', required=False, help='UniMorph Accurate verb replacements with regard to transitivity. In place of --unimorph0, --internal, --supertag, or --original.')
parser.add_argument('--internal', action='store_true', required=False, help='For internal word swapping. In place of --unimorph0, unimorph1, --supertag, or --original.')
parser.add_argument('--supertag', action='store_true', required=False, help='For internal supertag word swapping. In place of --unimorph0, unimorph1, --internal, or --original.')
parser.add_argument('--original', action='store_true', required=False, help='Appends the training data by itself without changes. In place of --unimorph0, unimorph1, --internal, or --supertag.')
parser.add_argument('-i', '--RRGinput', type=str, required=False, default='./rrgparbank/conllu/filtered_acc_en_conllu.conllu', help='(OPTIONAL) Filtered RRG file input. Default file: "rrgparbank/conllu/filtered_acc_en_conllu.conllu".')
parser.add_argument('-o', '--RRGoutput', type=str, required=False, default='./rrgparbank/conllu', help='(OPTIONAL) Filtered RRG file output directory. Default directory: "rrgparbank/conllu".')
parser.add_argument('-t', '--tag', type=str, required=False, help='Word tags.')
parser.add_argument('-ti', '--trainInput', required=False, default='./experiments/rrgparbank-en/base/train.supertags', type=str, help='(OPTIONAL) train.supertags file input. Default file: "experiments/rrgparbank-en/base/train.supertags".')
parser.add_argument('-to', '--trainOutput', required=False, default='./experiments/rrgparbank-en/new_', type=str, help='(OPTIONAL) train.supertags file output directory. If the directory is not specified, the default directory is used and filename changes to "new_train.extension".')
parser.add_argument('-s', '--extensionSize', required=True, type=int, help='Extension size of the resulting training file. Must be >= 2. "2" doubles the size (sentences) of the base training file, thus does 1 run through the file (-s input-1).')
baseTrPath = './experiments/rrgparbank-en/base/train.supertags'
args = parser.parse_args()
# //////////////////////////////////////////////////////////////////////////////////////////////////////
if args.tag not in tags and args.tag != None:
print(color.RED, color.BOLD, '\nWrong tag.\n')
print("Enter available tag.", color.END)
exit()
elif args.tag == None and (args.unimorph0 == True or args.unimorph1 == True or args.internal == True):
print(color.RED, color.BOLD, '\nMissing tag (-t) input!')
print("Enter available tag.", color.END)
exit()
try:
if args.extensionSize < 2:
raise Exception('ValueError')
except Exception as VE:
print(color.RED, color.BOLD, '\n', VE,' -s (--extensionSize) has to be >= 2.')
exit()
L_nS = []
L_aPoss = []
L_nP = []
L_aCmpr = []
L_aSup = []
L_vPst = []
L_vInf = []
L_vPresPart = []
L_vPstPart = []
L_adv = []
L_advInt = []
L_advSup = []
L_advCmpr = []
L_vPstIntr = []
L_vInfIntr = []
L_vPresPartIntr = []
L_vPstPartIntr = []
if os.path.isdir(args.trainOutput) == False:
print(color.RED, color.BOLD, '\nDirectory (-to) missing or does not exist!',)
print('Using default directory:\n./experiments/rrgparbank-en/', color.END)
args.trainOutput = './experiments/rrgparbank-en/new_'
if os.path.isfile(args.trainInput) == False:
print(color.RED, color.BOLD, '\nTraining input (-ti) missing or file does not exist!')
print('Using default train.supertags file.', color.END)
args.trainInput = './experiments/rrgparbank-en/base/train.supertags'
start = time.perf_counter()
# /// Copying input/original data to new training file
print('\nCopying input/original data to new training file...')
progressbar = tqdm(total=1)
with open(args.trainInput, 'r+', encoding='UTF-8', newline='\n') as training:
with open(args.trainOutput+'train.supertags', 'w', encoding='UTF-8', newline='\n') as outfileTr:
orgTr = csv.reader(training, delimiter='\t')
writer = csv.writer(outfileTr, delimiter='\t')
rowsTr = list(orgTr)
writer.writerows(rowsTr)
progressbar.update()
progressbar.close()
# /// creating temp file
temp = open('./experiments/rrgparbank-en/tempTr.txt', 'w', encoding='UTF-8', newline='\n')
temp.close()
if args.unimorph0 == True and args.unimorph1 == False and args.internal == False and args.supertag == False and args.original == False:
# /// running list function
lG(L_nS, L_nP, L_aPoss, L_aCmpr, L_aSup, L_vPst, L_vInf, L_vPresPart, L_vPstPart)
for x in range((args.extensionSize)-1):
mainG(args.RRGinput, args.trainInput, args.RRGoutput, args.tag, L_nS, L_nP, L_aPoss, L_aCmpr, L_aSup, L_vPst, L_vInf, L_vPresPart, L_vPstPart)
# /// sleep for 2 seconds for buffer
for i in range(2,0,-1):
print(f"{i}", end="\r", flush=True)
time.sleep(1)
print()
with open('./rrgparbank/conllu/modified_filtered_acc_en_conllu.conllu', 'r+', encoding='UTF-8', newline='\n') as modified:
with open('./experiments/rrgparbank-en/base/train.supertags', 'r+', encoding='UTF-8', newline='\n') as training:
with open('./experiments/rrgparbank-en/tempTr.txt', 'a', encoding='UTF-8', newline='\n') as outfile:
readerMod = csv.reader(modified, delimiter='\t')
readerTr = csv.reader(training, delimiter='\t')
writerTemp = csv.writer(outfile, delimiter='\t')
linesMod = list(readerMod) #///creates lists of lines from the file
linesTr = list(readerTr)
trainLength = []
sentLengths(linesTr, trainLength)
# /// run number indicator
print(color.BOLD, color.PURPLE, '\n\nRun ', (x+1), '/', (args.extensionSize)-1, color.END, '\n')
# /// Adding sentence lengths to the file
count = 0
for i in range(len(linesTr)):
if len(linesTr[i]) > 0:
linesTr[i].append('\t')
linesTr[i][4] = '_'
for j in range(len(linesTr)):
if len(linesTr[j]) > 0:
linesTr[j][4] = trainLength[count]
else:
count += 1
# /// creating dictionaries for faster access
dctMod = {'lines':[i for i in linesMod]}
dctTr = {'lines':[i for i in linesTr]}
# /// Swapping words in training file
print('\nSwapping words in training file...')
progressbar = tqdm(total=len(linesTr))
for lineTr in dctTr['lines']:
for lineMod in dctMod['lines']:
try:
if lineTr[1] == lineMod[10]:
if lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'NOUN':
if lineMod[5] == 'Number=Sing' and ('NUC_N (N <>' in lineTr[3] or 'NUC_N (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Number=Plur' and ('NUC_N (N <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'ADJ':
if lineMod[5] == 'Degree=Pos' and ('NUC_A (A <>' in lineTr[3] or 'NUC_A (V-PART <>' in lineTr[3] or 'NUC_A (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Degree=Cmp' and ('NUC_A (A <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Degree=Sup' and ('NUC_A (A <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'VERB':
if 'Tense=Past' in lineMod[5] and 'VerbForm=Fin' in lineMod[5] and 'NUC (V <>' in lineTr[3]:
lineTr[1] = lineMod[1]
elif 'VerbForm=Inf' in lineMod[5] and 'NUC (V <>' in lineTr[3]:
lineTr[1] = lineMod[1]
elif 'Tense=Pres' in lineMod[5] and 'VerbForm=Part' in lineMod[5] and ('NUC (V <>' in lineTr[3] or 'NUC_A (V-PART <>' in lineTr[3] or 'NUC_A (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif 'Tense=Past' in lineMod[5] and 'VerbForm=Part' in lineMod[5] and ('NUC_A (V-PART <>' in lineTr[3] or 'NUC (V <>' in lineTr[3] or 'NUC (V-PART <>' in lineTr[3] or 'V-PART <>' in lineTr[3]):
lineTr[1] = lineMod[1]
except(IndexError):
i += 1
progressbar.update()
progressbar.close()
trToList = list(dctTr['lines'])
print('\nChecking vowels and deleting unnecessary columns...')
# /// deletes columns with sentence lengths
progressbar = tqdm(total=len(trToList))
for i in range(len(trToList)):
if len(trToList[i]) > 0:
trToList[i].pop(4)
else:
i += 1
# /// checks vowels
for i in range(len(trToList)):
checkVowels(i, trToList)
progressbar.update()
writerTemp.writerows(trToList)
progressbar.close()
elif args.unimorph1 == True and args.unimorph0 == False and args.internal == False and args.supertag == False and args.original == False:
# /// running list function
lGacc(L_nS, L_nP, L_aPoss, L_aCmpr, L_aSup, L_vPst, L_vInf, L_vPresPart, L_vPstPart, L_vPstIntr, L_vInfIntr, L_vPresPartIntr, L_vPstPartIntr)
for x in range((args.extensionSize)-1):
mainGacc(args.RRGinput, args.trainInput, args.RRGoutput, args.tag, L_nS, L_nP, L_aPoss, L_aCmpr, L_aSup, L_vPst, L_vInf, L_vPresPart, L_vPstPart, L_vPstIntr, L_vInfIntr, L_vPresPartIntr, L_vPstPartIntr)
# /// sleep for 2 seconds for buffer
for i in range(2,0,-1):
print(f"{i}", end="\r", flush=True)
time.sleep(1)
print()
with open('./rrgparbank/conllu/modified_filtered_acc_en_conllu.conllu', 'r+', encoding='UTF-8', newline='\n') as modified:
with open('./experiments/rrgparbank-en/base/train.supertags', 'r+', encoding='UTF-8', newline='\n') as training:
with open('./experiments/rrgparbank-en/tempTr.txt', 'a', encoding='UTF-8', newline='\n') as outfile:
readerMod = csv.reader(modified, delimiter='\t')
readerTr = csv.reader(training, delimiter='\t')
writerTemp = csv.writer(outfile, delimiter='\t')
linesMod = list(readerMod) #///creates lists of lines from the file
linesTr = list(readerTr)
trainLength = []
sentLengths(linesTr, trainLength)
# /// run number indicator
print(color.BOLD, color.PURPLE, '\n\nRun ', (x+1), '/', (args.extensionSize)-1, color.END, '\n')
# /// Adding sentence lengths to the file
count = 0
for i in range(len(linesTr)):
if len(linesTr[i]) > 0:
linesTr[i].append('\t')
linesTr[i][4] = '_'
for j in range(len(linesTr)):
if len(linesTr[j]) > 0:
linesTr[j][4] = trainLength[count]
else:
count += 1
# /// creating dictionaries for faster access
dctMod = {'lines':[i for i in linesMod]}
dctTr = {'lines':[i for i in linesTr]}
# /// Swapping words in training file
print('\nSwapping words in training file...')
progressbar = tqdm(total=len(linesTr))
for lineTr in dctTr['lines']:
for lineMod in dctMod['lines']:
try:
if lineTr[1] == lineMod[10]:
if lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'NOUN':
if lineMod[5] == 'Number=Sing' and ('NUC_N (N <>' in lineTr[3] or 'NUC_N (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Number=Plur' and ('NUC_N (N <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'ADJ':
if lineMod[5] == 'Degree=Pos' and ('NUC_A (A <>' in lineTr[3] or 'NUC_A (V-PART <>' in lineTr[3] or 'NUC_A (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Degree=Cmp' and ('NUC_A (A <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Degree=Sup' and ('NUC_A (A <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'VERB':
if 'Tense=Past' in lineMod[5] and 'VerbForm=Fin' in lineMod[5] and 'NUC (V <>' in lineTr[3]:
lineTr[1] = lineMod[1]
elif 'VerbForm=Inf' in lineMod[5] and 'NUC (V <>' in lineTr[3]:
lineTr[1] = lineMod[1]
elif 'Tense=Pres' in lineMod[5] and 'VerbForm=Part' in lineMod[5] and ('NUC (V <>' in lineTr[3] or 'NUC_A (V-PART <>' in lineTr[3] or 'NUC_A (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif 'Tense=Past' in lineMod[5] and 'VerbForm=Part' in lineMod[5] and ('NUC_A (V-PART <>' in lineTr[3] or 'NUC (V <>' in lineTr[3] or 'NUC (V-PART <>' in lineTr[3] or 'V-PART <>' in lineTr[3]):
lineTr[1] = lineMod[1]
except(IndexError):
i += 1
progressbar.update()
progressbar.close()
trToList = list(dctTr['lines'])
print('\nChecking vowels and deleting unnecessary columns...')
# /// deletes columns with sentence lengths
progressbar = tqdm(total=len(trToList))
for i in range(len(trToList)):
if len(trToList[i]) > 0:
trToList[i].pop(4)
else:
i += 1
# /// checks vowels
for i in range(len(trToList)):
checkVowels(i, trToList)
progressbar.update()
writerTemp.writerows(trToList)
progressbar.close()
elif args.internal == True and args.unimorph0 == False and args.unimorph1 == False and args.supertag == False and args.original == False:
# /// running list function
lGIntern(L_nS, L_nP, L_aPoss, L_aCmpr, L_aSup, L_adv, L_advInt, L_advSup, L_advCmpr, L_vPst, L_vInf, L_vPresPart, L_vPstPart, L_vPstIntr, L_vInfIntr, L_vPresPartIntr, L_vPstPartIntr)
for x in range((args.extensionSize)-1):
mainGintern(args.RRGinput, args.trainInput, args.RRGoutput, args.tag, L_nS, L_nP, L_aPoss, L_aCmpr, L_aSup, L_adv, L_advInt, L_advSup, L_advCmpr, L_vPst, L_vInf, L_vPresPart, L_vPstPart, L_vPstIntr, L_vInfIntr, L_vPresPartIntr, L_vPstPartIntr)
# /// sleep for 2 seconds for buffer
for i in range(2,0,-1):
print(f"{i}", end="\r", flush=True)
time.sleep(1)
print()
with open('./rrgparbank/conllu/modified_filtered_acc_en_conllu.conllu', 'r+', encoding='UTF-8', newline='\n') as modified:
with open('./experiments/rrgparbank-en/base/train.supertags', 'r+', encoding='UTF-8', newline='\n') as training:
with open('./experiments/rrgparbank-en/tempTr.txt', 'a', encoding='UTF-8', newline='\n') as outfile:
readerMod = csv.reader(modified, delimiter='\t')
readerTr = csv.reader(training, delimiter='\t')
writerTemp = csv.writer(outfile, delimiter='\t')
linesMod = list(readerMod) #///creates lists of lines from the file
linesTr = list(readerTr)
trainLength = []
sentLengths(linesTr, trainLength)
# /// run number indicator
print(color.BOLD, color.PURPLE, '\n\nRun ', (x+1), '/', (args.extensionSize)-1, color.END, '\n')
# /// Adding sentence lengths to the file
count = 0
for i in range(len(linesTr)):
if len(linesTr[i]) > 0:
linesTr[i].append('\t')
linesTr[i][4] = '_'
for j in range(len(linesTr)):
if len(linesTr[j]) > 0:
linesTr[j][4] = trainLength[count]
else:
count += 1
# /// creating dictionaries for faster access
dctMod = {'lines':[i for i in linesMod]}
dctTr = {'lines':[i for i in linesTr]}
# /// Swapping words in training file
print('\nSwapping words in training file...')
progressbar = tqdm(total=len(linesTr))
for lineTr in dctTr['lines']:
for lineMod in dctMod['lines']:
try:
if lineTr[1] == lineMod[10]:
if lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'NOUN':
if lineMod[5] == 'Number=Sing' and ('NUC_N (N <>' in lineTr[3] or 'NUC_N (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Number=Plur' and ('NUC_N (N <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'ADJ':
if lineMod[5] == 'Degree=Pos' and ('NUC_A (A <>' in lineTr[3] or 'NUC_A (V-PART <>' in lineTr[3] or 'NUC_A (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Degree=Cmp' and ('NUC_A (A <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineMod[5] == 'Degree=Sup' and ('NUC_A (A <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'VERB':
if 'Tense=Past' in lineMod[5] and 'VerbForm=Fin' in lineMod[5] and 'NUC (V <>' in lineTr[3]:
lineTr[1] = lineMod[1]
elif 'VerbForm=Inf' in lineMod[5] and 'NUC (V <>' in lineTr[3]:
lineTr[1] = lineMod[1]
elif 'Tense=Pres' in lineMod[5] and 'VerbForm=Part' in lineMod[5] and ('NUC (V <>' in lineTr[3] or 'NUC_A (V-PART <>' in lineTr[3] or 'NUC_A (V-GER <>' in lineTr[3]):
lineTr[1] = lineMod[1]
elif 'Tense=Past' in lineMod[5] and 'VerbForm=Part' in lineMod[5] and ('NUC_A (V-PART <>' in lineTr[3] or 'NUC (V <>' in lineTr[3] or 'NUC (V-PART <>' in lineTr[3] or 'V-PART <>' in lineTr[3]):
lineTr[1] = lineMod[1]
# elif lineTr[4] == lineMod[4] and lineTr[0] == lineMod[0] and lineMod[3] == 'ADV' and 'NUC_ADV (ADV <>' in lineTr[3]:
# lineTr[1] = lineMod[1]
except(IndexError):
i += 1
progressbar.update()
progressbar.close()
trToList = list(dctTr['lines'])
print('\nChecking vowels and deleting unnecessary columns...')
# /// deletes columns with sentence lengths
progressbar = tqdm(total=len(trToList))
for i in range(len(trToList)):
if len(trToList[i]) > 0:
trToList[i].pop(4)
else:
i += 1
# /// checks vowels
for i in range(len(trToList)):
checkVowels(i, trToList)
progressbar.update()
writerTemp.writerows(trToList)
progressbar.close()
elif args.supertag == True and args.unimorph0 == False and args.unimorph1 == False and args.internal == False and args.original == False:
for x in range((args.extensionSize)-1):
mainGsupertag(args.trainInput, args.trainOutput, args.tag)
# /// sleep for 2 seconds for buffer
for i in range(2,0,-1):
print(f"{i}", end="\r", flush=True)
time.sleep(1)
print()
with open('./experiments/rrgparbank-en/tempST.txt', 'r+', encoding='UTF-8', newline='\n') as training:
with open('./experiments/rrgparbank-en/tempTr.txt', 'a', encoding='UTF-8', newline='\n') as outfile:
readerTr = csv.reader(training, delimiter='\t')
writerTemp = csv.writer(outfile, delimiter='\t')
linesTr = list(readerTr)
# /// run number indicator
print(color.BOLD, color.PURPLE, '\n\nRun ', (x+1), '/', (args.extensionSize)-1, color.END, '\n')
print('\nChecking vowels and deleting unnecessary columns...')
# /// deletes columns with sentence lengths
progressbar = tqdm(total=len(linesTr))
for i in range(len(linesTr)):
if len(linesTr[i]) > 0:
linesTr[i].pop(4)
else:
i += 1
# /// checks vowels
for i in range(len(linesTr)):
checkVowels(i, linesTr)
progressbar.update()
writerTemp.writerows(linesTr)
progressbar.close()
elif args.original == True and args.unimorph0 == False and args.unimorph1 == False and args.internal == False and args.supertag == False:
with open('./experiments/rrgparbank-en/base/train.supertags', 'r', encoding='UTF-8', newline='\n') as train:
with open('./experiments/rrgparbank-en/tempTr.txt', 'a', encoding='UTF-8', newline='\n') as outfile:
readerTr = csv.reader(train, delimiter='\t')
linesTr = list(readerTr)
writerTemp = csv.writer(outfile, delimiter='\t')
print('\nExtending training file with original sentences...')
progressbar = tqdm(total=args.extensionSize-1)
for x in range((args.extensionSize)-1):
writerTemp.writerows(linesTr)
progressbar.update()
progressbar.close()
else:
print('Options --unimorph0, --unimorph1, --internal, --supertag, and --original can only be used separately!')
exit()
# /// Writing to new training file
print('\nWriting to new training file...')
progressbar = tqdm(total=1)
with open('./experiments/rrgparbank-en/tempTr.txt', 'r+', encoding='UTF-8', newline='\n') as infileTemp:
with open(args.trainOutput+'train.supertags', 'a', encoding='UTF-8', newline='\n') as infileTr:
readerTemp = csv.reader(infileTemp, delimiter='\t')
writer = csv.writer(infileTr, delimiter='\t')
rowsTemp = list(readerTemp)
writer.writerows(rowsTemp)
progressbar.update()
progressbar.close()
# Removing temporary files
if os.path.exists('./experiments/rrgparbank-en/tempTr.txt'):
os.remove('./experiments/rrgparbank-en/tempTr.txt')
if os.path.exists('./experiments/rrgparbank-en/tempST.txt'):
os.remove('./experiments/rrgparbank-en/tempST.txt')
trainOut = args.trainOutput
logpath = args.trainOutput
if 'new_' in args.trainOutput:
logpath = trainOut.replace('new_', '')
# /// Creating logfile
print('\nCreating logfile...')
time.sleep(1)
progressbar = tqdm(total=1)
with open(logpath+'log.txt', 'w', encoding='UTF-8', newline='\n') as logfile:
with open(args.trainOutput+'train.supertags', 'r+', encoding='UTF-8', newline='\n') as infileNewTr:
with open(baseTrPath, 'r+', encoding='UTF-8', newline='\n') as infileBaseTr:
readerNewTr = csv.reader(infileNewTr, delimiter='\t')
readerOrgTr = csv.reader(infileBaseTr, delimiter='\t')
newTrlen = []
orgTrlen = []
sentLengths(list(readerNewTr), newTrlen)
sentLengths(list(readerOrgTr), orgTrlen)
if args.unimorph0 != False or args.unimorph1 != False or args.internal != False:
logfile.write('Tag used for replacements:\t'+str(args.tag)+'\n')
logfile.write('Training file used:\t'+args.trainInput)
logfile.write('\nNumber of sentences:\t'+str(len(newTrlen)))
logfile.write('\nExtension size input:\t'+str(args.extensionSize))
logfile.write('\nActual ratio:\t'+str(len(newTrlen)/len(orgTrlen))+'x of base training file')
if args.internal != False:
logfile.write('\n\nInternal constituent replacements')
elif args.supertag != False:
logfile.write('\n\nSupertag constituent replacements')
elif args.original != False:
logfile.write('\n\nAugmentation without constituent replacements')
elif args.unimorph0 != False:
logfile.write('\n\nUniMorph constituent replacements')
elif args.unimorph1 != False:
logfile.write('\n\nUniMorph constituent replacements')
logfile.write('\nVerb transitivity accounted for')
progressbar.update()
progressbar.close()
end = time.perf_counter()
mins = int((end-start)/60)
secs = int((end-start)%60)
print(f'\nTime taken: {mins}min {secs}s')