The George Washington University JWord 2.0


How to Write a JWord Driver

Writing a JWord Driver is pretty straight forward. We tried to write all of our drivers with three layers in mind:
1. Pulling from a database or File
This layer should specifically try to parse out or fetch information from the dictionary and put it into a data structure that is more easily understood by the rest of the driver. For example our WordNet driver has an entire set of libraries it calls to retrieve data from the WordNet dictionary files.

2. Splitting this Information Up
JWord displays data in a MutableTreeNode, thus the underlying data structure is basically a tree. Most drivers should separate words out by Part of Speech, then groupings by some general word or phrase, then it will display all of the matching word results. Back to our WordNet Driver, our tree displays Noun -> Some Phrases -> Each Phrase has several matching words under it

3. Displaying to the Screen
You must extend JWordNode and implement its functions to display your results to the screen. Most nodes will simply contain text to display, however the JWordNode allows for a second location (the bottom bar) to display additional infromation such as example sentences.

All three components must be designed carefully to work together to bring results to the screen quickly.

1. Extend JWordDriver
Click the above link to view the javadoc on the JWordDriver.

There are 4 methods to override in your driver.
getTitle is pretty straight forward, this will be the title JWord displays when it shows your results.
initDictionary should load or open any files that search calls will make. This will be the first function called by JWord, and it will only be called once, when the dictionary is loaded.
returnPOS draws the tree from the starting point of a particular part of speech
returnSearch draws the entire result tree.

returnPOS and returnSearch basically have the same underlying code
Here is some pseudocode to work with:

returnSearch(javax.swing.tree.DefaultMutableTreeNode root, java.lang.String searchWord)
1. Call the Function to Get all of the results of the searchWord
2. Call the Function to Put those results into a tree
3. For each Part of Speech
3.1 Create a DefaultMutableTreeNode("Part of Speech")
3.2 For each group of words

3.2.1 Create a JWordNode(Display Information, Additional Information)
3.2.2 For each Word in the group of words

3.2.2.1 Create a DefaultMutableTreeNode or a JWordNode depending on how much information we wish to display
3.2.2.2 Add this node as a child of the node created in 3.2.1

3.2.3 Add this node as a child of the node created in 3.1
3.3 Add this node as a child of root

2. Extend JWordNode
Click the link above to view the Javadoc for JWordNode
JWordNodes are what actually gets drawn to the JTree in JWord.

There are 3 methods to override for JWordNodes.
toString should be implemented to add HTML tags to the current string, plus it should bold and italicize the current word being searched for if its found in the string displayed. This is what is displayed in the string
getCurrentDescription and getDescription display information in the bottom yellow bar. getCurrentDescription should be used for the leaves and getDescription should be used for parent nodes.

3. Add information to drivers.props
numDrivers=4 #<-- Change to Number of Drivers
driver.0=edu.gwu.jworddrivers.WordNetDriver
driver.1=edu.gwu.jworddrivers.RogetDriver
driver.2=edu.gwu.jworddrivers.RogetwithLemmaDriver
driver.3=edu.gwu.jworddrivers.RootBookDriver
#driver.4=edu.gwu.edu.jworddrivers.YourDriverName

Make sure to add your class files to the jworddrivers folder on your filesystem as well!

Congratulations, you are now ready to write a driver for JWord.