code: def write_logical_forms(greedy, args):
      data_dir = os.path.join(args.data, "wikisql", "data")
      path = (
          os.path.join(data_dir, "dev.jsonl")
          if "valid" in args.evaluate
          else os.path.join(data_dir, "test.jsonl")
      )
      table_path = (
          os.path.join(data_dir, "dev.tables.jsonl")
          if "valid" in args.evaluate
          else os.path.join(data_dir, "test.tables.jsonl")
      )
      with open(table_path) as tables_file:
          tables = [json.loads(line) for line in tables_file]
          id_to_tables = {x["id"]: x for x in tables}
  
      examples = []
      with open(path) as example_file:
          for line in example_file:
              entry = json.loads(line)
              table = id_to_tables[entry["table_id"]]
              sql = entry["sql"]
              header = table["header"]
              a = repr(Query.from_dict(entry["sql"], table["header"]))
              ex = {
                  "sql": sql,
                  "header": header,
                  "answer": a,
                  "table": table,
              }
              examples.append(ex)
  
      with open(args.output, "a") as f:
          count = 0
          correct = 0
          text_answers = []
          for idx, (g, ex) in enumerate(zip(greedy, examples)):
              count += 1
              text_answers.append([ex["answer"].lower()])
              try:
                  lf = to_lf(g, ex["table"])
                  f.write(json.dumps(correct_format(lf)) + "\n")
                  gt = ex["sql"]
                  conds = gt["conds"]
                  lower_conds = []
                  for c in conds:
                      lc = c
                      lc[2] = str(lc[2]).lower()
                      lower_conds.append(lc)
                  gt["conds"] = lower_conds
                  correct += lf == gt
              except Exception as e:
                  f.write(json.dumps(correct_format({})) + "\n")
  
file_path: decanlp/convert_to_logical_forms.py
imports: from text.torchtext.datasets.generic import Query
  from argparse import ArgumentParser
  import os
  import re
  import ujson
  from metrics import to_lf
label_desc: Use image node_id 2 for calling a global function with example usage: write_logical_forms(greedy, args) without return types