org.incava.text

Class SpellChecker

public class SpellChecker extends Object

Calculates the edit distance between two strings.
Field Summary
protected static intARR_SIZE
protected static intCOMP_LEN
static intDEFAULT_MAX_DISTANCE
Method Summary
booleanaddDictionary(String dictionary)
Adds the given dictionary.
voidaddWord(String word)
protected intcompare(String str1, int len1, String str2, int len2)
Compares the two characters.
inteditDistance(String str1, String str2)
Computes the Levenstein edit distance between the two words, with a maximum of 3, at which point the distance is no longer computed.
inteditDistance(String str1, String str2, int maximum)
Computes the Levenstein edit distance between the two words.
StringgetKey(String word)
booleanhasWord(String word)
booleanisCorrect(String word, int maxEditDistance, Map nearMatches)
booleanisCorrect(String word, Map nearMatches)
protected static intmin3(int x, int y, int z)
booleannearMatch(String str1, String str2)

Field Detail

ARR_SIZE

protected static final int ARR_SIZE

COMP_LEN

protected static final int COMP_LEN

DEFAULT_MAX_DISTANCE

public static final int DEFAULT_MAX_DISTANCE

Method Detail

addDictionary

public boolean addDictionary(String dictionary)
Adds the given dictionary. Returns whether it could be read and had content.

addWord

public void addWord(String word)

compare

protected int compare(String str1, int len1, String str2, int len2)
Compares the two characters. English words should probably be case insensitive; code should not.

editDistance

public int editDistance(String str1, String str2)
Computes the Levenstein edit distance between the two words, with a maximum of 3, at which point the distance is no longer computed.

editDistance

public int editDistance(String str1, String str2, int maximum)
Computes the Levenstein edit distance between the two words.

getKey

public String getKey(String word)

hasWord

public boolean hasWord(String word)

isCorrect

public boolean isCorrect(String word, int maxEditDistance, Map nearMatches)

Parameters: nearMatches a map from edit distances to matches.

isCorrect

public boolean isCorrect(String word, Map nearMatches)

min3

protected static int min3(int x, int y, int z)

nearMatch

public boolean nearMatch(String str1, String str2)