edu.northwestern.at.utils.spellcheck

## Class TernaryTrieSpellingDictionary

- java.lang.Object
- - edu.northwestern.at.utils.spellcheck.TernaryTrieSpellingDictionary

- All Implemented Interfaces:
    SpellingDictionary

      public class TernaryTrieSpellingDictionary
      extends java.lang.Object
      implements SpellingDictionary

  TernaryTrieSpellingDictionary -- implements spelling dictionary using ternary trie.

  This class provides the basic methods for a spelling checker dictionary implemented using a ternary trie.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `debug` Debugging flag.
    `protected static int` | `MAXDIFFS` Maximum edit distance.
    `protected TernaryTrie` | `trie` Holds the ternary search trie.
    `protected java.lang.String` | `wordListFileName` Word list file which populates dictionary.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TernaryTrieSpellingDictionary(java.util.List<java.lang.String> wordsList)` Create TernaryTrieSpellingDictionary from a list containing words.
    `TernaryTrieSpellingDictionary(java.util.Map<java.lang.String,java.lang.String> wordsMap)` Create TernaryTrieSpellingDictionary from a map containing words.
    `TernaryTrieSpellingDictionary(java.util.Set<java.lang.String> wordsSet)` Create TernaryTrieSpellingDictionary from a set containing words.
    `TernaryTrieSpellingDictionary(TaggedStrings wordsList)` Create TernaryTrieSpellingDictionary from a tagged strings list.
    `TernaryTrieSpellingDictionary(TernaryTrie trie)` Create TernaryTrieSpellingDictionary from an existing trie.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `addWord(java.lang.String word)` Add a word to the dictionary.
    `boolean` | `addWords(java.lang.String[] words)` Add multiple words to the dictionary.
    `void` | `clear()` Clear dictionary of all words and metaphone values.
    `java.util.Set<java.lang.String>` | `findMostSimilarSet(java.lang.String word)`
    `java.util.Set<java.lang.String>` | `getAllWords()` Retrieves all words in dictionary.
    `java.util.Set<java.lang.String>` | `getMoreRelatedWords(java.lang.String word)` Get set of words which almost match given word.
    `int` | `getNumberOfWords()` Retrieves number of words in dictionary.
    `java.util.Set<java.lang.String>` | `getRelatedWords(java.lang.String word)` Get list of words which almost match given word.
    `boolean` | `lookupWord(java.lang.String word)` Lookup word in dictionary.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### trie

          protected TernaryTrie trie

      Holds the ternary search trie.

    - #### wordListFileName

          protected java.lang.String wordListFileName

      Word list file which populates dictionary.

    - #### debug

          protected boolean debug

      Debugging flag. True to debug.

    - #### MAXDIFFS

          protected static final int MAXDIFFS

      Maximum edit distance.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TernaryTrieSpellingDictionary

          public TernaryTrieSpellingDictionary(java.util.Map<java.lang.String,java.lang.String> wordsMap)

      Create TernaryTrieSpellingDictionary from a map containing words.
      Parameters:
        `wordsMap` - Map with words to add to the dictionary.

    - #### TernaryTrieSpellingDictionary

          public TernaryTrieSpellingDictionary(java.util.Set<java.lang.String> wordsSet)

      Create TernaryTrieSpellingDictionary from a set containing words.
      Parameters:
        `wordsSet` - Set with words to add to the dictionary.

    - #### TernaryTrieSpellingDictionary

          public TernaryTrieSpellingDictionary(java.util.List<java.lang.String> wordsList)

      Create TernaryTrieSpellingDictionary from a list containing words.
      Parameters:
        `wordsList` - List with words to add to the dictionary.

    - #### TernaryTrieSpellingDictionary

          public TernaryTrieSpellingDictionary(TaggedStrings wordsList)

      Create TernaryTrieSpellingDictionary from a tagged strings list.
      Parameters:
        `wordsList` - Tagged strings list with words to add to the dictionary.

    - #### TernaryTrieSpellingDictionary

          public TernaryTrieSpellingDictionary(TernaryTrie trie)

      Create TernaryTrieSpellingDictionary from an existing trie.
      Parameters:
        `trie` - Trie to use for dictionary.

  - ### Method Detail

    - #### lookupWord

          public boolean lookupWord(java.lang.String word)

      Lookup word in dictionary.
      Specified by:
        `lookupWord` in interface `SpellingDictionary`
      Parameters:
        `word` - The word to lookup.
      Returns:
        True if the word was found in the dictionary.

        Note:

        Any processing of the word (conversion to lower case, etc.) should be done before calling this routine.

    - #### addWord

          public boolean addWord(java.lang.String word)

      Add a word to the dictionary.
      Specified by:
        `addWord` in interface `SpellingDictionary`
      Parameters:
        `word` - The word to add to the dictionary.
      Returns:
        True if word added successfully.

    - #### addWords

          public boolean addWords(java.lang.String[] words)

      Add multiple words to the dictionary.
      Specified by:
        `addWords` in interface `SpellingDictionary`
      Parameters:
        `words` - The words to add to the dictionary.
      Returns:
        True if all words added successfully.

    - #### getRelatedWords

          public java.util.Set<java.lang.String> getRelatedWords(java.lang.String word)

      Get list of words which almost match given word.
      Specified by:
        `getRelatedWords` in interface `SpellingDictionary`
      Parameters:
        `word` - The word for which to find similar words.
      Returns:
        Set of words which are similar to specified word.

    - #### findMostSimilarSet

          public java.util.Set<java.lang.String> findMostSimilarSet(java.lang.String word)

    - #### getAllWords

          public java.util.Set<java.lang.String> getAllWords()

      Retrieves all words in dictionary.
      Specified by:
        `getAllWords` in interface `SpellingDictionary`
      Returns:
        ArrayList of all words in dictionary.

    - #### getNumberOfWords

          public int getNumberOfWords()

      Retrieves number of words in dictionary.
      Specified by:
        `getNumberOfWords` in interface `SpellingDictionary`
      Returns:
        Number of words in dictionary.

    - #### clear

          public void clear()

      Clear dictionary of all words and metaphone values.
      Specified by:
        `clear` in interface `SpellingDictionary`

    - #### getMoreRelatedWords

          public java.util.Set<java.lang.String> getMoreRelatedWords(java.lang.String word)

      Get set of words which almost match given word.
      Parameters:
        `word` - The word for which to find similar words.
      Returns:
        Set of words which are similar to specified word.