edu.vt.middleware.dictionary
Class TernaryTreeDictionary

java.lang.Object
  extended by edu.vt.middleware.dictionary.TernaryTreeDictionary
All Implemented Interfaces:
Dictionary

public class TernaryTreeDictionary
extends java.lang.Object
implements Dictionary

TernaryTreeDictionary provides fast searching for dictionary words using a ternary tree. The entire dictionary is stored in memory, so heap size may need to be adjusted to accommodate large dictionaries. It is highly recommended that sorted word lists be inserted using their median. This helps to produce a balanced ternary tree which improves search time. This class inherits the lower case property of the supplied word list.

Version:
$Revision: 1700 $ $Date: 2010-10-27 16:08:24 -0400 (Wed, 27 Oct 2010) $
Author:
Middleware Services

Field Summary
protected  TernaryTree tree
          Ternary tree used for searching.
 
Constructor Summary
TernaryTreeDictionary(TernaryTree tt)
          Creates a dictionary that uses the given ternary tree for dictionary searches.
TernaryTreeDictionary(WordList wordList)
          Creates a new balanced tree dictionary from the given WordList.
TernaryTreeDictionary(WordList wordList, boolean useMedian)
          Creates a new dictionary instance from the given WordList.
 
Method Summary
 TernaryTree getTernaryTree()
          Returns the underlying ternary tree used by this dictionary.
static void main(java.lang.String[] args)
          This provides command line access to a TernaryTreeDictionary.
 java.lang.String[] nearSearch(java.lang.String word, int distance)
          This will return an array of strings which are near to the supplied word by the supplied distance.
 java.lang.String[] partialSearch(java.lang.String word)
          This will return an array of strings which partially match the supplied word.
 boolean search(java.lang.String word)
          Returns whether the supplied word exists in the dictionary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tree

protected TernaryTree tree
Ternary tree used for searching.

Constructor Detail

TernaryTreeDictionary

public TernaryTreeDictionary(WordList wordList)
Creates a new balanced tree dictionary from the given WordList. This constructor creates a balanced tree by inserting from the median of the word list, which may require additional work depending on the WordList implementation.

NOTE While using an unsorted word list produces correct results, it may dramatically reduce search efficiency. Using a sorted word list is recommended.

Parameters:
wordList - List of words used to back the dictionary. This list is used exclusively to initialize the internal TernaryTree used by the dictionary, and may be safely discarded after dictionary creation.

TernaryTreeDictionary

public TernaryTreeDictionary(WordList wordList,
                             boolean useMedian)
Creates a new dictionary instance from the given WordList.

Parameters:
wordList - List of words used to back the dictionary. This list is used exclusively to initialize the internal TernaryTree used by the dictionary, and may be safely discarded after dictionary creation.

NOTE While using an unsorted word list produces correct results, it may dramatically reduce search efficiency. Using a sorted word list is recommended.

useMedian - Set to true to force creation of a balanced tree by inserting into the tree from the median of the WordList outward. Depending on the word list implementation, this may require additional work to access the median element on each insert.

TernaryTreeDictionary

public TernaryTreeDictionary(TernaryTree tt)
Creates a dictionary that uses the given ternary tree for dictionary searches.

Parameters:
tt - Ternary tree used to back dictionary.
Method Detail

search

public boolean search(java.lang.String word)
Returns whether the supplied word exists in the dictionary.

Specified by:
search in interface Dictionary
Parameters:
word - String to search for
Returns:
boolean - whether word was found

partialSearch

public java.lang.String[] partialSearch(java.lang.String word)
This will return an array of strings which partially match the supplied word. This search is case sensitive by default. See TernaryTree.partialSearch(java.lang.String).

Parameters:
word - String to search for
Returns:
String[] - of matching words

nearSearch

public java.lang.String[] nearSearch(java.lang.String word,
                                     int distance)
This will return an array of strings which are near to the supplied word by the supplied distance. This search is case sensitive by default. See TernaryTree.nearSearch(java.lang.String, int).

Parameters:
word - String to search for
distance - int for valid match
Returns:
String[] - of matching words

getTernaryTree

public TernaryTree getTernaryTree()
Returns the underlying ternary tree used by this dictionary.

Returns:
TernaryTree

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
This provides command line access to a TernaryTreeDictionary.

Parameters:
args - String[]
Throws:
java.lang.Exception - if an error occurs


Copyright © 2003-2010 Virginia Tech. All Rights Reserved.