Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Autocorrect fail... How does autocorrect work? We use it almost every day. The idea behind it is very simple. If you type a word that

image text in transcribed
image text in transcribed
image text in transcribed
Autocorrect fail... How does autocorrect work? We use it almost 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 return 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 antocorrect each word To correct a single word, you will consider the following: FOUND If the word is in the dictionary, it is correct. There is no need for a change. Print it as found, and go on to the next word DROP If 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, then print the word as corrected with drop, and stop For example, quinecunx can be changed to quincunx by dropping e. SWAP Ifthe 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 a 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. Yon can hardeode a list of all letters in the alphabet for this part letters . [ 'a','b','c','d." "e",'1','g','h','i','j', 'k'. If any of these are in the dietionary, then print it as corrected with replace, and stop. For example, sockpolager can be changed to sockdolager by replacing p with d

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

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

Does it avoid use of underlining?

Answered: 1 week ago