Since our application takes the input from uploading files, we need to do some basic checks if the file uploaded by the user is valid or not. We open the index() method where most of our coding is done.In our application, we will use templates to render HTML which will display in the browser. Flask uses the Jinja template library to render templates. The decorator is telling our that whenever a user visits our app domain ( localhost:5000 for local servers) at the given. Then we define the app route for the default page of our web-app which is ‘index.html’.txt), and configure the upload folder to the above path. We initialize our flask app, set a 24 digit secret key, configure the file extensions (in order to limit the file type to.For this purpose we need the username of the computer system to access files from the desktop whose path is generally in the form ofĬ:/Users/’+username+’/Desktop/ Our application must be able to upload the text file from any location of your computer, so after uploading the file to the server we save it on our desktop and later open the file for processing from the desktop itself.We import all the necessary libraries- flask, textblob, pyspellchecker, regex, getpass(to get the username of the computer) and os.The above program will not only allow you to rectify your spelling mistakes but will also provide you with a list of misspelled words and their corresponding candidate words. Finally we overwrite the text file replacing the old incorrect text with new rectified text.Before finding the misspelled words, we remove all punctuation marks from our text using regex. So we use pyspellchecker to get the list of all misspelled words, their corresponding correct words and candidate words. To correct the spellings we simply cannot rely on using only textblob’s correct method as it’s 70% accurate.We are trying to find the correct words, out of all possible candidate words, that maximizes the probability that c is the intended correction, given the original word w. There is no way to know for sure (for example, should “lates” be corrected to “late” or “latest” or “lattes” or …?), which suggests we use probabilities. TextBlob’s Spelling correction is based on Peter Norvig’s “ How to Write a Spelling Corrector”. We use the correct() method of the textblob class and print the correct text. Using the “with” keyword we open a file which has the text with spelling mistakes, read it,convert the string content into a textblob object which are just like python strings.We import the modules - Textblob, pyspellchecker, re(regex).Python Program for Spelling Correction using TextBlob & pyspellchecker Those words that are found more often in the frequency list are more likely the correct results.It supports multiple languages including English, Spanish, German, French, and Portuguese. It then compares all permutations (insertions, deletions, replacements, and transpositions) to known words in a word frequency list. It provides a consistent API for diving into common NLP tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, and more.Īccording to the official documentation, pyspellchecker is a simple spell checking algorithm which uses a Levenshtein Distance algorithm to find permutations within an edit distance of 2 from the original word. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.Īccording to the official documentation ,TextBlob is a Python (2 and 3) library for processing textual data. It is classified as a microframework because it does not require particular tools or libraries. If you are already familiar with these modules, you can directly jump to the next section.Īccording to the Wikipedia, Flask is a micro web framework written in Python. Integrate the program in a Flask Applicationīefore diving into the coding part let us first know about these modules briefly.Create a spelling rectification program in python.In this article, we will learn to create an offline Spelling Rectification Application in Python using modules like TextBlob, pyspellchecker & Flask.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |