|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.vt.middleware.dictionary.TernaryTreeDictionary
public class TernaryTreeDictionary
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.
| 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 |
|---|
protected TernaryTree tree
| Constructor Detail |
|---|
public TernaryTreeDictionary(WordList wordList)
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.
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.
public TernaryTreeDictionary(WordList wordList,
boolean useMedian)
WordList.
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.public TernaryTreeDictionary(TernaryTree tt)
tt - Ternary tree used to back dictionary.| Method Detail |
|---|
public boolean search(java.lang.String word)
search in interface Dictionaryword - String to search for
boolean - whether word was foundpublic java.lang.String[] partialSearch(java.lang.String word)
TernaryTree.partialSearch(java.lang.String).
word - String to search for
String[] - of matching words
public java.lang.String[] nearSearch(java.lang.String word,
int distance)
TernaryTree.nearSearch(java.lang.String, int).
word - String to search fordistance - int for valid match
String[] - of matching wordspublic TernaryTree getTernaryTree()
TernaryTree
public static void main(java.lang.String[] args)
throws java.lang.Exception
TernaryTreeDictionary.
args - String[]
java.lang.Exception - if an error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||