{"id":7795,"date":"2023-11-02T18:59:11","date_gmt":"2023-11-02T13:29:11","guid":{"rendered":"https:\/\/python-programs.com\/?p=7795"},"modified":"2023-11-10T12:13:02","modified_gmt":"2023-11-10T06:43:02","slug":"program-for-spell-checker-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-for-spell-checker-in-python\/","title":{"rendered":"Program for Spell Checker in Python"},"content":{"rendered":"
Spelling errors are widespread, and most individuals are accustomed to software alerting them when they have made a mistake. Spell checking is a crucial function for many different products, from autocorrect on mobile phones to red underlining in text editors.<\/p>\n
In 1971, for the DEC PDP-10, the first spell-checking programme was built. It was known as SPELL, and it was only capable of doing simple word comparisons and detecting one or two letter deviations. Spell checkers have evolved along with hardware and software. Modern spell checkers can deal with morphology and improve suggestions using statistics.<\/p>\n
Python has a variety of libraries for this purpose, making creating a simple spell checker a 20-minute task.<\/p>\n
TextBlob is one of these libraries, which is used for natural language processing and has a simple API to work with.<\/p>\n
Explore more instances related to python concepts from Python Programming Examples<\/a> Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n Our spell-checking tool will be made up of two modules:<\/p>\n Let’s begin by installing and importing each one individually.<\/p>\n You can install the module using the pip package manager if you don’t already have it.<\/p>\n The spellchecker module must be imported before we can develop a spell checker in Python.<\/p>\n In the same method, you can install\u00a0the textblob module.<\/p>\n TextBlob is a python module for processing textual data in the Python programming language. It provides a straightforward API for tackling standard natural language processing tasks including part of speech tagging, noun phrase extraction, sentiment analysis, classification, and translation, among others.<\/p>\n correct() method:<\/strong> The correct() method is the most basic approach to correct input text.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Let’s have a look at how the spellchecker module corrects sentence faults.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n This program\u00a0will use the spellchecker instance several times. It has a big amount of words stored in it. If you input any incorrect terms that aren’t in the spellchecker dictionary, the spellchecker will correct them. So now you know everything there is to know about this library.<\/p>\n Conclusion:<\/strong><\/p>\n This was a quick overview of how to create your own spell checker using the Python programming language, which is simple to code, learn, and understand with only a few lines of code. Spelling errors are widespread, and most individuals are accustomed to software alerting them when they have made a mistake. Spell checking is a crucial function for many different products, from autocorrect on mobile phones to red underlining in text editors. In 1971, for the DEC PDP-10, the first spell-checking programme was built. It was known …<\/p>\n1)Importing Required modules for implementing spell checker<\/h3>\n
\n
C: \\Users\\Admin > pip install spellchecker<\/code><\/p>\n
C: \\Users\\Admin > pip install textblob<\/code><\/p>\n
2)Checking the spell using textblob module<\/h3>\n
from textblob import TextBlob\r\n# first we tyoe the incorrect spelling text\r\ngiven_text = \"eaars\"\r\nprint(\"The original text before spell checking = \"+str(a))\r\ncorrect_text = TextBlob(given_text)\r\n# Getting the correct text and correcting the spelling using correc() functioon\r\nprint(\"The text after correcting given text: \"+str(correct_text.correct()))\r\n<\/pre>\n
The original text before spell checking = eaars\r\nThe text after correcting given text : ears<\/pre>\n
3)Using spell checker module<\/h3>\n
# importing spellchecker library\r\nfrom spellchecker import SpellChecker\r\n\r\n# Make a spell variable and use it as a spellchecker ()\r\nspellcheck = SpellChecker()\r\n'''Construct a while loop. You must establish a variable called a word and make this variable\r\ntake real-time inputs from the user within this loop.'''\r\n\r\nwhile True:\r\n word = input('Enter a word which may be of wrong spelling')\r\n # converting the word to lower case\r\n word = word.lower()\r\n'''If the term is in the spellchecker dictionary, it will say \"you spelled correctly.\r\nOtherwise, you must choose the best spelling for that term.'''\r\n if word in spellcheck:\r\n print(\"'{}' it is spelled as correct\".format(word))\r\n else:\r\n correctwords = spellcheck.correction(word)\r\n print(\"The best spellcorrections of given words'{}' is '{}'\".format(word, correctwords))\r\n<\/pre>\n
Enter a word which may be of wrong spelling : eaars\r\nThe best spellcorrections of given word eaars is 'ears'<\/pre>\n
\nRelated Programs<\/strong>:<\/p>\n\n