import re


def parse_bn2cnf_variables_file(variables_filename):
    """Parses the bn2cnf variables file into a
    variable x value |-> list of literals whose conjunction corresponds to value
    map (where each literal is represented by a DIMACS CNF line)."""
    indicators = {}
    with open(variables_filename) as variables_file:
        text = variables_file.read()
    for line in re.finditer(r'(\d+) = (.+)', text):
        variable = line.group(1)
        values = [v.split(', ') for v in line.group(2)[2:-2].split('][')]
        for value in range(len(values)):
            indicators[(int(variable),
                        value)] = [l + ' 0' for l in values[value]]
    return indicators