code: def parse_semeval(fn, reasoning, savefile):
      json_lines = []
      reasonings = {}
      with open(reasoning, "r") as f:
          json_lines = json.load(f)
  
      for json_line in json_lines:
          reasonings[json_line["key"]] = json_line
  
      with open(fn) as fd:
          doc = xmltodict.parse(fd.read())
  
      structs = []
      data = doc["data"]  # == u'an attribute'
      instances = data["instance"]  # == [u'elements', u'more elements']
      cnt = 0
      for instance in instances:
          ins = {}
          context = re.sub(r"\s+", " ", instance["text"])
          id = instance["@id"]
  
          ins["id"] = id
          ins["premise"] = context
  
          ins["questions"] = []
  
          for question in instance["questions"]["question"]:
              quu1 = {
                  "premise": "",
                  "hypothesis": "",
                  "answer": "",
                  "gpt-3": "",
                  "dataset": "",
              }
              quu2 = {
                  "premise": "",
                  "hypothesis": "",
                  "answer": "",
                  "gpt-3": "",
                  "dataset": "",
              }
  
              q = question["@text"]
              quu1["key"] = (
                  instance["@id"]
                  + "\t"
                  + question["@id"]
                  + "\t"
                  + question["answer"][0]["@id"]
              )
              quu2["key"] = (
                  instance["@id"]
                  + "\t"
                  + question["@id"]
                  + "\t"
                  + question["answer"][1]["@id"]
              )
  
              if question["answer"][0]["@correct"] == "False":
                  quu1["hypothesis"] = question["answer"][0]["@text"]
                  quu1["answer"] = "no"
              else:
                  quu1["hypothesis"] = question["answer"][0]["@text"]
                  quu1["answer"] = "yes"
  
              if question["answer"][1]["@correct"] == "False":
                  quu2["answer"] = "no"
                  quu2["hypothesis"] = question["answer"][1]["@text"]
              else:
                  quu2["hypothesis"] = question["answer"][1]["@text"]
                  quu2["answer"] = "yes"
  
              quu1["premise"] = context + " " + q
              quu2["premise"] = context + " " + q
  
              if quu1["key"] in reasonings:
                  reasoning = reasonings[quu1["key"]]["reasoning"]
                  quu1["gpt-3"] = reasoning
                  structs.append(quu1)
              else:
                  val = quu1["key"]
                  print(f"No reasoning found for key {val}")
  
              if quu2["key"] in reasonings:
                  reasoning = reasonings[quu2["key"]]["reasoning"]
                  quu2["gpt-3"] = reasoning
                  structs.append(quu2)
              else:
                  val = quu2["key"]
                  print(f"No reasoning found for key {val}")
          cnt += 1
  
      write_to_file(structs, savefile)
  
file_path: ParlAI/projects/roscoe/roscoe_data/restore_annotated.py
imports: import json
  import csv
  import os
  import re
  import xmltodict
  from parlai.core.params import ParlaiParser
label_desc: Use image node_id 5 for calling a global function with example usage: parse_semeval(fn, reasoning, savefile) without return types