World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITian's, only for AI Learners.
Designed by IITian's, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Neha Kumawat
a year ago
pip install pyspellchecker
git clone https://github.com/barrust/pyspellchecker.git
cd pyspellchecker
python setup.py install
from spellchecker import SpellChecker
spell = SpellChecker()
# find those words that may be misspelled
misspelled = spell.unknown(['python','programing','langage','hapenning'])
for word in misspelled:
# most likely answer
print(spell.correction(word))
# other similar options
print(spell.candidates(word))
happenning
{'hapening', 'happenning'}
language
{'language'}
from spellchecker import SpellChecker
# loads default word frequency list
spell = SpellChecker()
spell.word_frequency.load_text_file('./my_free_text_doc.txt')
# if I just want to make sure some words are not flagged as misspelled
spell.word_frequency.load_words(['IBM', 'Wipro', 'google'])
# will return both now
spell.known(['Wipro', 'google'])
from spellchecker import SpellChecker
# set at initialization
spell = SpellChecker(distance=1)
# do some work on longer words
# set the distance parameter back to the default
spell.distance = 2
from spellchecker import SpellChecker
spell = SpellChecker()
# find those words that may be misspelled
misspelled = spell.unknown(['Let', 'us', 'wlak','on','the','groun'])
for word in misspelled:
# Get the one `most likely` answer
print(spell.correction(word))
# Get a list of `likely` options
print(spell.candidates(word))
group
{'groin', 'ground', 'groan', 'group', 'grown', 'grout'}
walk
{'walk', 'flak', 'weak'}
get
{'aet', 'ret', 'get', 'cet', 'bet', 'vet', 'pet', 'wet', 'let', 'yet', 'det', 'het', 'set', 'et', 'jet', 'tet', 'met', 'fet', 'net'}
from spellchecker import SpellChecker
# the default is English (language='en')
english = SpellChecker()
# use the Spanish Dictionary
spanish = SpellChecker(language='es')
# use the Russian Dictionary
russian = SpellChecker(language='ru')