These exercises develop some useful utility functions for working with the Freebase API to access Google's Knowledge Graph.
Define two packages:
- freebase to hold the functions you define. Only export the ones required by the exercises.
- freebase-tests for testing the Freebase code. It should use at least the Common Lisp and Freebase packages, but you can add others, e.g., the Lisp-Unit or CS325 packages, as you feel appropriate.
You should do
(in-package :freebase-tests) before any
To access Freebase, you need to get an API key. Note the restrictions on querying.
You also need to access Freebase with HTTPS, which doen't work with the portable AllegroServe HTTP client. Instead use Drakma. Install with Quicklisp.
Test cases: freebase-tests.lisp
FB-1: Basic query
Global variable names:
(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 will assemble them all into the URL to send to Freebase.
: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.
Since it's a nested list structure, it makes more sense to create Lisp lists for complex filters, and let Lisp construct the string.
(filter-string list) to take a list representing
a filter and return the string to use for the
search-freebase. An example filter is
> (filter-string '(all :category volcano (any :part_of california :part_of france))) "(all category:volcano (any part_of:california part_of:france))"
Note the use of keywords for categories and that categories can appear multiple times. Note that symbols can be used, but the string equivalents are lowercase.