com.swabunga.spell.engine

Class Word

public class Word extends Object implements Comparator

The Word object holds information for one suggested spelling. It contains both the suggested word string and the distance cost, which represents how different the suggested word is from the misspelling.

This class is now immutable.

Constructor Summary
Word(String word, int score)
Constructs a new Word.
Word()
Constructs a new Word.
Method Summary
intcompare(Object o1, Object o2)
Compares two words, mostly for the purpose of sorting words.
booleanequals(Object o)
Indicates if this word is equal to another one.
intgetCost()
A cost measures how close a match this word was to the original word
StringgetWord()
gets suggested spelling
voidsetWord(String word)
sets suggested spelling
StringtoString()
returns the suggested spelling

Constructor Detail

Word

public Word(String word, int score)
Constructs a new Word.

Parameters: word The text of a word. score The word's distance cost

Word

public Word()
Constructs a new Word.

Method Detail

compare

public int compare(Object o1, Object o2)
Compares two words, mostly for the purpose of sorting words.

Parameters: o1 the first word o2 the second word

Returns: -1 if the first word is more similar to the misspelled word
1 if the second word is more similar to the misspelled word
0 if both words are equally similar

equals

public boolean equals(Object o)
Indicates if this word is equal to another one.

Parameters: o The other word to compare

Returns: The indication of equality

getCost

public int getCost()
A cost measures how close a match this word was to the original word

Returns: 0 if an exact match. Higher numbers are worse matches.

See Also: EditDistance

getWord

public String getWord()
gets suggested spelling

Returns: the actual text of the suggest spelling

setWord

public void setWord(String word)
sets suggested spelling

Parameters: word The text to set for suggestd spelling

toString

public String toString()
returns the suggested spelling

Returns: The word's text