-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_csv.py
34 lines (21 loc) · 801 Bytes
/
to_csv.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
f = open("./AffectiveText.test/affectivetext_test.xml", 'r').read().split('\n')[1:-2]
g = open("./AffectiveText.trial/affectivetext_trial.xml",
'r').read().split('\n')[1:-2]
f = f + g
filtered = []
for i in f:
filtered.append(i.split('>')[1].split('<')[0].replace("\"", ""))
f = open("./AffectiveText.test/affectivetext_test.emotions.gold",
'r').read().split('\n')[:-1]
g = open("./AffectiveText.trial/affectivetext_trial.emotions.gold",
'r').read().split('\n')[:-1]
f = f + g
assert len(filtered) == len(f)
to_csv = []
for i in xrange(len(f)):
to_csv.append("\"" + filtered[i] + "\", " + ", ".join(f[i].split(' ')[1:]) + '\n')
csv = open("emotion_data.csv", 'w')
csv.write("headline, anger, disgust, fear, joy, sadness, surprise\n")
for i in to_csv:
csv.write(i)
csv.close()