Skip to content

Instantly share code, notes, and snippets.

@Kimtaro
Created February 9, 2012 11:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Kimtaro/1779371 to your computer and use it in GitHub Desktop.
Save Kimtaro/1779371 to your computer and use it in GitHub Desktop.
Installing the wordnet gem on OSX, as of February 9 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 and MRI 1.8.7. On 1.9.2 convertdb.rb segfaults.

WordNet

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

$ ./configure
$ 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

ruby-bdb gem

$ 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)" 
@lramach
Copy link

lramach commented Mar 12, 2012

The last few lines of my result after running line "ruby extconf.rb --with-db-dir=/usr/local/Cellar/berkeley-db/5.3.15"

checking for db_version() in -ldb... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
extconf.rb:109: libdb not found (RuntimeError)
from extconf.rb:87:in `catch'
from extconf.rb:87

Could it be that the berkeley db hasn't been installed correctly? or maybe the version?

@Kimtaro
Copy link
Author

Kimtaro commented Mar 12, 2012

It could very well be that Berkeley DB isn't installed properly. Can you confirm that the Homebrew install is working?

Also check that the version is correct by ls /usr/local/Cellar/berkeley-db/.

@lramach
Copy link

lramach commented Mar 12, 2012

It is working. Berkeley-db is installed and the lib/ folder contains the libdb files.

@peterstyles
Copy link

@lramach I had the same error messages as you, and it was caused by my system defaulting to ruby 1.8.7, when I tried with 1.9.3 it worked fine.

@lramach
Copy link

lramach commented Mar 14, 2012

Thanks that helped! I was able to install ruby-bdb with ruby version 1.9.2.
However, while trying to install the wordnet gem and setting up the database with 'ruby convertdb.rb' I am getting the following error:
.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:243:in `mkdir': Permission denied - /Library/Ruby/Gems/1.8/gems/wordnet-0.0.5/ruby-wordnet (Errno::EACCES)
I downloaded and installed WordNet-3.0 in a folder that did not require any permission.
Any idea how I can fix this? Thanks again for all the help!

@peterstyles
Copy link

Did you previously install the WordNet gem as a superuser? Perhaps try an uninstall of WordNet and then try to re-install.

@lramach
Copy link

lramach commented Mar 21, 2012

Thanks for that suggestion!
I tried 'sudo ruby convert.rb' and it worked!

@lramach
Copy link

lramach commented Mar 21, 2012

I completed all the steps, but when I run

require 'rubygems'
require 'wordnet'
lex = WordNet::Lexicon.new
I get the following error:

TypeError: can't convert Symbol into Integer
from /ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/lexicon.rb:93:in %' from /ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/lexicon.rb:93:ininitialize'
from (irb):3:in new' from (irb):3 from /ruby-1.9.2-p290/bin/irb:16:in

'

Did anyone encounter this error?

@lramach
Copy link

lramach commented Mar 21, 2012

I finally got it working, after making a copy of the ruby-wordnet directory in the '..rvm/rubies/ruby-1.9.2-p290/share/' directory and using 'lex = WordNet::Lexicon.new(WordNet::Lexicon::DEFAULT_DB_ENV, :044)' to create the lexicon!

Thanks for all the help!

@Kimtaro
Copy link
Author

Kimtaro commented Mar 21, 2012

Great! Glad to hear you got it working.

@lramach
Copy link

lramach commented Mar 21, 2012

I just realized that the 'ruby convertdb.rb' had resulted in a segmentation fault.

convertdb.rb: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]

-- control frame ----------

c:0001 p:0000 s:0002 b:0002 l:0006d8 d:0006d8 TOP

-- C level backtrace information -------------------------------------------

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Although wordnet is working fine for some cases, it results in segmentation faults while trying to lookup_synset. I looked around but couldn't find a solution to this. Did anyone face a similar issue? Any help would be appreciated! thanks!

@peterstyles
Copy link

For me this segmentation fault occurred on exit - so the convertdb.rb script executed 'correctly'

@lramach
Copy link

lramach commented Mar 22, 2012

Same here. However, when I run my code for looking up synsets (lookup_synsets), it throws me the following error:

.rvm/gems/ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/synset.rb:309:in initialize': uninitialized constant WordNet::Synset::Sync (NameError) from .rvm/gems/ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/lexicon.rb:233:innew'
from .rvm/gems/ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/lexicon.rb:233:in block in lookup_synsets_by_key' from .rvm/gems/ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/lexicon.rb:227:ineach'
from .rvm/gems/ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/lexicon.rb:227:in lookup_synsets_by_key' from .rvm/gems/ruby-1.9.2-p290/gems/wordnet-0.0.5/lib/wordnet/lexicon.rb:214:inlookup_synsets'
from /Aptana Studio 3 Workspace/NLP_Test_0.1/wordnetBasedSimilarity.rb:43:in compareStrings' from /Aptana Studio 3 Workspace/NLP_Test_0.1/wordnetBasedSimilarity.rb:404:in

'
/Aptana Studio 3 Workspace/NLP_Test_0.1/wordnetBasedSimilarity.rb: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]

-- control frame ----------

c:0001 p:0000 s:0002 b:0002 l:000308 d:000308 TOP

-- C level backtrace information -------------------------------------------

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.

Bug reports are welcome.

Edit: The lookup code works fine while running it from the irb console.

@peterstyles
Copy link

try finishing your code by closing the WordNet::Lexicon connection (e.g. for me this is lex.close)

@lramach
Copy link

lramach commented Mar 22, 2012

But you would add the lex.close after the lookup_synsets() line, correct?
My code is failing on the line containing the lookup!

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