Beispiel #1
0
def is_valid(rule_label, col_table_dict, sql):
    try:
        lf.build_tree(copy.copy(rule_label))
    except:
        print(rule_label)

    flag = False
    for r_id, rule in enumerate(rule_label):
        if type(rule) == C:
            try:
                assert rule_label[r_id + 1].id_c in col_table_dict[rule.id_c], print(sql['question'])
            except:
                flag = True
                print(sql['question'])
    return flag is False
def adjust(action_seq, current_obj):
    '''
    action_seq:目前模型已经生成的action序列,类型不是字符串
    current_obj:当前的object action序列,类型不是字符串
    return:新的object action序列
    # current_obj需要调整的也就是把action_o为根的子树换成以action_p为根的子树
    '''

    if (action_seq[-1] == current_obj[len(action_seq) - 1]):
        return current_obj

    already_correct = action_seq[0:-1]
    action_p = action_seq[-1]
    # action_o = current_obj[len(already_correct)]
    current_obj_tree = build_tree(current_obj)  # 建成了树的结构
    node_lst = []
    preorder_travel_all(current_obj_tree, node_lst)

    selected_C = []
    for node in node_lst:
        if (isinstance(node, C)):
            selected_C.append(node)

    node_o = node_lst[len(already_correct)]
    p_children = action_p.get_next_action()
    o_children = node_o.children
    p_plus_children_type = []
    for p_child in p_children:
        flag = 0
        for i in range(len(o_children) - 1, -1, -1):
            if (isinstance(o_children[i], p_child)):
                o_children[i].set_parent(action_p)
                action_p.add_children(o_children[i])
                o_children.pop(i)
                flag = 1
                break
        if (flag == 0):
            p_plus_children_type.append(p_child)

    new_children = derive(p_plus_children_type, selected_C)
    for new_child in new_children:
        new_child.set_parent(action_p)
        action_p.add_children(new_child)

    parent = node_o.parent
    parent.children.remove(node_o)
    action_p.set_parent(parent)
    parent.add_children(action_p)

    new_node_lst = []
    preorder_travel_all(current_obj_tree, new_node_lst)
    # print(new_node_lst)

    return new_node_lst