diff --git a/squad_transform.py b/squad_transform.py index 358f563..d6410df 100644 --- a/squad_transform.py +++ b/squad_transform.py @@ -1,20 +1,9 @@ import json from dotenv import load_dotenv + from squad_utils import print_squad -def load(filename): - with open(filename, "r") as f: - squad = json.load(f) - - return squad - - -def save(filename, squad): - with open(filename, "w") as f: - json.dump(squad, f, indent=2) - - def sort_qas_by_answer_index(squad): for article in squad['data']: for paragraph in article['paragraphs']: @@ -83,11 +72,13 @@ def add_special_chars_to_paragraph(paragraph): if __name__ == "__main__": load_dotenv() - squad = load('./squad-test.json') + with open("./squad-test.json", "r") as f: + squad = json.load(f) sort_qas_by_answer_index(squad) transform_squad(squad) print_squad(squad) - save("./squad-test-translated.json", squad) + with open("./squad-test-translated.json", "w") as f: + json.dump(squad, f, indent=2)