from spellchecker import SpellChecker | |
spell = SpellChecker() | |
def spell_grammer(text): | |
# Split text into words | |
words = text.split() | |
# Find misspelled words | |
misspelled = spell.unknown(words) | |
# Correct misspelled words | |
corrected_words = [] | |
for word in words: | |
if word in misspelled: | |
corrected_words.append(spell.correction(word)) | |
else: | |
corrected_words.append(word) | |
# Join words back into text | |
corrected_text = ' '.join(corrected_words) | |
return corrected_text |