org.incava.text

Class SpellChecker

Known Direct Subclasses:
NoCaseSpellChecker

public class SpellChecker
extends java.lang.Object

Calculates the edit distance between two strings.

Field Summary

protected static int
ARR_SIZE
protected static int
COMP_LEN
static int
DEFAULT_MAX_DISTANCE

Method Summary

boolean
addDictionary(String dictionary)
Adds the given dictionary.
void
addWord(String word)
protected int
compare(String str1, int len1, String str2, int len2)
Compares the two characters.
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.
int
editDistance(String str1, String str2, int maximum)
Computes the Levenstein edit distance between the two words.
String
getKey(String word)
boolean
hasWord(String word)
boolean
isCorrect(String word, Map nearMatches)
boolean
isCorrect(String word, int maxEditDistance, Map nearMatches)
protected static int
min3(int x, int y, int z)
boolean
nearMatch(String str1, String str2)

Field Details

ARR_SIZE

protected static final int ARR_SIZE
Field Value:
21

COMP_LEN

protected static final int COMP_LEN
Field Value:
20

DEFAULT_MAX_DISTANCE

public static final int DEFAULT_MAX_DISTANCE
Field Value:
4

Method Details

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,
                         Map nearMatches)

isCorrect

public boolean isCorrect(String word,
                         int maxEditDistance,
                         Map nearMatches)
Parameters:
nearMatches - a map from edit distances to matches.

min3

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

nearMatch

public boolean nearMatch(String str1,
                         String str2)