| import os | |
| from utils import write_jsonl_file, read_csv_file, parse | |
| def get_knowledge(input_dir): | |
| path = os.path.join(input_dir, "train_sent_emo.csv") | |
| data = read_csv_file(path) | |
| emotions = set() | |
| for i in range(1, len(data)): | |
| emotions.add(data.iloc[i][3]) | |
| return sorted(emotions) | |
| def reformat(args, file): | |
| path = os.path.join(args.input_dir, f"{file}_sent_emo.csv") | |
| data = read_csv_file(path) | |
| turns = [] | |
| for i in range(len(data)): | |
| ds = data.iloc[i] | |
| t = { | |
| "turn": "single", | |
| "locale": "en", | |
| "dialog": [], | |
| } | |
| d = { | |
| "roles": [ds[2]], | |
| "utterance": ds[1], | |
| "emotions": [{"emotion": ds[3], "sentiment": ds[4]}], | |
| } | |
| t["dialog"].append(d) | |
| turns.append(t) | |
| write_jsonl_file(turns, args.output_dir + "/" + file + ".jsonl") | |
| if __name__ == "__main__": | |
| args = parse() | |
| reformat(args, "train") | |
| reformat(args, "dev") | |
| reformat(args, "test") | |