Why 1 failed testcase for w1_unittest.test_get_corrections(get_corrections, probs, vocab)
?
Wrong output values.
Expected: [('say', 0.0019770955347483865), ('can', 0.0019211400007460738), ('an', 0.0017719252434065728), ('man', 0.0013242809713880702), ('son', 0.0007274219420300668)].
Got: [['wan', 1.865184466743761e-05], ['sap', 1.865184466743761e-05], ['sad', 0.00026112582534412656], ['tan', 1.865184466743761e-05], ['can', 0.0019211400007460738]].
8 Tests passed
1 Tests failed
# UNIT TEST COMMENT: Candidate for Table Driven Tests
# UNQ_C10 GRADED FUNCTION: get_corrections
def get_corrections(word, probs, vocab, n=2, verbose = False):
'''
Input:
word: a user entered string to check for suggestions
probs: a dictionary that maps each word to its probability in the corpus
vocab: a set containing all the vocabulary
n: number of possible word corrections you want returned in the dictionary
Output:
n_best: a list of tuples with the most probable n corrected words and their probabilities.
'''
suggestions = []
n_best = []
### START CODE HERE ###
#Step 1: create suggestions as described above
sets_union = (edit_one_letter(word).intersection(vocab)).union(
edit_two_letters(word).intersection(vocab))
#suggestions = list(set(sets_union))
suggestions = set(edit_one_letter(word).intersection(vocab) or edit_two_letters(word).intersection(vocab))
#Step 2: determine probability of suggestions
#Step 3: Get all your best words and return the most probable top n_suggested words as n_best
n_best = [[s,probs[s]] for s in list(reversed(list(suggestions)))]
n_best = n_best[:n]
### END CODE HERE ###
if verbose: print("entered word = ", word, "\nsuggestions = ", suggestions)
return n_best