pooja-premnath
/
SemEval2024-Emotion-Classification-in-Hinglish-Code-Mixed-Dialogue-using-Transformer-based-Models
Public
forked from Parthiee/SemEval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_csv_preparation.py
25 lines (20 loc) · 873 Bytes
/
output_csv_preparation.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
import json
import csv
# Read the JSON file
with open(r"C:\Users\pooja\Downloads\MaSaC_test_erc.json", 'r') as json_file:
data = json.load(json_file)
# Extract utterance and emotion from each episode
utterances_emotions = []
for episode_data in data:
utterances = episode_data['utterances']
emotions = episode_data['labels']
# Ensure utterances and emotions have the same length
assert len(utterances) == len(emotions)
for utterance, emotion in zip(utterances, emotions):
utterances_emotions.append((utterance, emotion))
# Write the utterances and emotions to a CSV file
with open(r'C:\Users\pooja\Downloads\output_test.csv', 'w', newline='', encoding='utf-8') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['utterance', 'emotion']) # Write header
writer.writerows(utterances_emotions)
print("done- yay!")