public class HashMapSpellingDictionary extends java.lang.Object implements SpellingDictionary
This class provides the basic methods for a spelling checker dictionary implemented using hash maps.
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 and Description |
---|
HashMapSpellingDictionary()
Create HashMapSpellingDictionary.
|
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.
|
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> metaphoneDictionary
public HashMapSpellingDictionary()
public void read(java.io.BufferedReader in) throws java.io.IOException
in
- The buffered reader.java.io.IOException
public int wordCount()
public void write(java.io.BufferedWriter out) throws java.io.IOException
out
- The buffered writer.java.io.IOException
public boolean lookupWord(java.lang.String word)
lookupWord
in interface SpellingDictionary
word
- The word to lookup.Note:
Any processing of the word (conversion to lower case, etc.) should be done before calling this routine.
public boolean addWord(java.lang.String word)
addWord
in interface SpellingDictionary
word
- The word to add to the dictionary.public boolean addWords(java.lang.String[] words)
addWords
in interface SpellingDictionary
words
- The words to add to the dictionary.public java.util.Set<java.lang.String> getRelatedWords(java.lang.String metaphone)
getRelatedWords
in interface SpellingDictionary
metaphone
- The metaphone value.public java.util.Set<java.lang.String> getAllWords()
getAllWords
in interface SpellingDictionary
public int getNumberOfWords()
getNumberOfWords
in interface SpellingDictionary
public void clear()
clear
in interface SpellingDictionary