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)
Tests whether the argued word is present in this Dictionary.
|
static Dictionary |
make(java.lang.String filename)
Constructs a Dictionary from words from a file.
|
public Dictionary(TokenScanner ts)
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 store in this Dictionaryjava.lang.IllegalArgumentException
- If the provided token scanner is nullpublic static Dictionary make(java.lang.String filename) throws java.io.IOException
filename
- Location of file from which to read wordsjava.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.
Calling this method must 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.