removed load save functions

This commit is contained in:
Tomas Kucharik 2022-02-20 21:34:12 +01:00
parent 695cef2b32
commit e5c2794c06

View File

@ -1,20 +1,9 @@
import json import json
from dotenv import load_dotenv from dotenv import load_dotenv
from squad_utils import print_squad 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): def sort_qas_by_answer_index(squad):
for article in squad['data']: for article in squad['data']:
for paragraph in article['paragraphs']: for paragraph in article['paragraphs']:
@ -83,11 +72,13 @@ def add_special_chars_to_paragraph(paragraph):
if __name__ == "__main__": if __name__ == "__main__":
load_dotenv() 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) sort_qas_by_answer_index(squad)
transform_squad(squad) transform_squad(squad)
print_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)