import codecs


def _read_tuple_list_to_dict(path):
    """
        Reads a file into a dictionary. 
        The file must have the following format:
        key1 key2 value
        Then the dictionary is of the form:
        {(key1,key2):value}
    """
    with codecs.open(path, 'r', encoding="utf-8") as bigram_file:
        all_lines = bigram_file.readlines()
        lines = [l.rstrip() for l in all_lines]
        # create dict
        p_bigrams = {}
        for l in lines:
            parts = l.split(" ")
            if len(parts) == 3:
                if parts[0] != "" and parts[1] != "":
                    p_bigrams[(parts[0], parts[1])] = float(parts[2])
    return p_bigrams