Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What is the environment we are trying to create?

Answered: 1 week ago