(tokens, nlu, nlu_t, hds, tt_to_t_idx, pnt_start_tok, pnt_end_tok, pnt_idxs, i_vg_list, i_vg_sub_list)
return sql_q, sql_i
(
        "none", "max", "min", "count", "sum", "average",
        "select", "where", "and",
        "equal", "greater than", "less than",
        "start", "end"
    ),
(
        "none", "max", "min", "count", "sum", "average",
        "select", "where", "and",
        "equal", "greater than", "less than",
        "start", "end"
    ),
( none max min count sum average select where and equal greater than less than start end )
def gen_sql_q_from_i_vg(tokens, nlu, nlu_t, hds, tt_to_t_idx, pnt_start_tok, pnt_end_tok, pnt_idxs, i_vg_list, i_vg_sub_list):
    """
    (
        "none", "max", "min", "count", "sum", "average",
        "select", "where", "and",
        "equal", "greater than", "less than",
        "start", "end"
    ),
    """
    sql_q = []
    sql_i = []
    for b, nlu_t1 in enumerate(nlu_t):
        sql_q1_list = []
        sql_i1 = {}
        tt_to_t_idx1 = tt_to_t_idx[b]
        nlu_st_observed = False
        agg_observed = False
        wc_obs = False
        wo_obs = False
        conds = []

        for t, i_vg in enumerate(i_vg_list[b]):
            i_vg_sub = i_vg_sub_list[b][t]
            pnt = pnt_idxs[b][t]
            if i_vg == 0:
                # sql_vocab
                if pnt == pnt_start_tok or pnt == pnt_end_tok:
                    pass
                else:
                    tok = tokens[b][pnt]
                    if tok in ["none", "max", "min", "count", "sum", "average"]:
                        agg_observed = True
                        if tok == "none":
                            pass
                        sql_i1["agg"] = ["none", "max", "min", "count", "sum", "average"].index(tok)
                    else:
                        if tok in ["greater", "less", "equal"]:
                            if tok == 'greater':
                                tok = '>'
                            elif tok == 'less':
                                tok = '<'
                            elif tok == 'equal':
                                tok = '='

                            # gen conds1
                            if wc_obs:
                                conds1.append( ['=','>','<'].index(tok) )
                                wo_obs = True

                        sql_q1_list.append(tok)

            elif i_vg == 1:
                # nlu case
                if not nlu_st_observed:
                    idx_nlu_st = pnt
                    nlu_st_observed = True
                else:
                    # now to wrap up
                    idx_nlu_ed = pnt
                    st_wh_idx = tt_to_t_idx1[idx_nlu_st - pnt_end_tok - 2]
                    ed_wh_idx = tt_to_t_idx1[idx_nlu_ed - pnt_end_tok - 2]
                    pr_wv_str11 = nlu_t1[st_wh_idx:ed_wh_idx + 1]
                    merged_wv11 = merge_wv_t1_eng(pr_wv_str11, nlu[b])
                    sql_q1_list.append(merged_wv11)
                    nlu_st_observed = False

                    if wc_obs and wo_obs:
                        conds1.append(merged_wv11)
                        conds.append(conds1)

                        wc_obs = False
                        wo_obs = False


            elif i_vg == 2:
                # headers
                tok = hds[b][i_vg_sub]
                if agg_observed:
                    sql_q1_list.append(f"({tok})")
                    sql_i1["sel"] = i_vg_sub
                    agg_observed = False
                else:
                    wc_obs = True
                    conds1 = [i_vg_sub]

                    sql_q1_list.append(tok)

        # insert table name between.
        sql_i1["conds"] = conds
        sql_i.append(sql_i1)
        sql_q1 = ' '.join(sql_q1_list)
        sql_q.append(sql_q1)

    return sql_q, sql_i
def gen_sql_q_from_i_vg ( tokens , nlu , nlu_t , hds , tt_to_t_idx , pnt_start_tok , pnt_end_tok , pnt_idxs , i_vg_list , i_vg_sub_list ) : sql_q = [ ] sql_i = [ ] for b , nlu_t1 in enumerate ( nlu_t ) : sql_q1_list = [ ] sql_i1 = { } tt_to_t_idx1 = tt_to_t_idx [ b ] nlu_st_observed = False agg_observed = False wc_obs = False wo_obs = False conds = [ ] for t , i_vg in enumerate ( i_vg_list [ b ] ) : i_vg_sub = i_vg_sub_list [ b ] [ t ] pnt = pnt_idxs [ b ] [ t ] if i_vg == 0 : # sql_vocab if pnt == pnt_start_tok or pnt == pnt_end_tok : pass else : tok = tokens [ b ] [ pnt ] if tok in [ "none" , "max" , "min" , "count" , "sum" , "average" ] : agg_observed = True if tok == "none" : pass sql_i1 [ "agg" ] = [ "none" , "max" , "min" , "count" , "sum" , "average" ] . index ( tok ) else : if tok in [ "greater" , "less" , "equal" ] : if tok == 'greater' : tok = '>' elif tok == 'less' : tok = '<' elif tok == 'equal' : tok = '=' # gen conds1 if wc_obs : conds1 . append ( [ '=' , '>' , '<' ] . index ( tok ) ) wo_obs = True sql_q1_list . append ( tok ) elif i_vg == 1 : # nlu case if not nlu_st_observed : idx_nlu_st = pnt nlu_st_observed = True else : # now to wrap up idx_nlu_ed = pnt st_wh_idx = tt_to_t_idx1 [ idx_nlu_st - pnt_end_tok - 2 ] ed_wh_idx = tt_to_t_idx1 [ idx_nlu_ed - pnt_end_tok - 2 ] pr_wv_str11 = nlu_t1 [ st_wh_idx : ed_wh_idx + 1 ] merged_wv11 = merge_wv_t1_eng ( pr_wv_str11 , nlu [ b ] ) sql_q1_list . append ( merged_wv11 ) nlu_st_observed = False if wc_obs and wo_obs : conds1 . append ( merged_wv11 ) conds . append ( conds1 ) wc_obs = False wo_obs = False elif i_vg == 2 : # headers tok = hds [ b ] [ i_vg_sub ] if agg_observed : sql_q1_list . append ( f"({tok})" ) sql_i1 [ "sel" ] = i_vg_sub agg_observed = False else : wc_obs = True conds1 = [ i_vg_sub ] sql_q1_list . append ( tok ) # insert table name between. sql_i1 [ "conds" ] = conds sql_i . append ( sql_i1 ) sql_q1 = ' ' . join ( sql_q1_list ) sql_q . append ( sql_q1 ) return sql_q , sql_i