Beispiel #1
0
def builtin_shuffle(lst_in, lst_out, **kwargs):
    check_mode((lst_in, lst_out), ["Lv"], **kwargs)
    # TODO keep correct probability?
    lst_in1 = term2list(lst_in)
    random.shuffle(lst_in1)
    lst_out = term2list(lst_out)
    return [(lst_in, lst_out)]
Beispiel #2
0
def enum_groups(groups, values):
    groups_l = term2list(groups, False)
    values_l = term2list(values, False)

    grouped = defaultdict(list)

    for g, v in zip(groups_l, values_l):
        grouped[g].append(v)
    return list(grouped.items())
Beispiel #3
0
def cell_to_atoms(table_name, header, cell_row, column_type,
                  column_unique_values, cell_value, **kwargs):
    table_name = unquote(str(table_name)).lower()
    header = unquote(str(header)).lower()
    cell_row = unquote(str(cell_row)).lower()
    column_type = unquote(str(column_type)).lower()
    cell_value = unquote(str(cell_value)).lower()
    column_unique_values1 = term2list(column_unique_values)
    # print(column_unique_values1)

    row_id = table_name + "_r" + cell_row

    # result = [Term(header, Constant(row_id), Constant(cell_value))]
    result = []

    result.append((Term("row", Constant(row_id)), 1.0))

    if column_type == "string":
        for unique_value in column_unique_values1:
            if unquote(unique_value).lower() == cell_value:
                result.append((Term(header + "_" + cell_value,
                                    Constant(row_id)), 1.0))
            else:
                # WIth Probability 0
                result.append((
                    Term(
                        header + "_" + unquote(unique_value).lower(),
                        Constant(row_id),
                    ),
                    0.0,
                ))
    return result
Beispiel #4
0
def generate_cell(matrix, indices, *args, **kwargs):
    force_load(matrix, **kwargs)
    m = matrix.functor
    list_indices = term2list(indices)
    cell = m.get_cell(*list_indices)
    if cell:
        return [(matrix, indices, cell)]
    return []
Beispiel #5
0
def enum_groups(group_values):
    group_values_l = term2list(group_values, False)

    grouped = defaultdict(list)

    for gv in group_values_l:
        grouped[gv.args[0]].append(gv.args[1])
    return list(grouped.items())
Beispiel #6
0
def insert_cell(matrix, indices, value):
    list_indices = term2list(indices)
    return insert_value(matrix, list_indices, value.value)
Beispiel #7
0
def insert_str_cell(matrix, indices, value):
    list_indices = term2list(indices)
    return insert_value(matrix, list_indices, unquote(value))
Beispiel #8
0
def insert_array(matrix, index, array, axis):
    m = matrix.functor
    m.insert_parameters.append(
        (SpreadsheetMatrix.insert, index.value, term2list(array), axis))
    return ()