texting pyspellchecker in lambda

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-01 18:49:45 +01:00
parent d84b463771
commit 9af1a0f6a8
2 changed files with 5 additions and 4 deletions

View file

@ -29,4 +29,5 @@ watchfiles==0.19.0
websockets==11.0.3
sqlalchemy==2.0.19
psycopg2-binary
pytz==2023.3
pytz==2023.3
pyspellchecker==0.7.2

View file

@ -1,5 +1,5 @@
import re
from textblob import TextBlob
from spellchecker import SpellChecker
# Pre-compile the regular expression
PERCENTAGE_PATTERN = re.compile(r'^\d+%?$')
@ -18,8 +18,8 @@ def correct_spelling(text):
if is_percentage_or_number(word):
corrected_words.append(word)
else:
blob = TextBlob(word) # create a TextBlob object
corrected_word = blob.correct() # use the correct method to correct spelling
spell = SpellChecker()
corrected_word = spell.correction(text)
corrected_words.append(str(corrected_word)) # convert corrected word back to string
corrected_text = ' '.join(corrected_words)