-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_labels.py
39 lines (35 loc) · 1.37 KB
/
convert_labels.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
import json
all_data = []
filenames = ["E_train.json", "F_train.json", "G_train.json", "H_train.json"]
for filename in filenames:
print(filename)
with open("./data/new_annot/polarity/" + filename, "r", encoding="latin1") as af:
for line in af:
annot = json.loads(line)
polarity = []
if annot["label"] == "Positive":
annot["label"] = 2
elif annot["label"] == "Negative":
annot["label"] = 0
else:
annot["label"] = 1
all_data.append(annot)
with open("./data/new_annot/polarity_label/" + filename, "w", encoding="latin1") as wf:
for line in all_data:
json.dump(line, wf)
wf.write('\n')
'''
print("evaluating validity...")
# testing
with open("./data/new_annot/polarity_label/" + filename, "r", encoding="latin1") as ef:
i = 0
for line in ef:
annot = json.loads(line)
print(line == all_data[i])
if annot["label"] == 1 and all_data[i]["label"] != "Positive":
print("incorrectly labelled 1:" + str(line))
elif annot["label"] == -1 and all_data[i]["label"] != "Negative":
print("incorrectly labelled -1:" + str(line))
elif annot["label"] == 0:
print("incorrectly labelled 0:" + str(line))
'''