File size: 1,497 Bytes
a6326c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import re
from utils import read_json_file, read_jsonl_file, write_json_file, write_jsonl_file, read_txt_file, read_csv_file,  parse


def reformat(args, file):
    path = args.input_dir + "/" + file + ".csv"
    data = read_csv_file(path)
    turns = []
    for i in range(1, len(data)):
        ds = data[i]
        t = {
            "turn": "single", 
            "locale": "en",
            "dialog": []
        }
        d = {"role": ds[1].strip("\[\]\'"),
             "utterance": ds[0],
             "belief_state": [{"domain": None,
                               "goal": [{"intent": None,
                                         "slot_value_table": [{"slot": 'Emotion', "value": ds[2]},
                                                              {"slot": 'Sentiment', "value": ds[4]}
                                                              ]}
                                        ]}
                              ],
             "querying_result": [],
             "summary": None,
             "locale": None,
             "topic" : None,
             "opinions": None,
             "answer": None}
        t["dialog"].append(d)

        t["knowledge"] = None
        turns.append(t)

    write_jsonl_file(turns, args.output_dir + "/" + file + ".jsonl")


def preprocess(args):
    reformat(args, "emorynlp_train_final")
    reformat(args, "emorynlp_dev_final")
    reformat(args, "emorynlp_test_final")


if __name__ == "__main__":
    args = parse()
    preprocess(args)