WordNet running on MSYS2 on Windows

As a non-native English speaker who reads, writes and reviews lots of English texts, I frequently look up definitions as well as synonyms of words. Of course there are numerous online sources available to do this, but I like to decrease my online 'footprint' due to privacy reasons. It also takes extra time to switch to a browser window and enter a search query.

Fortunately the fine folks at Princeton University compiled WordNet [1], a large lexical database of English, which can be used offline - together with a tool to search that database. Even better, somebody wrote a package to use WordNet inside my favorite editor Emacs [2]. This means that just by hovering the cursor over a word inside Emacs, the definition as well as synonyms can be shown. The source code [3] is kindly provided by Princeton University.

Compiling WordNet using MSYS2 on/for Windows

As is usually the case, compiling on/for Windows using the MSYS2 subsystem [4] can be done, with a few minor tweaks.

First, start a MSYS2 shell and install the required dependencies (build tools, as well as the programming language Tcl and its widget toolkit Tk ):

pacman -Sy --noconfirm base-devel mingw-w64-x86_64-tcl mingw-w64-x86_64-tk

Then download the source code [3] as well as the latest database files [5] using wget , and unpack both:

wget http://wordnetcode.princeton.edu/3.0/WordNet-3.0.tar.gz
wget http://wordnetcode.princeton.edu/wn3.1.dict.tar.gz
tar -xzvf WordNet-3.0.tar.gz
cd WordNet-3.0
tar -xzvf ../wn3.1.dict.tar.gz

Run configure...


...and run into the first hurdle:

WARNING: Can't find Tk configuration definitions

The compiler script warns about not being able to find Tk configuration definitions. Looking at the configure script, the file it is looking for is tkConfig.sh . On MSYS2, this file has been is installed under /mingw64/lib/tkConfig.sh and this location can directly be passed as parameter. The same holds true for the Tck configuration definitions:

./configure --with-tcl='/mingw64/lib/' --with-tk='/mingw64/lib/'

Now the configure script succeeds. The next step, compiling the program unfortunately fails at first run:


error: 'Tcl_Interp' {aka 'struct Tcl_Interp'} has no member named 'result'

This hints at an incorrect version of Tcl being expected. Fortunately this can be solved [6] by defining a constant ( USE_INTERP_RESULT ) while compiling, either in the source code or on the command line. As it's best not to touch the source, I opt for the command line:

CFLAGS="-DUSE_INTERP_RESULT" ./configure --with-tcl='/mingw64/lib/' --with-tk='/mingw64/lib/'

After this the program compiles successfully on MSYS2, running on Windows 10. The next step now strips the binaries and installs it, ready to be used on the system.

make install-strip

After this, when running the executable wn it still complains about not being able to open data and index files:

WordNet library error: Can't open datafile(/mingw64/dict/data.noun)
WordNet library error: Can't open indexfile(/mingw64/dict/index.noun)
WordNet library error: Can't open datafile(/mingw64/dict/data.verb) WordNet
library error: Can't open indexfile(/mingw64/dict/index.verb) WordNet
library error: Can't open datafile(/mingw64/dict/data.adj) WordNet library
error: Can't open indexfile(/mingw64/dict/index.adj) WordNet library error:
Can't open datafile(/mingw64/dict/data.adv) WordNet library error: Can't
open indexfile(/mingw64/dict/index.adv) WordNet library warning: Can't open
verb example sentence file(/mingw64/dict/sents.vrb) WordNet library warning:
Can't open verb example sentence index file(/mingw64/dict/sentidx.vrb) wn:
Fatal error - cannot open WordNet database

The instructions point out that the environment variable WNHOME needs to be set, pointing to the installation directory. After that, the binary seems to work:

export WNHOME=/mingw64
wn successful -over

WordNet successful

Using WordNet with Emacs using helm

Next up is tying WordNet to Emacs. This is a matter of installing the packages helm and helm-wordnet , and setting the variable helm-wordnet-wordnet-location to contain the absolute path to the MSYS2 subsystem folder where WordNet installed its dictionary files. This is the same as the 'virtual' path /mingw64/dict .

Personally I use use-package [7] for all Emacs package management: This code snippet from the startup file .init.el expects that package to be installed and will take care of all the heavy lifting.

(use-package helm
  :ensure t

(use-package helm-wordnet
  :after helm
  :config (setq helm-wordnet-wordnet-location "/full/path/to/mingw64/lib")
  :ensure t
  :pin "melpa"                           ;; The package is only available at Melpa for the moment

If everything went well, you can execute the function helm-wordnet-suggest and Emacs will happily show synonyms and a definition.

WordNet inside Emacs using helm

Mission accomplished...


On most Linux variants, installing WordNet is simply a case of using the native package manager, e.g. on Debian sudo apt-get install wordnet

[3](1, 2) http://wordnetcode.princeton.edu/3.0/WordNet-3.0.tar.gz


comments powered by Disqus