public class Dictionary
extends java.lang.Object
Constructor and Description |
---|
Dictionary(TokenScanner ts)
Constructs a dictionary from words provided by a TokenScanner.
|
Modifier and Type | Method and Description |
---|---|
int |
getNumWords()
Returns the number of unique words in this dictionary.
|
boolean |
isWord(java.lang.String word)
Test whether the input word is present in the Dictionary.
|
static Dictionary |
make(java.lang.String filename)
Constructs a dictionary from words from a file.
|
public Dictionary(TokenScanner ts) throws java.io.IOException
A word is any sequence of letters (see Character.isLetter) or apostrophe characters. All non-word tokens provided by the TokenScanner should be ignored.
ts
- sequence of words to use as a dictionaryjava.io.IOException
- if error while readingjava.lang.IllegalArgumentException
- if the provided reader is nullpublic static Dictionary make(java.lang.String filename) throws java.io.IOException
filename
- location of file to read words fromjava.io.FileNotFoundException
- if the file does not existjava.io.IOException
- if error while readingpublic int getNumWords()
public boolean isWord(java.lang.String word)
This check should be case insensitive. For example, if the Dictionary contains "dog" or "dOg" then isWord("DOG") should return true.
The argument to this method should only contain letters or apostrophe characters. The empty string, or strings containing only whitespace characters, are not in the dictionary. If the argument is null, the method returns false.
Calling this method should not re-open or re-read the source file.
word
- a string token to check. Assume any leading or trailing
whitespace has already been removed.