English word spelling correction program
Java code to suggest correct English words against incorrectly spelled word.
It implements Ternary Search Tree (TST) data structure and Levenshtein Distance(LD) algorithm to suggest a list of 10 related english words sorted by Edit Distance (asc) (default-max : 3) followed by frequency(desc) of entered word in english language.
java
java -jar SpellCorrectApp.jar
java
public void setEditLimit(int)
java
public void setSuggestedWordListLimit(int)
java
public LinkedHashMap<String, Integer> correct(String) throws IllegalArgumentException
IllegalArgumentException
for blank or null String argument. It returns a LinkedHashMap<String, Integer>
object where key(String) is the suggested correct word and its value is its edit distance from the wrong word. Also, the elements in map are arranged according to edit distance(asc) and then by the frequency of that word in english language(desc).
try{
SpellCorrector spellCorrector = new SpellCorrector();
spellCorrector.setEditLimit(3); //[optional]
spell_correct.setSuggestedWordListLimit(10); //[optional]
LinkedHashMap<String, Integer> wordList = wordList = spellCorrector.correct("happyness");
System.out.println("Word\t\tDistance");
for (String word : suggestedWordMap.keySet()) {
System.out.println(word +"\t\t"+suggestedWordMap.get(word));
}
}catch (IllegalArgumentException e){
e.printStackTrace();
}