Getting started with Wordnik’s word & worldlist API

Getting started with Wordnik's Word & Worldlist API

Wordnik offers unique words and other English language-related services, which content can be accessed through their API. See how.

Introducing Wordnik

In today’s world where language is somewhat neglected modern ‘word-related’ services are a welcome addition to the struggle against illiteracy. One such service provider, Wordnik, offers unique words and other English language-related services.

Wordnik bills itself as “a place for all the words, and everything known about them.” They allow users to look up definitions, add new words to their online database and provide example sentences pulled from the internet. Unlike many online dictionaries, Wordnik’s content can be accessed through their API.

From their website:

“Wordnik has amassed an incredible amount of data… one of our core principles is that you shouldn’t have to come to any particular web site to learn about words: the word data should come to you wherever you are.”

Wordnik’s API

Wordnik’s RESTful API allows developers to look up definitions, display the use of words in example sentences and return data about how frequently the word appears in Wordnik’s corpus. The Wordnik API also gives developers access to an auto-complete function, and both a ‘random word’ and a ‘word of the day’ listing. Data for each function is accessed by GET request, and data can be returned in either XML or JSON format.

For Python

For the official Python library see Github and follow the instructions there. Other code libraries can be obtained here.

Pip needs to be installed:

sudo apt-get install python-pip
sudo pip install --upgrade pip --index-url=https://pypi.python.org/simple/

After installation, sign up for a Wordnik account and get an API key.

Wordnik API Python sample script

Create a new Python script in a desired location. For the Word Of The Day script I will use /home/pi/wotd/wotd.py for explanation purposes. In a freshly booted Raspberry Pi terminal use:

mkdir /home/pi/wotd
nano /home/pi/wotd/wotd.py

and copy the following code into it:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from wordnik import *
apiUrl = 'http://api.wordnik.com/v4'
apiKey = 'your-api-key-here'
client = swagger.ApiClient(apiKey, apiUrl)

wordsApi = WordsApi.WordsApi(client)
wotd = wordsApi.getWordOfTheDay()

print wotd.word
print wotd.definitions[0].text
print wotd.note
print wotd.examples[0].text

Change the API details to the one from your own account, exit and save (Ctrl + X & Y).

To run the script use:

python /home/pi/wotd/wotd.py

You can see more Words functions on the official Python development page (https://github.com/wordnik/wordnik-python).

Conclusion

Wordnick is a place for all the words, and everything known about them. Unlike many online dictionaries, Wordnik’s content can be accessed through their API.

Leave a Reply

Your email address will not be published. Required fields are marked *