DNS for things Freebase is extremely useful for many things, but one of the most simple is as a sort of "DNS for things". Take for example films, computer games, programming languages. There are various disparate databases, with their own keys, all over the internet. It would be difficult to write an application to understand both an IMDB key and a key from a software site like freshmeat.net, for example. Freebase makes this possible, however. There are a huge number of things in Freebase, each with their own (and often humanly readable) IDs. More than just a repository of IDs Of course, Freebase tries to store not just a key for a thing, but also as much information about that thing as possible. There are huge swathes of data about things from Hatha Yoga postures to Saturday Night Live. Lots of images One of the most basic things which Freebase tries to store with each thing (or topic, in Freebase terms) is an image (or images). Freebase actually has pretty good coverage for images - around 40% of topics in Freebase have an associated image - many of which come from Wikipedia. Mapping a thing to an image Freebase makes images (and other static content blobs) available through its "trans" API. Trans provides a couple of transformations - the most interesting in this context being the image thumbnailing service - along with providing access to the raw binary data. Content is addressed by its own Freebase ID. Freebase Topics then link to these content objects. So, in order to, for example, fetch an image for a topic, you need to query Freebase using MQL. The MQL query is trivial:

[{ 
    'id': /* id of topic to find image for */, 
    '/common/topic/image': [{}]
}]
The result will contain an array of image IDs, which can be plugged into the trans api, such that you can write code like:

Thats nice, but wouldn't it be nice if you could just have a path to the Freebase ID, and have the first associated image be returned? For example to get a picture of US Treasury Secretary Henry Paulson, you could just write:

Acre applications While you could write your own app to issue the MQL queries on your behalf and return the resultant URLs, Freebase provides a framework for these kinds of applications - hosted on their servers (close to the databases etc) so you don't have to. This hosted application service is called Acre, and while it is still in the early stages of development, it works fine for simple things like this. `ID 2 Image' Acre Application I wrote this simple id-2-image translation application in 11 lines of JavaScript, and it works just fine. Here is the source:
if (acre.environ.path_info == "/") {
    acre.start_response(400);
    acre.exit();
}
var query = [{ "id" : acre.environ.path_info, "/common/topic/image":[{}]}];
var r = acre.freebase.MqlRead(query);
acre.start_response(302, {
        'Location': acre.freebase.imgurl(r.result[0]['/common/topic/image'][0]['id'].substring(1))
});
Using this application, you can write HTML like this, and have it display:

To prove it works, here is the image generated by it: So there you have it - trivially show an image for anything. Coupling this concept of being able to generate interesting output for a given Freebase ID, with the power of making it easy to find, select and store Freebase IDs in your application via freely available widgets like Freebase Suggest is extremely compelling. If you are in the SF Bay area, and are interested in Freebase, why not consider coming to the Freebase Hack Day on November 8th? Click the link below for details.

Niall O'Higgins is an author and software developer. He wrote the O'Reilly book MongoDB and Python. He also develops Strider Open Source Continuous Deployment and offers full-stack consulting services at FrozenRidge.co.

Read and Post Comments

This evening I was trying to select entries within a specific date range, for example, all torrents for films which had been released in 2007. My query looked something like:

SELECT name FROM table WHERE date > 2007-01-01 AND date < 2008-01-01
PostgreSQL consistently returned very odd results. As far as it was concerned, Transformers was not a 2007 release, furthermore Batman Begins - which I distinctly remember going to see about three years ago - was. Any relatively experienced SQL hacker is no doubt chuckling, having immediately seen my error. Of course, PostgreSQL is treating the un-quoted dates as arithmetic expressions and evaluating them numerically. When you think about it, 2005 - 05 - 05 = 1995. This is a perfectly valid arithmetic expression, its just that it happens to look like a definitive calendar date to my brain. I found this mistake on my part absolutely hilarious.

Niall O'Higgins is an author and software developer. He wrote the O'Reilly book MongoDB and Python. He also develops Strider Open Source Continuous Deployment and offers full-stack consulting services at FrozenRidge.co.

Read and Post Comments

« Previous Page