A thin Python API for wordnik.com
In my current project I wanted to get the definition of a word. In addition, it’d be nice to see some examples with the given word. How to do that?
In Google you can use the search term “define:word” (example). It shows you the definition, some synonyms, and it can even pronounce the word for you. Nice, but I didn’t want to parse HTML. I wanted a clean API for getting all these data.
Wiktionary is an open dictionary. It has an API but I wasn’t fully satisfied with it. You can get the definition of a word as raw text (word, raw text), but it’s not that easy to extract what you want. They also provide the content in JSON format, but there the whole content was grouped in a string. Not too convenient.
And finally I found wordnik.com that provided exactly what I needed. They have a REST API (here), which is freely available, but first you need to request your own API key. The result is provided in JSON format. They have a Python client API but I wanted something simpler, so I wrote my own (wordnik.py).
# input: barkeeper # output: ===Definition=== (noun) A person who owns or operates a bar for the sale of alcoholic beverages. ===Examples=== (1) Aaron called the barkeeper over and asked for a beer. ...
I built a simple interactive, command-line dictionary that uses this thin API (see here).