dict.org client with Ruby Shoes

02 May 2008

While reading blogs and other online documents, emails etc, I always come across words whose meaning is not known to me. Usually I lookup these words using Ubuntu's Dictionary application . Copying the word, pasting it in the text field of the dictionary app, hitting "Search", and then waiting for results - this was proving to be a difficult process, as I have to do it very often. Today morning Vamsee told me about dict.org and that it has an API. So I thought of using dict.org's API to build a tiny application that would help me lookup unknown words easily, preferably in a single step.

dict.org follows the standard Dictionary protocol. One could connect with TCP to 'dict.org' at 2628, and use the requests specified in the protocol to lookup words.

But most of the languages already have dict.org API wrappers. A list is given here. I tried the Ruby and Python APIs, they are pretty straight forward. I also found a 'dict' program, which is a dict.org client.

sudo apt-get install dict

$ dict freedom

It dumps the meaning of the word as well as similar words from thesaurus on to the terminal. Now my idea was to build a simple GUI to 'dict'. To do it in a flash, i decided to use Ruby Shoes, a light weight GUI tool kit in Ruby. More about Shoes and its installation can be read from Divya's article on Shoes.

First step was to create a Ruby interface for dict.org using the 'dict' client.

IO.popen("dict #{word}").read
Now using this interface, I made a normal dictionary application using Shoes - one with a text field and search button. On clicking the button, the word in the text field will be looked using dict aand result will be displayed in the window. It worked well, but it did not have any advantage over the dictionary application already available with Ubuntu. I wanted the whole lookup process to happen seamlessly for the user, disturbing his reading flow as less as possible.

So i decided to use the clipboard. User now simply has to select a word. My program will pick it up from clipboard and lookup the word in dict.org and have the meaning, thesaurus and other details ready in a flash. All the user has to do is to select a word..!

My dict.org client with Ruby shoes is available here.

You can run it like this :

$ shoes dict.rb