views:

6942

answers:

11

Does anyone know of a good dictionary API or ruby library to lookup the definitions of words?

I'm thinking it should work something like:

  1. I call get_definition(word)
  2. It returns the definition for that word (ideally in some way to easily format the definition for display.

Thanks

+11  A: 

I discovered a webservice for this yesterday.

Go to the British Council homepage and double click on any word (that isn't already a hyperlink).

This should open a popup window with a Cambridge Dictionary definition in it. The API is relatively simple (and it is a public API, I checked it yesterday):

http://dictionary.cambridge.org/learnenglish/results.asp?searchword=SEARCH_PHRASE&dict=L

For reference, here's the code they use to launch this on double-click:

/* BC double-click pop-up dictionary */
var NS = (navigator.appName == "Netscape" || navigator.product == 'Gecko') ? 1 : 0;
if (NS) document.captureEvents(Event.DBLCLICK);
document.ondblclick = dict;
var dictvar;

function dict() {
    if (NS) {
        t = document.getSelection();
        pass_to_dictionary(t);
    } else {
        t = document.selection.createRange();
        if(document.selection.type == 'Text' && t.text != '') {
            document.selection.empty();
            pass_to_dictionary(t.text);
        }
    }
}

function pass_to_dictionary(text) {
    //alert(text);
    if (text > '') {
        window.open('http://dictionary.cambridge.org/learnenglish/results.asp?searchword='+text+ '&dict=L', 'dict_win', 'width=650,height=400,resizable=yes,scrollbars=yes');
    }
}
Ross
This service seems to no longer be available in the form described by the answer author.
Adam Tuttle
A: 

I am unclear what you means with definition. The Wiktionary has a description of many words in many languages. The html pages can be easy displayed.

Horcrux7
+3  A: 

Ruby-WordNet sounds like it does what you're looking for:

Ruby-WordNet is a Ruby interface to the WordNet® Lexical Database. WordNet is an online lexical reference system whose design is inspired by current psycholinguistic theories of human lexical memory. English nouns, verbs, adjectives and adverbs are organized into synonym sets, each representing one underlying lexical concept. Different relations link the synonym sets.

Chris Bunch
Fair warning, this library takes forever to install and set up. The conversion process is very slow.
Bob Aman
A: 

excellent code Ross.. this is what i had been looking for .. it works like a charm ..thanks a lot :-)

suraj jain
+6  A: 

Hi -- Wordnik.com has several word-info APIs, including a definitions API. More info is here: http://docs.wordnik.com/api

[I work for Wordnik. We will have more APIs soon, let us know what you want!]

Erin
This looks very comprehensive - it would be nice to have further return data types please, esp JSON callback! :)
Andy
or a working iPhone example. With so many classes it's a pain to figure out what calls what
amok
+1  A: 

The WordNik API is very clean!

The have a great foundation. I would suggest focusing on WordNik from Erin, otherwise wait for Dictionary.com to release their API to the public(hopefully).

hookedonit
http://dictionary.reference.com/api/
hookedonit
A: 

Erin, thanks for posting this information on the wordnik.com/api (and for disclosing that you work for them).

I'm playing around with a wordpress plugin that could use this kind of data and this looks like it is a perfect API for my purposes.

I've only briefly glanced at it, and will investigate more but I just wanted to say thanks!

jfgrissom
A: 

Erin's WordNik API looks awesome. I think I'll be using that one.

nickb
+1  A: 

Andy, the Wordnik API has recently added support for callbacks with JSONP. More info at the link in Erin's response (in her spirit of disclosure, I work for Wordnik too :-)

John
A: 

Is anyone able to use dictionary.com Api now?

Jasjeev