code: def to_lf(s, table):
      aggs = [y.lower() for y in Query.agg_ops]
      agg_to_idx = {x: i for i, x in enumerate(aggs)}
      conditionals = [y.lower() for y in Query.cond_ops]
      headers_unsorted = [
          (y.lower(), i) for i, y in enumerate(table["header"])
      ]
      headers = [(y.lower(), i) for i, y in enumerate(table["header"])]
      headers.sort(reverse=True, key=lambda x: len(x[0]))
      condition_s, conds = None, []
      if "where" in s:
          s, condition_s = s.split("where", 1)
  
      s = " ".join(s.split()[1:-2])
      sel, agg = None, 0
      for col, idx in headers:
          if col == s:
              sel = idx
      if sel is None:
          s = s.split()
          agg = agg_to_idx[s[0]]
          s = " ".join(s[1:])
          for col, idx in headers:
              if col == s:
                  sel = idx
  
      full_conditions = []
      if not condition_s is None:
          condition_s = " " + condition_s + " "
          for idx, col in enumerate(headers):
              condition_s = condition_s.replace(
                  " " + col[0] + " ", " Col{} ".format(col[1])
              )
          condition_s = condition_s.strip()
  
          for idx, col in enumerate(conditionals):
              new_s = []
              for t in condition_s.split():
                  if t == col:
                      new_s.append("Cond{}".format(idx))
                  else:
                      new_s.append(t)
              condition_s = " ".join(new_s)
          s = condition_s
          conds = re.split("(Col\d+ Cond\d+)", s)
          if len(conds) == 0:
              conds = [s]
          conds = [x for x in conds if len(x.strip()) > 0]
          full_conditions = []
          for i, x in enumerate(conds):
              if i % 2 == 0:
                  x = x.split()
                  col_num = int(x[0].replace("Col", ""))
                  opp_num = int(x[1].replace("Cond", ""))
                  full_conditions.append([col_num, opp_num])
              else:
                  x = x.split()
                  if x[-1] == "and":
                      x = x[:-1]
                  x = " ".join(x)
                  if "Col" in x:
                      new_x = []
                      for t in x.split():
                          if "Col" in t:
                              idx = int(t.replace("Col", ""))
                              t = headers_unsorted[idx][0]
                          new_x.append(t)
                      x = new_x
                      x = " ".join(x)
                  if "Cond" in x:
                      new_x = []
                      for t in x.split():
                          if "Cond" in t:
                              idx = int(t.replace("Cond", ""))
                              t = conditionals[idx]
                          new_x.append(t)
                      x = new_x
                      x = " ".join(x)
                  full_conditions[-1].append(x)
      logical_form = {"sel": sel, "conds": full_conditions, "agg": agg}
      return logical_form
  
imports: from subprocess import Popen, PIPE, CalledProcessError
  import json
  from text.torchtext.datasets.generic import Query
  import logging
  import os
  import re
  import string
  import numpy
  import collections
  from multiprocessing import Pool, cpu_count
  from contextlib import closing
  from pyrouge import Rouge155
  from sacrebleu import corpus_bleu
label_desc: Use image node_id 1 for calling a global function with example usage: to_lf(s, table) and returns: logical_form