These exercises develop some useful utility functions for working with the Freebase API to access Google's Knowledge Graph.

Define two packages:

You should do (in-package :freebase-tests) before any testing.

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.

The results returned from Freebase are in a string using JSON syntax. Use the CL-JSON parser to translate JSON strings into CLOS objects.


Test cases: freebase-tests.lisp

FB-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 will assemble them all into the URL to send to Freebase.

If no :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.

FB-2: Filters

Function names: filter-string

An important but complicated parameter for Freebase queries is the filter. Examples are here.

Since it's a nested list structure, it makes more sense to create Lisp lists for complex filters, and let Lisp construct the string.

Define (filter-string list) to take a list representing a filter and return the string to use for the :filter parameter of 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.

Faculty: Chris Riesbeck
Time: Monday, Wednesday, Friday: 11am - 11:50am
Location: Tech LR5


Important Links