-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeLabelsFromCsv.py
38 lines (32 loc) · 1.37 KB
/
makeLabelsFromCsv.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
# 1 means correct language and correct meaning
# 2 means incorrect language and correct meaning
# 3 means incorrect language and incorrect meaning
import sys
import subprocess
content = []
result = []
for idx, arg in enumerate(sys.argv):
if not idx == 0:
with open(arg) as inputFile:
content = inputFile.readlines()
for line in content:
splitted = line.split(" ")
if splitted[0] != "Id":
# language
language = splitted[5].lower().replace('"', '')
meaning = splitted[6].lower().replace('"', '')
label = '-1'
if 'correct' in language and 'correct' in meaning:
label = '1,0,0'
if 'incorrect' in language and 'correct'in meaning:
label = '0,1,0'
if 'incorrect' in language and 'incorrect' in meaning:
label = '0,0,1'
line = ''
if len(result) < len(content):
line += splitted[0].replace('"','') + ',' + label + '\n'
else:
line += splitted[0].replace('"','') + ',' + label
result.append(line)
with open("gen_labeled_data.csv", 'w+') as outputFile:
outputFile.writelines(result)