Spelling checker in Python

For any type of text processing or analysis, checking the spelling of the word is one of the basic requirements. This article discusses various ways that you can check the spellings of the words and also can correct the spelling of the respective word.

Using textblob library

First you need to install the library textblob using pip in command prompt.

pip install textblob

You can also install this library in Jupyter Notebook as:



filter_none

edit
close

play_arrow

link
brightness_4
code

import sys 
!{sys.executable} -m pip install textblob

chevron_right


 
Program for Spelling checker –

filter_none

edit
close

play_arrow

link
brightness_4
code

from textblob import TextBlob
  
a = "cmputr"           # incorrect spelling
print("original text: "+str(a))
  
b = TextBlob(a)
  
# prints the corrected spelling
print("corrected text: "+str(b.correct()))   

chevron_right


Output:

original text: cmputr
corrected text: computer

Using pyspellchecker library

You can install this library as below:

Using pip:

pip install pyspellchecker

In Jupyter Notebook:

filter_none

edit
close

play_arrow

link
brightness_4
code

import sys 
!{sys.executable} -m pip install pyspellchecker

chevron_right


 
Spelling Checker program using pyspellchecker –

filter_none

edit
close

play_arrow

link
brightness_4
code

from spellchecker import SpellChecker
  
spell = SpellChecker()
  
# find those words that may be misspelled
misspelled = spell.unknown(["cmputr", "watr", "study", "wrte"])
  
for word in misspelled:
    # Get the one `most likely` answer
    print(spell.correction(word))
  
    # Get a list of `likely` options
    print(spell.candidates(word))

chevron_right


Output:

computer
{'caput', 'caputs', 'compute', 'computor', 'impute', 'computer'}
water
{'water', 'watt', 'warr', 'wart', 'war', 'wath', 'wat'}
write
{'wroe', 'arte', 'wre', 'rte', 'wrote', 'write'}


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.