Question
The goal of this assignment is to spell check a single word. You will use a dictionary le in order to decide if a word
The goal of this assignment is to spell check a single word. You will use a dictionary file in order to decide if a word is correct. I provide two dictionary files small-dictionary.txt and dictionary.txt which contains one word per line (in English). You will use input redirection to redirect the dictionary file into your program (that means your program will read from standard input), and store each word in an array of strings. There are 80368 words in the large dictionary I provide. Your array of strings will be declared as a static two-dimensional array of characters. You may assume that the longest word in the dictionary has 50 characters. The user will enter a word as a command line argument using the flag -w word The goal of the spell-checker is to determine if the given word is misspelled and output a list of possible corrections.
Possible Corrections: If the word you are looking for is not in the dictionary, assume that it is misspelled. To suggest corrections, for each misspelled word, list any words in the dictionary that are obtainable by any of the following rules. • Change one letter: For example, if the misspelled word is “kest”, try all possibilities of changing one character at a time, and look the modified word up in the dictionary. The possibilities will be “aest”, “best”,...,”zest”, “kast”,...,”kzst”, etc. • Exchange adjacent letters: For example, if the misspelled word is “ebst”, try “best”, esbt” and “ebts”. • Remove one letter: For example, if the misspelled word is “tbird”, try all possibilities of removing one letter at a time, and look the modified word up in the dictionary, which are: “bird”, “tird”, “tbrd”, and “tbir”.
Note that, you have to try all possibilities, but only the ones that are actually found in the dictionary are possible corrections to be suggested. For each word you generate, look it up in the dictionary, if found, print it to standard output. Note that, the dictionary is sorted, and you SHOULD use binary search when looking up a word (much faster than sequential search). You are NOT allowed to use any functions from string.h. You should write your own string comparison function and any other function you need. If the given word is spelled correctly, just output ”Spelled correctly.” If the given word is misspelled, generate a single output line printing ”Misspelled. Suggestions:” followed by the list of possible corrections separated by commas. For example:
1
$ hw2 -w ebst < dictionary.txt Misspelled. Suggestions: best, east, erst $ hw2 -w best < dictionary.txt Spelled correctly.
When testing, use the small dictionary file, and if it works then start using the larger dictionary file.
Part 2. Now, update your homework in Part 1 to add other options as described below.
• Add the flag -h, which prints out a Unix-like manual page informing the user how to use your program and its arguments. Also print this screen whenever improper input has been detected. Also, if there is a -h flag, it cancels out all others, i.e. help screen will be printed and nothing else. • Add the flag -c, which prints only the possible corrections due to changing one letter. $hw2 -w ebst -c < dictionary.txt Misspelled. Suggestions: east, erst • Add the flag -e, which prints only one possible corrections due to exchanging adjacent letters
$hw2 -w ebst -e < dictionary.txt Misspelled. Suggestions: best • Add the flag -r, which prints only one possible corrections due to removing one letter. $hw2 -w tbird -r < dictionary.txt Misspelled. Suggestions: bird • These flags may be combined. $hw2 -w ebst -e -c < dictionary.txt Misspelled. Suggestions: best, east, erst
$hw2 -w ebst -ec < dictionary.txt Misspelled. Suggestions: best, east, erst
• These flags can come in any order, i.e. -e -c -w ebst is equivalent to -c -w ebst -e. Any or all flags may be omitted. If no flags are given, default is -h. If only -w flag is given (followed by a word) all possible corrections will be printed (as described in part 1) • Note that the input redirection part of the command is NOT considered a command line argument. For now, we will input the dictionary through input redirection, later you may update this program to directly read from a file (after we learn file I/O).
use c programming
Step by Step Solution
3.56 Rating (146 Votes )
There are 3 Steps involved in it
Step: 1
Ans swer import javaio import javautil import javautilregex public class spellcheckercode Hashtable dictionary boolean suggestWord public static void ...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