Skip to content

Instantly share code, notes, and snippets.

@rodacato
Forked from Kimtaro/gist:1779371
Created July 12, 2012 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodacato/3098837 to your computer and use it in GitHub Desktop.
Save rodacato/3098837 to your computer and use it in GitHub Desktop.
Installing the wordnet gem on OSX or Ubunut, as of July 17 2012

Getting the wordnet gem, version 0.0.5, working is a little tricky at the moment. It's being rewritten but isn't released yet and the dbd gem is in a similar state.

These steps got it working for me on OS X Lion or Ubuntu 10.04 and MRI 1.8.7.

WordNet

Download WordNet from http://wordnet.princeton.edu/wordnet/download/current-version/

$ ./configure
$ make
$ make install

for ubuntu, first install tcl and tk libraries

$ sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev

and compile with

$ ./configure --with-tclconfig=/usr/lib/tcl8.4 --with-tkconfig=/usr/lib/tk8.4
$ make
$ make install

BerkeleyDB

This uses homebrew (http://mxcl.github.com/homebrew/). If you use a different package manager then you will have to adjust the --with-db-dir below.

$ brew install berkeley-db

for Ubuntu

$ wget http://download.oracle.com/berkeley-db/db-5.1.29.tar.gz
$ tar xvzf db-5.1.29.tar.gz
$ cd db-5.1.29/build_unix
$ ../dist/configure 
$ make
$make install

ruby-bdb gem

the location may change, but for MacOs is: /usr/local/Cellar/berkeley-db/5.1.19 and Ubuntu: /usr/local/BerkeleyDB.5.1/

$ git clone https://github.com/knu/ruby-bdb
$ cd ruby-bdb
$ git checkout 6aa8054e022fa38055fd441de98b65fd392b8dcb
$ ruby extconf.rb --with-db-dir=/usr/local/Cellar/berkeley-db/5.1.19
$ make
$ make install

wordnet gem

$ gem install wordnet
$ gem which wordnet
$ cd your/wordnet/path
$ ruby convertdb.rb
$ mv ruby-wordnet/ `ruby -e "require 'rbconfig'; print Config::CONFIG['datadir']"`

Using it

$ irb
> require 'rubygems'
> require 'wordnet'
> lex = WordNet::Lexicon.new
> frog = lex.lookup_synsets('frog', WordNet::Noun)
> frog.first.hypernyms.first.overview
  => "amphibian [noun] -- (cold-blooded vertebrate typically living on land but breeding in water; aquatic larvae undergo metamorphosis into adult form)" 

Don't forget to close the connection for avoid Segmentation Fault

> lex.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment