Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a spelling checker by using a hash table. Assume that the dictionary c

ID: 3684194 • Letter: I

Question

Implement a spelling checker by using a hash table. Assume that the dictionary comes from two sources: an existing large dictionary and a second file containing a personal dictionary. Output all misspelled words and the line numbers in which they occur. Also, for each misspelled word, list any words in the large dictionary that are obtainable by applying any of the following rules: a) Add one character. b) Remove one character. c) Exchange adjacent characters.

Implement this problem as described with the exception of the secondary dictionary. Your program, called SpellChecker.java should take two command line arguments, the dictionary (provided here as words.txt), and the text that you wish to spellcheck. Provide some sample text. Your program should be case insensitive (so you can toLower everything). Numbers and contractions are considered valid words. You may use the java HashTable or HashMap to implement this program; but it must use some kind of hash table.

Explanation / Answer

You make a good effort at breaking up the methods and separating concerns, but I would take it a step further. The methods that build alternate spellings should not be responsible for checking the dictionary. Instead, combine all misspellings into a single list and search the dictionary in one place. This also allows you to remove duplicates and avoid wasted lookups. private void printStatusAndSuggestions(String input) { System.out.println(); System.out.print(input); if (dict.contains(input) { System.out.println(" is spelled correctly."); } else { System.out.print(" is not spelled correctly,"); printSuggestions(suggest(input)); } } private void printSuggestions(Set suggestions) { if (suggestions.isEmpty()) { System.out.println(" and I have no idea what word you could mean." } else { ... print them ... } } private Set suggest(String input) { Set suggestions = new HashSet(); Set alternates = makeAlternates(input); for (String alternate : alternates) { if (dict.contains(alternate) { suggestions.add(alternate); } } return suggestions; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote