diff --git a/backend/requirements/base.txt b/backend/requirements/base.txt index 03b1a28e..3e5e5439 100644 --- a/backend/requirements/base.txt +++ b/backend/requirements/base.txt @@ -29,4 +29,5 @@ watchfiles==0.19.0 websockets==11.0.3 sqlalchemy==2.0.19 psycopg2-binary -pytz==2023.3 \ No newline at end of file +pytz==2023.3 +pyspellchecker==0.7.2 diff --git a/model_data/utils.py b/model_data/utils.py index 744914a4..079d1849 100644 --- a/model_data/utils.py +++ b/model_data/utils.py @@ -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)