3

I wanna build a spell correction using python and I try to use pyspellchecker, because I have to build my own dictionary and I think pyspellchecker is easy to use with our own model or dictionary. My problem is, how to load and return my word with case_sensitive is On? I have tried this:

spell = SpellChecker(language=None, case_sensitive=True)

but when I load my file contains many text like 'Hello' with this code:

spell.word_frequency.load_text_file('myfile.txt')

and when I start to spell with spell.correction('Hello') its return 'hello' (lower case). Do you know how to build our own model or dictionary with our letters not diminished or it stays uppercase?

Or if you have a recommendation for spell-checking with our own model please let me know, Thank you!

1 Answer 1

5

Try this:

from spellchecker import SpellChecker

spell = SpellChecker(language=None, case_sensitive=True)
a = spell.word_frequency.load_words(["Hello", "HELLO", "I", "AM", "Alok", "Mishra"])

# find those words that may be misspelled
misspelled = spell.unknown(["helo", "Alk", "Mishr"])

for word in misspelled:
    # Get the one `most likely` answer
    print(spell.correction(word))

    # Get a list of `likely` options
    print(spell.candidates(word))

Output:

Alok
{'Alok'}
Hello
{'Hello'}
Mishra
{'Mishra'}
Sign up to request clarification or add additional context in comments.

1 Comment

Hello, thanks for your solution. It worked! But, if we are going to save our model and then load our model that has been saved before, I got my word being lowercase automatically by pyspellchecker. I export my model using spell.export('my_custom_dictionary.gz', gzipped=True) and load my model using spell.word_frequency.load_text_file('./path-to-my-model.gz')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.