Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spell Correction with Python (pyspellchecker)

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!

like image 807
Hermawan Wiwid Avatar asked Dec 09 '25 01:12

Hermawan Wiwid


1 Answers

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'}
like image 111
Alok Mishra Avatar answered Dec 10 '25 15:12

Alok Mishra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!