|
from utils import ( |
|
read_jsonl_file, |
|
write_jsonl_file, |
|
parse, |
|
) |
|
|
|
label2relation = { |
|
"1": "Child and Parent", |
|
"2": "Child and Other Family Elder", |
|
"3": "Siblings", |
|
"4": "Spouse", |
|
"5": "Lovers", |
|
"6": "Courtship", |
|
"7": "Friends", |
|
"8": "Neighbors", |
|
"9": "Roommates", |
|
"10": "Workplace Superior and Subordinate", |
|
"11": "Colleague or Partners", |
|
"12": "Opponents", |
|
"13": "Professional Contact", |
|
} |
|
|
|
|
|
def reformat(args, file): |
|
path = args.input_dir + "/" + file + ".txt" |
|
data = read_jsonl_file(path) |
|
|
|
turns = [] |
|
for i in range(len(data)): |
|
t = {"turn": "multi", "locale": "en", "dialog": []} |
|
AB2name = {"A": data[i]["nameA"], "B": data[i]["nameB"]} |
|
|
|
for c in data[i]["context"]: |
|
role = c[0] |
|
utterance = c[2:].strip() |
|
|
|
if role not in AB2name: |
|
role = "B" |
|
utterance = c |
|
|
|
d = {"roles": [AB2name[role]], "utterance": utterance} |
|
t["dialog"].append(d) |
|
|
|
t["role_relations"] = [{"relation": label2relation[data[i]["label"]]}] |
|
|
|
turns.append(t) |
|
|
|
write_jsonl_file(turns, args.output_dir + "/" + file + ".jsonl") |
|
|
|
|
|
def preprocess(args): |
|
reformat(args, "train") |
|
reformat(args, "dev") |
|
reformat(args, "test") |
|
|
|
|
|
if __name__ == "__main__": |
|
args = parse() |
|
preprocess(args) |
|
|