def check_spelling(checked_word, dist, word_list):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    s_m = student.build_scoring_matrix(alphabet, 2, 1, 0)
    result = []
    for word in word_list:
        a_m = student.compute_alignment_matrix(checked_word, word, s_m, True)
        score = student.compute_global_alignment(checked_word, word, s_m, a_m)
        changes = len(checked_word) + len(word) - score[0]
        if changes <= dist:
            result.append(word)
            print score[1], score[2]
    return result
def check_spelling(checked_word, dist, word_list):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    s_m = student.build_scoring_matrix(alphabet, 2, 1, 0)
    result = []
    for word in word_list:
        a_m = student.compute_alignment_matrix(checked_word, word, s_m, True)
        score = student.compute_global_alignment(checked_word, word, s_m, a_m)
        changes = len(checked_word) + len(word) - score[0]
        if changes <= dist:
            result.append(word)
            print score[1], score[2]
    return result
示例#3
0
    for word in checked_set:
        if word in word_dict:
            result_set.update(word_dict[word])
    result = []
    for word in result_set:
        if distance(checked_word, word, s_m) <= dist:
            result.append(word)
    return result


timer = time.time()
words = set(read_words(WORD_LIST_URL))
new_words = new_keys(words)
print len(new_words)
new_words = new_keys_dict(new_words)
print len(new_words)
#print new_keys_dict(new_keys(["cat"]))
alphabet = "abcdefghijklmnopqrstuvwxyz"
s_m = student.build_scoring_matrix(alphabet, 2, 1, 0)
print "Generating took ", time.time() - timer
timer = time.time()
print "humble", len(check_spelling("humble", 2, new_words, s_m))
print "Time :", time.time() - timer
timer = time.time()
print "firefly", len(check_spelling("firefly", 2, new_words, s_m))
print "Time :", time.time() - timer
timer = time.time()
print "fireflyfosjfoijsfoidsj", len(
    check_spelling("fireflyfosjfoijsfoidsj", 2, new_words, s_m))
print "Time :", time.time() - timer
    result_set = set([])
    for word in checked_set:
        if word in word_dict:
            result_set.update(word_dict[word])
    result = []
    for word in result_set:
        if distance(checked_word, word, s_m) <= dist:
            result.append(word)
    return result


timer = time.time()
words = set(read_words(WORD_LIST_URL))
new_words = new_keys(words)
print len(new_words)
new_words = new_keys_dict(new_words)
print len(new_words)
# print new_keys_dict(new_keys(["cat"]))
alphabet = "abcdefghijklmnopqrstuvwxyz"
s_m = student.build_scoring_matrix(alphabet, 2, 1, 0)
print "Generating took ", time.time() - timer
timer = time.time()
print "humble", len(check_spelling("humble", 2, new_words, s_m))
print "Time :", time.time() - timer
timer = time.time()
print "firefly", len(check_spelling("firefly", 2, new_words, s_m))
print "Time :", time.time() - timer
timer = time.time()
print "fireflyfosjfoijsfoidsj", len(check_spelling("fireflyfosjfoijsfoidsj", 2, new_words, s_m))
print "Time :", time.time() - timer