challenging-america-word-ga.../prep_txt.py

34 lines
753 B
Python

import csv
tr = []
tr_r = []
folder = 'dev-0'
with open(f'{folder}/in_1.csv', 'r', encoding='utf-8') as file:
csv_reader = csv.reader(file, delimiter=',')
for row in csv_reader:
tr.append(row)
with open(f'{folder}/expected.tsv', 'r', encoding='utf-8') as file:
csv_reader = csv.reader(file, delimiter='\t')
for row in csv_reader:
tr_r.append(row)
data = []
for i in range(len(tr)):
try:
data.append([tr[i][0], tr_r[i], tr[i][1]])
except:
try:
data.append([tr[i][0], tr_r[i], ''])
except:
pass
with open(f'{folder}/in.txt', 'w', encoding='utf-8') as f:
for item in data:
f.write(str(item[0]) + ' ' + str(item[1][0]) + ' ' + str(item[2]) + '\n')