Wordnik is an online dictionary that bills itself as “The most comprehensive dictionary in the known universe”. Recently I wanted to add the ability to lookup word definitions to one of my applications, so I wrote a Java library to wrap the Wordnik API. The library is called Knicker, and is available under the terms of the GPL.
Using Knicker is simple:
- Sign up for a Wordnik API key
- Set the system property WORDNIK_API_KEY to your API key
- Put the Knicker library in your classpath
- Call methods on the library
Here’s an example of how to use the API to get a list of definitions for the word “siren”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import java.util.List; import net.jeremybrooks.knicker.Knicker; import net.jeremybrooks.knicker.dto.Definition; import net.jeremybrooks.knicker.dto.TokenStatus; public class TestKnicker { public static void main(String[] args) throws Exception { // use your API key here System.setProperty("WORDNIK_API_KEY", ""); // check the status of the API key TokenStatus status = Knicker.status(); if (status.isValid()) { System.out.println("API key is valid."); } else { System.out.println("API key is invalid!"); System.exit(1); } // get a list of definitions for a word List<Definition> def = Knicker.definitions("siren"); System.out.println("Found " + def.size() + " definitions."); int i = 1; for (Definition d : def) { System.out.println((i++) + ") " + d.getPartOfSpeech() + ": " + d.getText()); } } } |
For more information about the Wordnik API, see their developers page.