JWI is compatible with Wordnet versions 1.6 through 3.0. It is not compatible with Wordnet 1.5. Wordnet itself is not included with the JWI distribution, but rather must be downloaded separately from the Wordnet site at http://wordnet.princeton.edu.
The freely available version of JWI is licensed for use for non-commercial purposes only, as long as proper acknowledgment is made. Details can be found in the license, which is included in the distribution. The copyright on the software is owned by MIT; if you wish to use the software for commercial purposes, please contact the MIT Technology Licensing Office for more information on how to obtain a commercial license.
The entry point for accessing dictionary data is the {@code edu.mit.jwi.IDictionary} interface. JWI comes with a single default implementation of this interface in the same package, the {@code Dictionary} class. In the simplest case, where you are using Wordnet with the data files on the same filesystem as your Java program, you can instantiate the Dictionary class with a single argument, a {@code URL} object that points to the directory where the Wordnet dictionary data files are located.
An example of this can be found below, in the form of a Java method {@code runExample()}. In the method, the first block of seven lines (4-9) deals with constructing a {@code URL} object that points to the Wordnet data files. In this particular example, the base Wordnet directory is assumed to be stored in a system environment variable called WNHOME; this may be different on your system. Note that the WNHOME variable points to the root of the Wordnet installation directory and the dictionary data directory “dict” must be appended to this path. Again, this may be different on your system depending on where your Wordnet files are located. The second block of code, two lines long (12-13), constructs an instance of the default Dictionary object, and opens it by calling the {@code open()} method. The final block of six lines (16-21) demonstrates searching the dictionary for the first sense of the noun “dog”. The final numbered block of code shows the console output of the method.
Sample Dictionary code:
1 public void runExample(){ 2 3 // construct the URL to the Wordnet dictionary directory 4 String wnhome = System.getenv("WNHOME"); 5 String path = wnhome + File.separator + "dict"; 6 URL url = null; 7 try{ url = new URL("file", null, path); } 8 catch(MalformedURLException e){ e.printStackTrace(); } 9 if(url == null) return; 10 11 // construct the dictionary object and open it 12 IDictionary dict = new Dictionary(url); 13 dict.open(); 14 15 // look up first sense of the word "dog" 16 IIndexWord idxWord = dict.getIndexWord("dog", PartOfSpeech.NOUN); 17 IWordID wordID = idxWord.getWordIDs()[0]; 18 IWord word = dict.getWord(wordID); 19 System.out.println("Id = " + wordID); 20 System.out.println("Lemma = " + word.getLemma()); 21 System.out.println("Gloss = " + word.getGloss()); 22 23 }Output (for Wordnet 3.0)
1 Id = WID-2084071-n-?-dog 2 Lemma = dog 3 Gloss = a member of the genus Canis (probably descended from the common wolf) ...