Tutorial on WordNet Using the WordNet Linguistic Database

I find the WordNet book WordNet: An Electronic Lexical Database Language, Speech, and Communication by Christiane Fellbaum, 1998 to be a detailed refer- ence for WordNet but there have been several new releases of WordNet since the book was published. The WordNet site and the Wikipedia article on WordNet are also good sources of information if you decide to make WordNet part of your toolkit: http:wordnet.princeton.edu http:en.wikipedia.orgwikiWordNet We will Brett’s open source Java WordNet utility library in the next section to ex- periment with WordNet. There are also good open source client applications for browsing the WordNet lexical database that are linked on the WordNet web site.

9.3.2 Example Use of the JAWS WordNet Library

Assuming that you have downloaded and installed WordNet on your computer, if you look at the data files themselves you will notice that the data is divided into index and data files for different data types. The JAWS library and other WordNet client libraries for many programming languages provides a useful view and convenient access to the WordNet data. You will need to define a Java property for the location of the raw WordNet data files in order to use JAWS; on my system I set: wordnet.database.dir=Usersmarkwtempwordnet3dict The example class W ordN etT est finds the different word senses for a given word and prints this data to standard output. We will tweak this code slightly in the next section where we will be combining WordNet with a part of speech tagger in another example program. Accessing WordNet data using Brett’s library is easy, so we will spend more time actually looking at the WordNet data itself. Here is a sample program that shows how to use the APIs. The class constructor makes a connection to the WordNet data files for reuse: public class WordNetTest { public WordNetTest { database = WordNetDatabase.getFileInstance; } Here I wrap a JAWS utility method to return lists of synsets instead of raw Java arrays: 145 public ListSynset getSynsetsString word { return Arrays.asListdatabase.getSynsetsword; } public static void mainString[] args { The constant P ropertyN ames.DAT ABASE DIRECT ORY is equal to “word- net.database.dir.” It is a good idea to make sure that you have this Java property set; if the value prints as null, then either fix the way you set Java properties, or just set it explicitly: System.setPropertyPropertyNames.DATABASE_DIRECTORY, Usersmarkwtempwordnet3dict; WordNetTest tester = new WordNetTest; String word = bank; ListSynset synset_list = tester.getSynsetsword; System.out.println\n\n Process word: + word; for Synset synset : synset_list { System.out.println\nsynset type: + SYNSET_TYPES[synset.getType.getCode]; System.out.println definition: + synset.getDefinition; word forms are synonyms: for String wordForm : synset.getWordForms { if wordForm.equalsword { System.out.println synonym: + wordForm; Antonyms are the opposites to synonyms. Notice that antonyms are specific to indi- vidual senses for a word. This is why I have the following code to display antonyms inside the loop over word forms for each word sense for “bank”: antonyms mean the opposite: for WordSense antonym : synset.getAntonymswordForm { for String opposite : antonym.getSynset.getWordForms { System.out.println antonym of + wordForm+: + opposite; } } } } 146