Question
Use Python Your program will read the words from the dictionary into a set. All operations that check for membership of words in the dictionary
Use Python
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 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 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: letters = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'y', 'z' ] If any of these are in the dictionary, then print it as corrected with replace, and stop. For example, sockpolager can be changed to sockdolager by replacing p with d.
NO MATCH If the word is not corrected by any of the above steps, print NO MATCH.
The example:
Dictionary file => words_10pt.txt.
words_10pt.txt
Input file => input_words.txt
input_words.txt
ditrust -> ditrust :NO MATCH
catroon -> cartoon :SWAP
martial -> marital :SWAP
fridges -> fidges :DROP
throned -> thorned :SWAP
frozen -> frozen :FOUND
blizzard -> blizzard :NO MATCH
bailers -> bailors :REPLACE
ampuls -> ampul :DROP
fool -> food :REPLACE
generously -> generously :NO MATCH
ramosely -> rimosely :REPLACE
imprudences -> imprudence :DROP
thiotepa -> thiotepa :FOUND
lair -> liar :SWAP
dissatisfaktion -> dissatisfaction :REPLACE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started