Package com.inet.jortho
Class DictionaryBase
- java.lang.Object
-
- com.inet.jortho.DictionaryBase
-
- Direct Known Subclasses:
Dictionary
abstract class DictionaryBase extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DictionaryBase()
Empty Constructor.(package private)
DictionaryBase(char[] tree)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
charDiff(char a, char b)
Returns an int that describe the dissimilarity of the characters.boolean
exist(java.lang.String word)
Check if the word exist in this dictinary.private boolean
isWordMatch()
Check if on the current item position a word ends.(package private) int
readIndex()
Read the offset in the tree of the next character.private boolean
searchChar(char c)
Search if the character exist in the current node.private void
searchSuggestions(Suggestions list, java.lang.CharSequence chars, int charPosition, int lastIdx, int diff)
It will search with different rules for similar words.java.util.List<Suggestion>
searchSuggestions(java.lang.String word)
Returns a list of suggestions if the word is not in the dictionary.private void
searchSuggestionsLonger(Suggestions list, java.lang.CharSequence chars, int lastIdx, int diff)
-
-
-
Field Detail
-
tree
protected char[] tree
-
size
protected int size
-
idx
protected int idx
-
LAST_CHAR
protected static final char LAST_CHAR
- See Also:
- Constant Field Values
-
-
Method Detail
-
exist
public boolean exist(java.lang.String word)
Check if the word exist in this dictinary.- Parameters:
word
- the word to check. Can't be null.- Returns:
- true if the word exist.
-
searchSuggestions
public java.util.List<Suggestion> searchSuggestions(java.lang.String word)
Returns a list of suggestions if the word is not in the dictionary.- Parameters:
word
- the wrong spelled word. Can't be null.- Returns:
- a list of class Suggestion.
- See Also:
Suggestion
-
searchSuggestions
private void searchSuggestions(Suggestions list, java.lang.CharSequence chars, int charPosition, int lastIdx, int diff)
It will search with different rules for similar words. For every rule there are a different difference. The smaller the difference that so similarer. This method is calling recursive it self.- Parameters:
list
- Container for found wordschars
- until charPosition already map characters, after the part of the original word that still need to map.charPosition
- character position in char arraylastIdx
- position in the index (dictionary) to the current character positiondiff
- the dissimilar up to the current character position
-
searchSuggestionsLonger
private void searchSuggestionsLonger(Suggestions list, java.lang.CharSequence chars, int lastIdx, int diff)
-
searchChar
private boolean searchChar(char c)
Search if the character exist in the current node. If found then the variableidx
point to the location. If not found then it point on the next character (char value) item in the node.- Parameters:
c
- the searching character- Returns:
- true if found
-
isWordMatch
private boolean isWordMatch()
Check if on the current item position a word ends.
-
readIndex
final int readIndex()
Read the offset in the tree of the next character.
-
charDiff
private int charDiff(char a, char b)
Returns an int that describe the dissimilarity of the characters. The value is ever larger 0. A value of means only a small difference.- Parameters:
a
- first charb
- second char- Returns:
- the dissimilarity
-
-