In this shot, we will build an NLP engine that will correct the spellings of misspelled words.
We will use the Python package TextBlob to build this application. Install it using the following command:
`pip install textblob`
TextBlob is a Python library used to process text data. It provides a simple and consistent API that can perform common natural language processing tasks. These tasks include POS tagging, noun-phrase extraction, analyzing sentiments, classifying text, translating text, and much more.
Now, let’s move to the coding portion below.
from textblob import TextBlobmisspelled_words = ["Natral", "Langage", "Procesing"]corrected_words = []for word in misspelled_words:corrected_words.append(TextBlob(word).correct())print("Wrong words:", misspelled_words)print("Corrected Words:")for word in corrected_words:print(word, end=" ")
TextBlob
objects. (These objects are nothing but words converted to TextBlob
.)TextBlob
object in that empty list.TextBlob
object. We then use the correct()
method of the TextBlob
class to convert the misspelled word into its correct form.This is how you can write a Python program that corrects spelling using the TextBlob
library. This feature is convenient in Natural language processing tasks.