ma2za commited on
Commit
1baae2e
·
1 Parent(s): 937f2e2

Upload emotions_dataset.py

Browse files
Files changed (1) hide show
  1. emotions_dataset.py +22 -14
emotions_dataset.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import zipfile
2
  from typing import List
3
 
@@ -133,17 +134,24 @@ class EmotionsDataset(datasets.GeneratorBasedBuilder):
133
  emo_mapping = {0: "no emotion", 1: "anger", 2: "disgust",
134
  3: "fear", 4: "happiness", 5: "sadness", 6: "surprise"}
135
  for i, filepath in enumerate(filepaths):
136
- with zipfile.ZipFile(filepath, 'r') as archive:
137
- emotions = archive.open("ijcnlp_dailydialog/dialogues_emotion.txt", "r").read().decode().split("\n")
138
- text = archive.open("ijcnlp_dailydialog/dialogues_text.txt", "r").read().decode().split("\n")
139
- for idx_out, (e, t) in enumerate(zip(emotions, text)):
140
- if len(t.strip()) > 0:
141
- cast_emotions = [int(j) for j in e.strip().split(" ")]
142
- cast_dialog = [d.strip() for d in t.split("__eou__") if len(d)]
143
- for idx_in, (ce, ct) in enumerate(zip(cast_emotions, cast_dialog)):
144
- uid = f"daily_dialog_{i}_{idx_out}_{idx_in}"
145
- yield uid, {"text": ct,
146
- "id": uid,
147
- "dataset": dataset,
148
- "license": license,
149
- "label": emo_mapping[ce]}
 
 
 
 
 
 
 
 
1
+ import os
2
  import zipfile
3
  from typing import List
4
 
 
134
  emo_mapping = {0: "no emotion", 1: "anger", 2: "disgust",
135
  3: "fear", 4: "happiness", 5: "sadness", 6: "surprise"}
136
  for i, filepath in enumerate(filepaths):
137
+ if os.path.isdir(filepath):
138
+ emotions = open(os.path.join(filepath, "ijcnlp_dailydialog/dialogues_emotion.txt"), "r").read()
139
+ text = open(os.path.join(filepath, "ijcnlp_dailydialog/dialogues_text.txt"), "r").read()
140
+ else:
141
+ archive = zipfile.ZipFile(filepath, 'r')
142
+ emotions = archive.open("ijcnlp_dailydialog/dialogues_emotion.txt", "r").read().decode()
143
+ text = archive.open("ijcnlp_dailydialog/dialogues_text.txt", "r").read().decode()
144
+ emotions = emotions.split("\n")
145
+ text = text.split("\n")
146
+
147
+ for idx_out, (e, t) in enumerate(zip(emotions, text)):
148
+ if len(t.strip()) > 0:
149
+ cast_emotions = [int(j) for j in e.strip().split(" ")]
150
+ cast_dialog = [d.strip() for d in t.split("__eou__") if len(d)]
151
+ for idx_in, (ce, ct) in enumerate(zip(cast_emotions, cast_dialog)):
152
+ uid = f"daily_dialog_{i}_{idx_out}_{idx_in}"
153
+ yield uid, {"text": ct,
154
+ "id": uid,
155
+ "dataset": dataset,
156
+ "license": license,
157
+ "label": emo_mapping[ce]}