how can I corect word spelling by use of nltk? code example
Example 1: how can I corect word spelling by use of nltk?
from spellchecker import SpellChecker
spell = SpellChecker()
misspelled = spell.unknown(['something', 'is', 'hapenning', 'here'])
for word in misspelled:
print(spell.correction(word))
print(spell.candidates(word))
Example 2: how can I corect word spelling by use of nltk?
from textblob import TextBlob
data = "Natural language is a cantral part of our day to day life, and it's so antresting to work on any problem related to langages."
output = TextBlob(data).correct()
print(output)
Example 3: how to remove misspelled words in nltk
def edits1(word):
splits = [(word[:i], word[i:]) for i in range(len(word) + 1)]
deletes = [a + b[1:] for a, b in splits if b]
transposes = [a + b[1] + b[0] + b[2:] for a, b in splits if len(b)>1]
replaces = [a + c + b[1:] for a, b in splits for c in alphabet if b]
inserts = [a + c + b for a, b in splits for c in alphabet]
return set(deletes + transposes + replaces + inserts)