Class WordTree

java.lang.Object
  extended by WordTree

public class WordTree
extends java.lang.Object

The WordTree class is an efficient data structure for storing a dictionary of words and quickly checking to see if particular strings are contained in the dictionary, or if they are prefixes of words in the dictionary. Lookup times scale linearly with the length of the string being searched for and do not depend on the size of the dictionary. The data structure is inspired by http://nifty.stanford.edu/2006/reges-anagrams/ which refers to: http://www.ssynth.co.uk/~gay/anagabout.html

Version:
V1.0 03/2012
Author:
Nathan Sprague

Constructor Summary
WordTree(java.lang.String fileName)
          Construct a WordTree.
 
Method Summary
 boolean isWord(java.lang.String string)
          Return true if the argument is a word, false otherwise.
 int longestWord(java.lang.String startString)
          Return the length of the longest word that begins with the indicated string.
 int numWords(java.lang.String startString)
          Return the number of words that begin with the indicated string.
 void printWords()
          Print all of the words stored in the tree.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WordTree

public WordTree(java.lang.String fileName)
         throws java.io.FileNotFoundException
Construct a WordTree.

Parameters:
fileName - Location of the word file.
Throws:
java.io.FileNotFoundException
Method Detail

printWords

public void printWords()
Print all of the words stored in the tree. (This is just for debugging.)


longestWord

public int longestWord(java.lang.String startString)
Return the length of the longest word that begins with the indicated string. An empty string argument will return the length of the longest word overall. If there are no words that start with this string, then 0 will be returned.

Parameters:
startString - A string that may start some number of words.
Returns:
The length of the longest word that starts with startString.

numWords

public int numWords(java.lang.String startString)
Return the number of words that begin with the indicated string. An empty string argument ("") will return the total number of words. If there are no words that begin with this string, 0 will be returned.

Parameters:
startString - A string that may start some number of words.
Returns:
The number of words that begin with startString.

isWord

public boolean isWord(java.lang.String string)
Return true if the argument is a word, false otherwise.

Parameters:
string - String which may or may not be a word.
Returns:
True if the argument is a word, false otherwise.