| from utils import parse, write_jsonl_file | |
| import xml.etree.ElementTree as ET | |
| import os | |
| def preprocess(args, split): | |
| infile = os.path.join(args.input_dir, f"{split}.xml") | |
| if split == "val": | |
| split = "dev" | |
| outfile = os.path.join(args.output_dir, f"{split}.jsonl") | |
| tree = ET.parse(infile) | |
| processed_data = [] | |
| for sentence in tree.getroot(): | |
| processed_data.append( | |
| { | |
| "turn": "single", | |
| "locale": "en", | |
| "dialog": [ | |
| {"roles": ["USER"], "utterance": sentence[0].text, "aspects": []} | |
| ], | |
| } | |
| ) | |
| for aspect in sentence[1]: | |
| processed_data[-1]["dialog"][-1]["aspects"].append( | |
| { | |
| "category": aspect.attrib["category"], | |
| "sentiment": aspect.attrib["polarity"], | |
| } | |
| ) | |
| write_jsonl_file(processed_data, outfile) | |
| if __name__ == "__main__": | |
| args = parse() | |
| preprocess(args, "train") | |
| preprocess(args, "val") | |
| preprocess(args, "test") | |