Installing Ruby-WordNet on Leopard
I recently decided to play around with WordNet, a lexical database of English. Naturally, I wanted to use Ruby and found the Ruby-WordNet bindings. The install process was more involved than I expected.
Install WordNet
Download and unpack the latest version of WordNet. (I installed WordNet-3.0.tar.gz.) Then, proceed with the usual build steps:
$ cd ~src/WordNet-3.0 $ ./configure $ make $ sudo make install
Install Berkeley DB
I used MacPorts, which was nice and simple:
$ sudo port install db46
Install Berkeley DB Ruby Bindings
Download the latest release of BDB via FTP server. (I installed bdb-0.6.2.tar.gz.)
$ cd ~src/bdb-0.6.2
Next, if you are using an Intel-based Mac, use this:
$ env ARCHFLAGS="-arch i386" ruby extconf.rb --with-db-include=/opt/local/include/db46 --with-db-lib=/opt/local/lib/db46
Otherwise, if you’re using a PPC-based Mac:
$ env ARCHFLAGS="-arch ppc" ruby extconf.rb --with-db-include=/opt/local/include/db46 --with-db-lib=/opt/local/lib/db46
For me, not specifying the architecture results in this general error:
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:78: libdb not found (RuntimeError) ...
With more detailed error information in ~/src/bdb-0.6.2/mkmf.log:
... ld: symbol(s) not found for architecture ppc ...
Note: In general, I’ve found that anything that I build using MKMF needs the ARCHFLAGS environment variable. Also, note that some RubyGems use MKMF to build native extensions, so -arch is also required (i.e. sudo env ARCHFLAGS="-arch i386" gem install mysql).
If everything went well you’ll have a Makefile and can finish off the Berkeley DB Ruby bindings installation:
$ make $ sudo make install
Install Ruby-WordNet
Download the latest version of Ruby-Wordnet (I installed Ruby-WordNet-0.0.4.tar.gz):
$ cd ~src/Ruby-WordNet-0.0.4 $ ruby convertdb.rb /usr/local/WordNet-3.0/dict/ $ ruby test.rb $ sudo ruby install.rb
I got one failure while running the tests, which I assumed to not be a huge problem.
You should now be able to run the examples:
$ sudo ruby examples/distance.rb pine tree The hypernym distance between pine and tree is: 3
Note: To avoid having to sudo to run your Ruby scripts that leverage WordNet, you will likely need to correct permissions to allow your user write access to the ruby-wordnet database files. I do not recommend adding your user to the group wheel, which exposes you to security vulnerabilities and/or prevent applications from loading plugins. For example, Safari won’t load plugins (Input Managers) if your user is a member of wheel.
Concluding Thoughts
I have a strong suspicion that the Ruby community would benefit from using MySQL for the WordNet database. There are already some projects that port WordNet to a MySQL database, such as wordnet sql builder. With a reasonable amount of effort the schema could be altered to conform to ActiveRecord conventions, making WordNet much more accessible.
Installing LIBSVM on Leopard
LIBSVM is a popular software library for performing document classification using support vector machines.
One easy approach to installing LIBSVM on Mac OS X Leopard is to use the popular MacPorts (download page). If you have MacPorts installed, you can install LIBSVM as shown below.
The Portfile has recently been fixed, so be sure to sync like so:
$ sudo port -v selfupdate
Install libsvm already:
$ sudo port install libsvm
Naturally, I’m particularly interested in using the Ruby bindings for LIBSVM. I’m not completely satisfied with the method I used to get them built and installed, but I’ll write it up.
NOTE: The Portfile for LIBSVM is currently was broken, but I contributed a very minor patch which updates the port to LIBSVM 2.86. The patch has been accepted by the maintainer and will soon be has been rolled.