propositions[prefix_cd] = pref

    return propositions


def t9_guess(sequence, dictionary):
    """
    Create a t9 suggestion based on a dictionary built from Maupassant's book bel ami.

    Params
    ------
    sequence: String
        A sequence of numbers such as '2665687'
    dictionary: {}
        A dictionary where keys are french words and values are associated waights
    """
    propositions = build_pref_dict(dictionary)
    if sequence in propositions:
        return propositions[sequence]
    else:
        return None


if __name__ == "__main__":
    default_values = DefaultValues()
    dico = create_french_dict_from(default_values.BEL_AMI_PATH)
    inputs = read_file()
    for line in inputs:
        for seq in line.split(' '):
            print(f'Sequence: {seq}\nProposition: {t9_guess(seq, dico)}\n')
Esempio n. 2
0
    return search(T.char[w[i]], w, dist - 1, i + 1)


def spell_check(T, w):
    """Test different distance until we find a word to recommend.
    
    Params
    ------
    T: Trie structure
    w: String
        Word to correct
    """
    dist = 0
    while True:
        reco = search(T, w, dist)
        if reco != None:
            return reco
        dist += 1


if __name__ == "__main__":
    default_values = DefaultValues()
    words_list = create_words_list_from(default_values.BEL_AMI_PATH)
    T = trie(words_list)
    lines = read_file()
    for line in lines:
        words = list(map(remove_accent_from, line.lower().split(' ')))
        for w in words:
            print(spell_check(T, w))