Class DictionaryBase

  • Direct Known Subclasses:
    Dictionary

    abstract class DictionaryBase
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int idx  
      protected static char LAST_CHAR  
      protected int size  
      protected char[] tree  
    • 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • tree

        protected char[] tree
      • size

        protected int size
      • idx

        protected int idx
    • Constructor Detail

      • DictionaryBase

        DictionaryBase​(char[] tree)
      • DictionaryBase

        protected DictionaryBase()
        Empty Constructor.
    • 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 words
        chars - until charPosition already map characters, after the part of the original word that still need to map.
        charPosition - character position in char array
        lastIdx - position in the index (dictionary) to the current character position
        diff - 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 variable idx 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 char
        b - second char
        Returns:
        the dissimilarity