You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defanswer_nine(entries=['cormulent', 'incendenece', 'validrate']):
# get first letter of each word with cc= [iforiincorrect_spellingsifi[0]=='c']
# calculate the distance of each word with entry and link both togetherone= [(nltk.jaccard_distance(set(nltk.ngrams(entries[0], n=3)), \
set(nltk.ngrams(a, n=3))), a) forainc]
i1= [iforiincorrect_spellingsifi[0]=='i']
two= [(nltk.jaccard_distance(set(nltk.ngrams(entries[1], n=3)), \
set(nltk.ngrams(a, n=3))), a) foraini1]
v= [iforiincorrect_spellingsifi[0]=='v']
three= [(nltk.jaccard_distance(set(nltk.ngrams(entries[2], n=3)), \
set(nltk.ngrams(a, n=3))), a) forainv]
# sort them to ascending order so shortest distance is on top.# extract the word onlyoutput= [sorted(one)[0][1], sorted(two)[0][1], sorted(three)[0][1]]
returnoutputanswer_nine()
Jaccard Distance on 4-gram
defanswer_ten(entries=['cormulent', 'incendenece', 'validrate']):
# get first letter of each word with cc= [iforiincorrect_spellingsifi[0]=='c']
# calculate the distance of each word with entry and link both togetherone= [(nltk.jaccard_distance(set(nltk.ngrams(entries[0], n=4)), \
set(nltk.ngrams(a, n=4))), a) forainc]
i1= [iforiincorrect_spellingsifi[0]=='i']
two= [(nltk.jaccard_distance(set(nltk.ngrams(entries[1], n=4)), \
set(nltk.ngrams(a, n=4))), a) foraini1]
v= [iforiincorrect_spellingsifi[0]=='v']
three= [(nltk.jaccard_distance(set(nltk.ngrams(entries[2], n=4)), \
set(nltk.ngrams(a, n=4))), a) forainv]
# sort them to ascending order so shortest distance is on top.# extract the word onlyoutput= [sorted(one)[0][1], sorted(two)[0][1], sorted(three)[0][1]]
returnoutputanswer_ten()
Edit Distance
defanswer_eleven(entries=['cormulent', 'incendenece', 'validrate']):
fromnltk.corpusimportwordscorrect_spellings=words.words()
# get first letter of each word with cc= [iforiincorrect_spellingsifi[0]=='c']
# calculate the distance of each word with entry and link both togetherone= [((nltk.edit_distance(entries[0], a)), a) forainc]
i1= [iforiincorrect_spellingsifi[0]=='i']
two= [((nltk.edit_distance(entries[1], a)), a) foraini1]
v= [iforiincorrect_spellingsifi[0]=='v']
three= [((nltk.edit_distance(entries[2], a)), a) forainv]
# sort them to ascending order so shortest distance is on top.# extract the word onlyoutput= [sorted(one)[0][1], sorted(two)[0][1], sorted(three)[0][1]]
returnoutputanswer_ten()