These exercises develop some useful Lisp functions for accessing knowledge graphs from two services:
Both services are accessed via HTTPS. That doen't work with the portable version of the AllegroServe HTTP client, so use Drakma. Install it with Quicklisp.
Google Knowledge Graph
To access GKG, you need to get an API key. Note the restrictions on querying.
Define two packages:
- gkg to hold the functions you define. Only export the ones required by the exercises.
- gkg-tests for testing your code. It should use at least the Common Lisp and GKG packages, but you can add others, e.g., the Lisp-Unit or CS325 packages, as you feel appropriate.
You should do (in-package :gkg-tests)
before any
testing.
The results returned from GKG are in a string using JSON-LD syntax and the schema.org ontology. Use the CL-JSON parser to translate JSON strings into CLOS objects.
Exercises
Test cases: gkg-tests.lisp
GKG-1: Basic query
Function names: search-freebase
, set-default-key
Global variable names: *default-api-key*
Define (search-freebase query [keys...]
to query the Google knowledge graph and return the results as a nested alist.
The function should allow any keywords to be passed in, and assemble them all into the URL to send to GKG. The expected keywords are those listed in the standard API.
If no :api-key
is given, it should default to the value in
*default-api-key*
. The default key is the empty string. Set it
to the API key you get from Google.