edu.northwestern.at.utils.spellcheck

## Class HashMapSpellingDictionary

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

- All Implemented Interfaces:
    SpellingDictionary
  Direct Known Subclasses:
    FileBasedSpellingDictionary, ResourceBasedSpellingDictionary

      public class HashMapSpellingDictionary
      extends java.lang.Object
      implements SpellingDictionary

  HashMapSpellingDictionary -- implements hash map based spelling dictionary.

  This class provides the basic methods for a spelling checker dictionary implemented using hash maps.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>` | `metaphoneDictionary` The dictionary keyed by metaphone values.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HashMapSpellingDictionary()` Create HashMapSpellingDictionary.

  - ### 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>` | `getAllWords()` Retrieves all words in dictionary.
    `int` | `getNumberOfWords()` Retrieves number of words in dictionary.
    `java.util.Set<java.lang.String>` | `getRelatedWords(java.lang.String metaphone)` Get list of words with a specified metaphone value.
    `boolean` | `lookupWord(java.lang.String word)` Lookup word in dictionary.
    `void` | `read(java.io.BufferedReader in)` Reads the dictionary from a buffered reader.
    `int` | `wordCount()` Counts words in the dictionary.
    `void` | `write(java.io.BufferedWriter out)` Writes the dictionary to a buffered writer.

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

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

- - ### Field Detail

    - #### metaphoneDictionary

          protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> metaphoneDictionary

      The dictionary keyed by metaphone values.

  - ### Constructor Detail

    - #### HashMapSpellingDictionary

          public HashMapSpellingDictionary()

      Create HashMapSpellingDictionary.

  - ### Method Detail

    - #### read

          public void read(java.io.BufferedReader in)
                    throws java.io.IOException

      Reads the dictionary from a buffered reader.
      Parameters:
        `in` - The buffered reader.
      Throws:
        `java.io.IOException`

    - #### wordCount

          public int wordCount()

      Counts words in the dictionary.
      Returns:
        The number of words in the dictionary.

    - #### write

          public void write(java.io.BufferedWriter out)
                     throws java.io.IOException

      Writes the dictionary to a buffered writer.
      Parameters:
        `out` - The buffered writer.
      Throws:
        `java.io.IOException`

    - #### 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 metaphone)

      Get list of words with a specified metaphone value.
      Specified by:
        `getRelatedWords` in interface `SpellingDictionary`
      Parameters:
        `metaphone` - The metaphone value.
      Returns:
        Set of words with specified metaphone value. May be empty if no words with matching metaphone value found.

    - #### 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`