[66af30]: / util / get_sentiment_labels.py

Download this file

34 lines (26 with data), 1.1 kB

 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
import os
from glob import glob
import json
print('##############################')
print('start generating ZuCo task1-SR sentiment labels...')
sentiment_labels_task1_csv_path = '~/datasets/ZuCo/task_materials/sentiment_labels_task1.csv'
sentiment_labels = {}
with open(sentiment_labels_task1_csv_path, 'r') as f:
for line in f:
if line.startswith('sentence_id') or line.startswith('#'):
continue
else:
parsed_line = line.split(';')
# handle edge case:
if '\";' in line:
sent_text = line.split('\";')[0].split('\"')[1]
else:
sent_text = parsed_line[1]
label = int(parsed_line[-1].strip())
sentiment_labels[sent_text] = label
output_dir = f'~/datasets/ZuCo/task1-SR/sentiment_labels'
if not os.path.exists(output_dir):
os.makedirs(output_dir)
with open(os.path.join(output_dir, 'sentiment_labels.json'), 'w') as out:
json.dump(sentiment_labels,out,indent = 4)
print('write to ~/datasets/ZuCo/task1-SR/sentiment_labels/sentiment_labels.json')