Python Programming Examples Tutorial Index

Python Function Programs

This Python program displays spelling correction features using the TextBlob Python library. TextBlob Python has a comprehensive library that simplifies text processing. It provides simple APIs for common natural language (NLP) such as tokenization, noun phrase extraction, part-speech tagging, n-grams, sentiment analysis, spelling correction, translation, language detection, text classification, etc.



In this Python program, we used the library's spelling correction feature. It is an excellent feature that TextBlob offers. With the help of this, if there is a spelling error in a sentence, it can be rectified. As shown below, we can access it using the "correct" function:

Example:

Python program to automatically correct spelling:

# Import TextBlob
from textblob import TextBlob
 
txt = TextBlob("I loev my ieda.")
 
# using correct() method
txt = txt.correct()
 
print(txt)

Output:

I love my idea.

Another example shows this feature in other ways:

Example:

Python program to automatically correct spelling:

from textblob import TextBlob

def Convert(string):
    li = list(string.split())
    return li

str1 = input("Please enter some misspelled texts: ")
words=Convert(str1)

corrected_words = []
for i in words:
    corrected_words.append(TextBlob(i))
    
print("Words are:", words)
print("Corrected Words are:")
for i in corrected_words:
    print(i.correct(), end=" ")

Output:

Please enter some misspelled texts: A uniuqe problm-solving idea can make lief easier for many.
Words are: ['A', 'uniuqe', 'problm-solving', 'idea', 'can', 'make', 'lief', 'easier', 'for', 'many.']
Corrected Words are:
A unique problem-solving idea can make life easier for many.

Install TextBlob

The TextBlob Python library can be installed using pip (package manager for Python). The following command installs the TextBlob package:

pip install textblob


Found This Useful? Share This Page!