WNJN

WordNet JNI Java Native Support

Bernard BOU
Lycée Champollion
bbou@ac-toulouse.fr

SourceForge Logo

THIS PAGE WAS REVISED ON FEB 20, 2006

CONTENTS

LICENSE

This package is is under a GPL GNU Licence (See file GPL). Some of the code is under the WordNet license agreement.

top of page

THE PURPOSE OF WNJN

This package allows you to use WordNet from Java. Some of the code is under the WordNet license agreement.

top of page

PURE JAVA OR NATIVE METHODS IN C

I weighed the pros and cons of writing a pure java solution (with no C code) and decided against it on the following grounds :

native methods pure java methods
for against for against
it is independent from the format of the database which may evolve in future releases

if the current C API is still supported future releases of WordNet - and at the moment this is the only thing that looks like an interface - , adjustment could involve only minor changes

best performance

the methods have to be recompiled to the target platform code

release package is more complex and there is the hassle of indicating the library path

it is portable without recompiling it is data-dependent and tied to the format of the database which may evolve in future releases

performance penalty in wide scope searches

top of page

THIS AND OTHER IMPLEMENTATIONS

There are other implementations with the same functionality. I'm referring to Jorge Gomez' ( jjgomez@sip.ucm.es ) implementation of a Java native interface. It came first and suffices in most situations but, as as I started using it, I wanted to improve on on a number of points. So I started a rewrite and the result has evolved away from the original. 

However we do have points in common : 

The points I wanted to improve on  :

top of page

NMI VERSUS JNI

This is taken from the JDK 1.2 documentation :

Java Native Interface is a standard programming interface for writing Java native methods and embedding the Java virtual machine into native applications. The primary goal is binary compatibility of native method libraries across all Java virtual machine implementations on a given platform.
JDK 1.2 extends the Java Native Interface (JNI) to incorporate new features in the Java platform.
JDK 1.2 still supports the old native method interface (NMI), which was originally implemented in JDK 1.0. The old NMI is not part of the Java platform standard, and will not be supported by the upcoming Java HotSpotTM virtual machine. Programmers are strongly encouraged to migrate their existing NMI code to the JNI.
 
top of page

REQUIREMENTS

You need :

top of page

PLATFORMS

I have carefully avoided features which could not be portable. You simply need a standard C++ tool.

However I developed this on two specific platforms :

I include the build files attached to these tools for convenience togehter with redundant batch or shell files.

But I didn't test it on other platforms as I don't have any other platform handy. Please refer to the build process below.

top of page

TARGETS

  Windows Linux
java lib wnjn.jar wnjn.jar
native libs
one of the version-tagged libs below renamed or linked to, this is what wnjn.jar expects
wnjn.dll libwnjn.so
native libs
version-tagged libs
wnjn16.dll wnjn171.dll wnjn20.dll wnjn21.dll
libwn16jn.so libwn17jn.so libwn171jn.so libwn20jn.so libwnjn21.so

BUILD

You have to have Apache Jakarta Ant and run (in the folder where the build.xml file is to be found):

ant -Dtarget.wnx="21"

Valid wnx targets are "16", "17" or "171" or "20" or "21"

Alternatively you can run the different steps :

step input output
javac -sourcepath <sourcefolder> -d <classfolder> <sourcefolder>/edu/princeton/wordnet/*.java
compile the java source files to classes edu.princeton.wordnet.Synset.java
edu.princeton.wordnet.Index.java
edu.princeton.wordnet.WordNet.java
edu.princeton.wordnet.Synset.class
edu.princeton.wordnet.Index.class
edu.princeton.wordnet.WordNet.class
jar cvf <jarfolder>/WordNet.jar -C <classfolder> .
make java archive edu.princeton.wordnet.Synset.class
edu.princeton.wordnet.Index.class
edu.princeton.wordnet.WordNet.class
WordNet.jar (containing zipped input)
javah -classpath <classfolder> -d <Cfolder> edu.princeton.wordnet.Synset
javah -classpath <classfolder> -d <Cfolder> edu.princeton.wordnet.Index
javah -classpath <classfolder> -d <Cfolder> edu.princeton.wordnet.WordNet
generate the C-header files edu.princeton.wordnet.Synset.class
edu.princeton.wordnet.Index.class
edu.princeton.wordnet.WordNet.class
edu_princeton_wordnet_Synset.h
edu_princeton_wordnet_Index.h
edu_.princeton_wordnet_WordNet.h
javap -s -private -classpath <classfolder> edu.princeton.wordnet.Synset > Synset.sig
javap -s -private -classpath <classfolder> edu.princeton.wordnet.Index > Index.sig
javap -s -private -classpath <classfolder> edu.princeton.wordnet.WordNet > Wordnet.sig
generate the signature files (this step can be skipped and is useful for reference only) edu.princeton.wordnet.Synset.class
edu.princeton.wordnet.Index.class
edu.princeton.wordnet.WordNet.class
Synset.sig
Index.sig
WordNet.sig
<the command line is platform dependent>
generate the WordNet 1.x library
care must be taken to include the bug-fixes
BINSRCH.C
MORPH.C
SEARCH.C
SETUTIL.C
WNGLOBAL.C
WNHELP.C
WNRTL.C
WNUTIL.C
LICENSE.H
SETUTIL.H
WN.H
WNGLOBAL.H
WNHELP.H
WNRTL.H
WNTYPES.H
WNCONSTS.H
wnxx.lib or  libwnxx.a
<the command line is platform dependent>
compile the wnjn
link with standard libraries and the wn16 library
WordNet.cpp
wnFactory.cpp
edu_princeton_wordnet_Index.h
edu_princeton_wordnet_Synset.h
edu_princeton_wordnet_WordNet.hwnFactory.h
wnxxxjn.dll or libwnxxxjn.so
java -classpath <wnjar path>wn.jar -Djava.library.path=<wnjn lib path> Test horse
run wn.jar
wnjn.dll or libwnjn.so
 

We owe the Unix makefiles to Ola Åkerberg and Hans Svensson (e94hsv@efd.lth.se), two masters thesis students from Lund, Sweden.
 

top of page

FILES

wnjn files comments
  • wnjn.html
this file
  • build.xml
Ant file
  • java
    • _compile.bat 
    • _makejar.bat
    • _compiletest.bat
    • _getenv.bat 
    • _runtest.bat 
    • _wnjava.jpr
build command files for the Win32 platform using the JDK
_wnjava.jpr is the JBuilder project file (its settings will have to be tuned to the target machine
  • java/sources
    • Test.java
    • XWordNet.java
test application source files
  • java/sources/edu/princeton/wordnet
    • Index.java
    • Synset.java
    • WordNet.java
wnjn source files
  • java/classes
    • Test.class
    • XWordNet.class
test application byte-code files
  • java/classes/edu/princeton/wordnet
    • Index.class
    • Synset.class
    • WordNet.class
wnjn byte-code files
  • java/jar
    • wnjn.jar
wnjn jar file containing code
  • c
    • _makeheaders.bat
    • _makesignatures.bat 
build commands of headers and signatures form class files
  • c
    • Makefile
    • Makefile.config

 

Microsoft Visual C++'s build files 
wnjn.dsp is the project file
wnjn.dsw is the workspace file
wnjn.mak is the command line file
wnjn.dep is th dependency file included in wnjn.dep
  • c
    • wnjn.dsp
    • wnjn.dsw
Unix makefiles
  • c/sources
    • edu_princeton_wordnet_WordNet.h
    • edu_princeton_wordnet_Synset.h
    • edu_princeton_wordnet_Index.h
    • Wordnet.sig
    • Synset.sig
    • Index.sig
the header files generated
the signature files are for reference only and not used in the compile process
  • c/sources
    • WordNet.cpp
    • wnFactory.cpp
    • wnFactory.h
C++ native source files (portable)
  • c/sources
    • wnjn.rc
    • resource.h
resource files for versioning (Visual C++)
  • c/sources
    • Makefile
makefile for Unix
  • c/release
    • wnjn.dll
    • libwnjn.so
output library
  • licence
    • GPL
    • WordnetLicense
license agreements
WordNet files comments
  • c/lib/wnxx
    • wnxx.dep
    • wnxx.dsp
    • wnxx.mak
make files for the Microsoft's C++ Compiler
wn16.dsp is the project file
wn16.mak is the make file
  • c/lib/wnxx
    • Makefile
    • Makefile.config
makefiles for Unix
  • c/lib/wnxx/lib
    • BINSRCH.C
    • MORPH.C
    • SEARCH.C
    • SETUTIL.C
    • WNGLOBAL.C
    • WNHELP.C;
    • WNRTL.C
    • WNUTIL.C
source files
  • c/lib/wnxx/lib
    • Makefile
makefile for Unix
  • c/lib/wnxx/include
    • LICENSE.H
    • SETUTIL.H
    • WN.H
    • WNCONSTS.H
    • WNGLOBAL.H
    • WNHELP.H
    • WNRTL.H
    • WNTYPES.H
include files
  • c/lib/wnxx/Release
    • wnxx.lib
    • libwnxx.a
output library

 

top of page

WORDNET 2.0 support

The tests compile and run fine with the WordNet 2.0 C API files. One major change with versions as of 1.7 is the addition at the beginning of the C-structure of a idxoffset, which could mean trouble if the proper defines and header files are not included.
The distribution has been compiled to WordNet 2.0

top of page

WORDNET 2.1 support

The tests compile and run fine with the WordNet 2.1 C API files. One major change with versions as of 1.7 is the addition at the beginning of the C-structure of a idxoffset, which could mean trouble if the proper defines and header files are not included.
The distribution has been compiled to WordNet 2.1

top of page

AUTHOR

Bernard BOU
Lycée Champollion,
Figeac, France.

This wnjn interface is needed as part of a data provider for my Treebolic engine which will be released later this year. I also authored WordNet TreeWalk (for which I have received very positive feedback):

as well as other various software programs ( http://www.ac-toulouse.fr/bbou)

top of page

CONTRIBUTORS

Ola Åkerberg and Hans Svensson
Barry Hathaway

top of page

COMMON PITFALLS

When the output yields wninit=-1, the trouble can originate in the following:

top of page

DOWNLOAD

The project page at SourceForge is http://sourceforge.net/projects/wnjn . There you will be directed to the CVS or to distribution (Zip file).

top of page

PROJECT MANAGEMENT

If anyone is interested in managing the project I'd also be happy to hand it over.

top of page