In today’s world where language is somewhat neglected modern ‘word-related’ services are a welcome edition to the struggle against illiteracy. One such service provider, Wordnik, offers unique word 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 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.
Pip needs to be installed:
sudo apt-get install python-pip sudo pip install --upgrade pip --index-url=https://pypi.python.org/simple/
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.text print wotd.note print wotd.examples.text
Change the API details to the one from your own account, exit and save (Ctrl + X & Y).
To run the script use:
You can see more Words functions on the official Python development page (https://github.com/wordnik/wordnik-python).