What is JWordNet?

JWordNet is a pure Java standalone object-oriented interface to the WordNet database of lexical relationships. It is intended for Java programmers who wish to write portable Java applications that use a local copy of the WordNet files, or who find JWordNet's object-oriented interface preferable to the procedural interface that the C library (and native method interfaces built on top of it) provide.

JWordNet supports Wordnet Versions 2.0, 2.1 and 3.0.

JWordNet is provided as-is, under an open license:

Download and Installation

Download the WordNet database from the Princeton site.
Download the JWordNet source code.


The JWordnet source code contains three primary subdirectories.
  • edu/brandeis/cs/wn
contains the domain-specific code, include the Dictionary broker class, the IndexWord, Synset, Word, and Pointer domain entity classes, and the POS and PointerType enumeration holders.
  • edu/brandeis/cs/utils
contains the generic utilities that the wn module uses.
  • browser
contains a simplified clone of the TCL application that ships with WordNet, and illustrates how to use many of JWordNet's features.

Many Java compilers insist that a source file be placed in a directory whose name matches the package name of the file. To compile this code with such a compiler, you'll need to place the files in wn in a directory whose name ends in edu/brandeis/cs/steele/wn/, and so forth.

Example Code

'Dog' Example

import edu.brandeis.cs.steele.wn.*;

/* This prints the senses of the noun 'dog' to the console. */
public class Main {

static void main(String[] args) {
	// Open the database from its default location (as specified
	// by the WNHOME and WNSEARCHDIR properties).
	// To specify a pathname for the database directory, use
	//   new FileBackedDictionary(searchDir);
	// To use a remote server via RMI, use
	//   new FileBackedDictionary(RemoteFileManager.lookup(hostname));
	
	DictionaryDatabase dictionary = new FileBackedDictionary();
	IndexWord word = dictionary.lookupIndexWord(POS.NOUN, "dog");
	Synset[] senses = word.getSenses();
	int taggedCount = word.getTaggedSenseCount();
	
	System.out.print(
		"The " + word.getPOS().getLabel() + 
		" " + word.getLemma() + " has " + senses.length + 
		" sense" + (senses.length == 1 ? "" : "s") + " ");
	
	System.out.print("(");
	
	if (taggedCount == 0) {
		System.out.print("no senses from tagged texts");
	} else {
		System.out.print("first " + taggedCount + " from tagged texts");
	}
	System.out.print(")\n\n");
	
	for (int i = 0; i < senses.length; ++i) {
		Synset sense = senses[i];
		System.out.println("" + (i + 1) + ". " + sense.getLongDescription());
	}
}

}