Reputation: 561
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!
Upvotes: 3
Views: 6882
Reputation: 704
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'}
Upvotes: 5