Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I just need some help to code this. After the program terminates, there will be a new text file (new_essay.txt) with the following three lines

I just need some help to code this.

image text in transcribedimage text in transcribedimage text in transcribed
After the program terminates, there will be a new text file (new_essay.txt) with the following three lines It was the best of times. It was the worst of tims. Where does the cat go from here? Here are some further details. 1. For each "problem" encountered, which is either a misspelled word or repeated word, the program displays which line number the problem occurred and shows a snippet of the text showing the problem. The snippet of text should include the word that comes before the problem (unless it is the first word) and the word that comes after the problem (unless it is the last word in the line). The problem should be inside quotes. 2. For each problem, some options for the user must be displayed. a. The option 0 is always to make no change. b. For misspelled words, a short list (3-5) of suggested corrections will be listed. The suggested corrections will come from the common.txt file AND will also be computed (see below for details). The last option will allow the user to manually enter the correction (edit). c. For repeated words, the second option (1) will be to remove one of the repeated words. 3. The common.txt file will have common spelling mistakes and the correct word. Each line consist of two words (with whitespace between them). The first word is the misspelled word and the second word is the correct version of the word. For example, (correcting for Canadian vs American English), some lines in the file might be color colour neighbor neighbour 4. When processing a file, if the same mistake (and correction) occurs 2 or more times, then this correction should be added to the common.txt file (after the file is processed). 5. The rest of the suggested words will be determined by finding the words (from the known correct words) with the smallest Levenshtein distance to the misspelled word. The Levenshtein distance is defined as follows (image taken from wikipedia).Part 1: Text Processing [50 marks] You will create a program that allows a user to spell-check and remove repeated words in a text file. The program will do the following: Prompt the user for a text file to check (the filename) Prompt the user for a text file of known words (with correct spellings) . . Read the contents of both files Read the contents of a text file containing common mistakes (called common.txt) Process the input file line-by-line o Prompt user to correct each mistake found on each line . Prompt the user for a new name to save the corrected document o Saves the updated document in the file o Updates commont.txt with any new common mistakes . Prompt the user to repeat with new files or quit the program Details of the program are illustrated in the following example run and specifications below. Suppose we have the text file (essay.txt) consisting of the following three lines: It was the best of times. It was the blurst of tims. Where does does the cat go from here? Suppose there is also a file called spell.txt which has a collection of words (one word per line). Running the program might look like the following (yellow is used to indicate user input) Fancy Spell-Checker File to check: essay . txt File with known words [enter for default] : spell . txt Processing essay . txt Line 2: the 'blurst' of (0) 'blurst' (1) 'first' (2) 'worst' (3) 'plurst' (4) edit Option : 2 Line 2: of 'tims'. (0) 'tims' (1) 'times' (2) 'rims' (3) 'tins' (4) edit Option : 0 Line 3: Where 'does does' the (0) 'does does' (1) 'does' Option: 1 File to save updated document: new essay . txt Hit enter to continue with another file or quit exit: quitDefinition [ edit ] The Levenshtein distance between two strings a, b (of length a| and b| respectively) is given by lev(a, b) where [al if |b| = 0, 161 if a = 0, lev(a, b) = lev(tail(a), tail(b)) if a [0] = b[0] lev(tail(a), b) 1 + min

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

Students also viewed these Programming questions

Question

=+b. Determine the level of nominal output.

Answered: 1 week ago