Question

IN JAVA: Write a spell checker class that stores a set of words, W, in a...

IN JAVA: Write a spell checker class that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a Spell Check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, since it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns a list of every word in W that could be a correct spelling of s. Your program should be able to handle all the common ways that s might be a misspelling of a word in W, including swapping adjacent characters in a word , inserting a single character inbetween two adjacent characters in a word, deleting a single character from a word, and replacing a character in a word with another character. for an extra challenge, consider phonetic substitutions as well.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package mis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class SpellChecker {

   HashMap<String,ArrayList<String>> mp;
   SpellChecker(){
       //you can more list of words
       mp=new HashMap<>();
       ArrayList<String> al;
       al=new ArrayList<>();
       al.add("book");
       mp.put("book", al);
       al=new ArrayList<>();
       //all misspelled words for booke
       al.add("Broke");
       al.add("boook");
       al.add("brook");
       mp.put("boook", al);
       mp.put("booke",al);
      
       al=new ArrayList<>();
       //all misspelled words for buk
       al.add("buck");
       al.add("bulk");
       al.add("bunk");
       al.add("bud");
       al.add("bug");
       al.add("bum");
       al.add("bun");
       al.add("bus");
       al.add("but");
       mp.put("buk", al);
      
   }
   public void spellChecker(String s){
       if(!mp.containsKey(s)){
           System.out.println("This word is not in collection");
           return;
       }
      
       ArrayList<String> al=mp.get(s);
       if(al.size()>1){
           System.out.println("Word is misspelled. Here is the list of words you might be thinking");
       }
      
       for(String w:al){
           System.out.print(w+" ");
       }
       System.out.println();
   }
   public static void main(String[] args) {
       SpellChecker spellChecker=new SpellChecker();
       Scanner sc=new Scanner(System.in);
       System.out.print("Write something");
       String word=sc.next();
       spellChecker.spellChecker(word);
      

   }

}

output

Write something buk
Word is misspelled. Here is the list of words you might be thinking
buck bulk bunk bud bug bum bun bus but

Add a comment
Know the answer?
Add Answer to:
IN JAVA: Write a spell checker class that stores a set of words, W, in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a spell checker class that stores a set of words, W, in a hash table...

    Write a spell checker class that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a Spell Check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, since it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns...

  • Write a spell checker that stores a set of words, W, in a hash table and...

    Write a spell checker that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a spell check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, because it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns a...

  • create a hash table to implement spell checker in java 1. Create a file of 100...

    create a hash table to implement spell checker in java 1. Create a file of 100 words of varying length (max 8 characters). 2. All the words are in lower case. 3. design a hash table. 4. enter each word in the hash table. Once the hash table is created, run it as a spell checker.enter a word (interactive), find the word in the hash table. If not found enter an error message. Then prompt for next word. End the...

  • In C++ and not Java: Implement a spelling checker by using a hash table. Assume that...

    In C++ and not Java: 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 on which they occur. Also, for each misspelled word, list any words in the dictionary that are obtainable by applying any of the following rules: 1. Add one character. 2. Remove one character. 3. Exchange adjacent characters The...

  • 26-ary tree for spell checker in JAVA You are asked to write some functionalities for a...

    26-ary tree for spell checker in JAVA You are asked to write some functionalities for a spelling checker inside Tree.java that has at least the following methods: /*Adds a word to a spelling checker’s collection of correctly spelled words*/ void add(String word) /*Returns true if the given word is spelled correctly*/ boolean check(String word) /*Returns back all words in the tree in alphabetical order*/ public String getDictionaryInAlphabeticalOrder() Store the collection of correctly spelled words in a 26-ary tree. The number...

  • Overview: The goal of this assignment is to implement a simple spell checker using a hash...

    Overview: The goal of this assignment is to implement a simple spell checker using a hash table. You will be given the basic guidelines for your implementation, but other than that you are free to determine and implement the exact classes and methods that you might need. Your spell-checker will be reading from two input files. The first file is a dictionary containing one word per line. The program should read the dictionary and insert the words into a hash...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT