Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python code please Autocorrect fail. How does autocorrect work? We use it amost every day. The idea behind it is very simple. If you type

Python code please
image text in transcribed
image text in transcribed
Autocorrect fail. How does autocorrect work? We use it amost every day. The idea behind it is very simple. If you type a word that is not in my dictionary, I go through all possible ways you could have misspelled a word (within reason) and check whether any of the corrections of misspellings is in my dictionary if so I returm it as my prediction Fair warning: we will solve a simplified version of autocorrect in this part. You must use sets. We will revisit the same problem in Homework #7 with a more complex solution using dictionaries You will be able to reuse most of what you write here at that time, so spend some time to structure your code well, and use functions to make it more modular. Think about the future you of a week from now trying to read and modify your code, and be nice to that person To solve this problem, your program will read the name of two files: the first containing a dictionary of words and the second containing a list of words to autocorrect. Both files have a single word per line. Your program will read the words from the dictionary into a set. All operations that check for membership of words in the dictionary or for finding the common words within a dictionary must be done with sets. Your program will then go through every single word in the input file and autocorrect each word. To correct a single word, you will consider the following FOUND If the word is in the dictionary, it is correct. There no need for a change. Print it as found, and go on to the next word. DROP I the word is not found, consider all possible ways to drop a single letter from the word. If any of them are in the dictionary, them print the word as corrected with drop, and stop. For example, quinecunx can be changed to quincunx by dropping e SWAP If the word is not yet corrected, consider all possible ways to swap two consecutive letters from the word. If any of one of these in the dictionary, then print the word as corrected with swap, and stop. For example, serednipity can be transformed to serendipity by swapping the letters d and n REPLACE If the word is not yet corrected, consider all possible ways to change a single letter in the word with any other letter from the alphabet. You can hardcode a list of all letters in the alphabet for this part: If any of these are in the dictionary, then print it as corrected with replace, and stop. For example, sockpolager can be danged to sockdolager by replacing p with d. NO MATCH If the word is not corrected by any of the above steps, print NO MATCH Autocorrect fail. How does autocorrect work? We use it amost every day. The idea behind it is very simple. If you type a word that is not in my dictionary, I go through all possible ways you could have misspelled a word (within reason) and check whether any of the corrections of misspellings is in my dictionary if so I returm it as my prediction Fair warning: we will solve a simplified version of autocorrect in this part. You must use sets. We will revisit the same problem in Homework #7 with a more complex solution using dictionaries You will be able to reuse most of what you write here at that time, so spend some time to structure your code well, and use functions to make it more modular. Think about the future you of a week from now trying to read and modify your code, and be nice to that person To solve this problem, your program will read the name of two files: the first containing a dictionary of words and the second containing a list of words to autocorrect. Both files have a single word per line. Your program will read the words from the dictionary into a set. All operations that check for membership of words in the dictionary or for finding the common words within a dictionary must be done with sets. Your program will then go through every single word in the input file and autocorrect each word. To correct a single word, you will consider the following FOUND If the word is in the dictionary, it is correct. There no need for a change. Print it as found, and go on to the next word. DROP I the word is not found, consider all possible ways to drop a single letter from the word. If any of them are in the dictionary, them print the word as corrected with drop, and stop. For example, quinecunx can be changed to quincunx by dropping e SWAP If the word is not yet corrected, consider all possible ways to swap two consecutive letters from the word. If any of one of these in the dictionary, then print the word as corrected with swap, and stop. For example, serednipity can be transformed to serendipity by swapping the letters d and n REPLACE If the word is not yet corrected, consider all possible ways to change a single letter in the word with any other letter from the alphabet. You can hardcode a list of all letters in the alphabet for this part: If any of these are in the dictionary, then print it as corrected with replace, and stop. For example, sockpolager can be danged to sockdolager by replacing p with d. NO MATCH If the word is not corrected by any of the above steps, print NO MATCH

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions