Python Spell Checker Program
In this article, you will learn various ways to perform a spelling check using Python programming. To ensure good content readability and accessibility, spell checking is a very important task. The text analysis data or web contents are generally so huge that the manual spell check process becomes so difficult and time-consuming. Python provides some packages that help in spell checking and also correct them. Here, we have used two modules - TextBlob and pyspellchecker.
Python TextBlob library
The TextBlob is a natural language processing library and is basically used for processing textual data. It has several functionalities, such as tokenization, stemming, language translation, sentiment analysis, text classification, and much more. Here is the command to install the TextBlob library using the pip tool-
pip install textblob
The successful installation of this library looks as in the below screenshot-
Python Spell Checker Program using TextBlob
The correct() method of TextBlob corrects the word if any word has a spelling mistake.
# import TextBlob
from textblob import TextBlob
txt = TextBlob("Walcome to etutorialspoint. It contains lots of davelopement resourses.")
print(txt)
# correct sentence
correct_txt = txt.correct()
print(correct_txt)
>Python pyspellchecker library
The Python library pyspellchecker provides a feature to find the mis-spelled word and also provides possible correction suggestions. It is supported in both Python 3 and Python 2.7. We can use this for multiple languages, including English, German, French, Spanish, and Portuguese. Here is the command to install the pyspellchecker module using the pip tool-
pip install pyspellchecker
Python Spell Checker Program using pyspellchecker
Here, the unknown() method returns those words that are not in the frequency list. The correction() method returns the most probable result for the misspelled word and candidates() method returns a set of possible candidates for the misspelled word.
# import TextBlob
from spellchecker import SpellChecker
spell = SpellChecker()
txt = spell.unknown(["It", "contains", "lots", "of", "davelopement", "resourses"])
print(txt)
correct_txt = ""
# correct text
for x in txt:
print(spell.correction(x))
print(spell.candidates(x))
Related Articles
Remove last element from list PythonFind the stop words in nltk Python
Python program to multiply two numbers
Python program to input week number and print week day
Convert MySQL query result to JSON in Python
How to read data from excel file using Python Pandas
How to read data from excel file in Python
Python read JSON from URL requests
Python send email
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml