answer-grading-app / HTR /spell_and_gramer_check.py
yamanavijayavardhan's picture
Switched to pyspellchecker for simpler spell checking
be37136
raw
history blame
550 Bytes
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