Hey,
Don't worry about the hash table guys but just give me some idea how to manage Strings.
I need to do spell check a word entered by the user in dictionary using hashtables. I got a method named checkDictionary() from hash tables to check whether the given word is present in dictionary or not. It returns a Boolean value if the word is present or false if not.
What I want to do is, I just want to check the word in dictionary when it is misspelled, making some possible corrections.
possible corrections :
Change one letter: For example, if the misspelled word is “kest”, i want to 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.
---How can I change a single character at a time and that too from a to z.
Exchange adjacent letters: For example, if the misspelled word is “ebst”, try “best”, esbt”
and “ebts”.
---How can I change the adjacent letters , need to swap or something?..
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”.
---How can I remove each letter every time?
GUYS!! PLEASE DO REMEMBER THAT THE WORD ENTERED MAY BE OF ANY LENGTH, like 5-20 charaters. or may be of any length.
I need to return this suggestions to the user after checking the words in dictionary.
Is there any methods in Strings that I can use.
Please help in implementing above the above methods Change, Exchange and Remove.
Java Code:
import java.util.*;
import java .io.*;
public class HashTableDemo
{
public static void main(String [] args)
{
// constructs a new empty hashtable with default initial capacity
HashTable hashtable = new HashTable();
Scanner keyboard = null;
Scanner input=null;
try
{
System.out.println("Enter a word to check in dictionary");
keyboard = new Scanner(System.in);
String word = (keyboard.nextLine().toUpperCase());
//Adding aal dictionary words from a text file to hash table.
input=new Scanner(new FileInputStream("TWL.txt"));
int i=1;
// adding value into hashtable
while(input.hasNextLine())
{
String hello = input.nextLine();
hashtable.put( hello, new Integer(i) );
i++;
}
);
if(hashtable.checkDictionary(word))
System.out.println("The word "+word+" is there in the dictionary.");
else
System.out.println("The word "+word+" is not there in the dictionary.");
}//try
//Here I need to implement the required methods if the word is not in dictionary and misspelled.
catch(FileNotFoundException e)
{
System.out.println("Cannot open file");
System.exit(0);
}//end catch
Bookmarks