Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java program Overview In this assignment, you will write a simple spell-checker. Your program should be named Spell and take two file names as command-line
Java program
Overview In this assignment, you will write a simple spell-checker. Your program should be named Spell and take two file names as command-line arguments. Your program will be invoked from the command line as Spell dictionary.txt fileTocheck.txt The first file name is the dictionary with correctly spelled words, which I provide. The second file is the text to be spell-checked. Your program should check all words in fileToCheck.txt. Nothing needs to be done for words that are correctly spelled, i.e. those found in the dictionary file. Your program should suggest possible correct spellings for words not in the dictionary file by printing to the standard output. You should perform the following modifications of a misspelled word to handle commonly made mistakes: - Letter substitution: iterate over characters in the misspelled word, trying to replace the current character with a different character. For example, in a misspelled word' lat', substituting' c instead of' I' will produce the word' cat' in a dictionary. There are 25 different characters to try for the current character. Thus, if the length of a word is k characters, the number of modifications to try is 25k. - Letter omission: try to omit (in turn, one by one) a single character in the misspelled word and check if the resulting new word is in the dictionary. For example, if the misspelled word is' catt', omitting the last character' t' will produce the word' cat' in the dictionary. In this case, there are k modifications to try where k is the number of characters in the word. - Letter insertion: try to insert a letter in the misspelled word. For example, for' plce', inserting' a' after' l' produces a correctly spelled word' place'. If a word is k characters long, there are 26(k+1) modifications to try since there are 26 characters to insert and k+1 places (including in the beginning and at the end of the word) to insert a character. - Letter reversal: Try swapping every pair of adjacent characters. For example, in' paernt', swapping' e' and' r ' produces a correctly spelled word' parent'. For a word of length k, there are k1 pairs to swap. Example Input and Output File 'toydictionary.txt' contains the words: cats, like, on, of, to, play And file 'filetocheck.txt' contains the words: Catts lik o play The output of Spell toydictionary.txt fileToCheck. txt is as follows: catts: Incorrect Spelling catts cats lik: Incorrect Spelling lik > like o: Incorrect Spelling 0 to, of, on play: Correct Spelling Each misspelled word should be placed on a new line. The list of suggested correct spelling may not contain repeated words. In the example above, for the misspelled word' catts', removing the first' t' or the second' t' leads to the same word' cats', but' cats' should appear in the output only once. If no modification of the word produces a correctly spelled word, your program should print out "no suggestions" for that word. Implementation You are to implement the program based on a dictionary data structure. First, your program should read all words from the input dictionary file (specified by the first command line argument) and insert them into a dictionary data structure, let us call it D. Then your program should open the second file (containing the text to be spell-checked). As you read words from the second file, if any word is not in D, that means it is a misspelled word that needs to be handled. You must try all possible modifications of the word outlined in the 'overview' section. It's expected that your implementation will convert all words into lowercase so that the words 'Cat' and' cat' are treated the same. Thus, all the words you read from a file using your program will be lowercase. Provided Files - Spell.java: A template that you can use as a starting point to implement your program. You might find the comments in the file useful. However, feel free to use such a template or come up with your own Spell.java file. - TestHashDictionary.java: This is a program the TA will use to test your implementation. Compile and run it after you have implemented your program. It will run some tests and let you know which tests are passed/failed. Each test is worth 4 marks. - toyDictionary.txt: Use it as demonstrated above - dictionary.txt: This is a larger dictionary file that contains 10,000 words. - fileTocheck.txt: Use it as demonstrated above Note: All files are hosted under OWL-> Resources -> Assignments -> Assignments 2Step 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