Starting with Freebase

One of the more interesting parts of the web developing currently is Freebase. It is a structured value store that lets you compose complex queries about the relationships between things in the world.

I’ve been playing with a TV browser and my queries aren’t working quite right. I’ve been working through the API reference and hit a couple snags. I thought I would record my progress.

In the section on nested queries, there is an example of how to list the tracks from The Police‘s Synchronicity.

{
  "type" : "/music/artist",
  "name" : "The Police",
  "album" : {
    "name" : "Synchronicity",
    "track" : []
  }
}

Freebase is queried using JSON objects. This query should return the object with the track array filled in with the tracks, but instead it returns Type /music/album does not have property track.

Freebase types are collections of attributes and there is a schema viewer to browse these. Apparently the album schema has been refactored since the documentation was written and albums are now the basis for multiple releases. To query the tracks for a release, the object is:

{
  "type" : "/music/artist",
  "name" : "The Police",
  "album" : {
    "name" : "Synchronicity",
    "releases" : [ {
      "release_date" : null,
      "label" : null,
      "catalog_number" : null,
      "track" : [],
    } ]
  }
}​

This query does succeed. One last test is to order the tracks. This uses a special property called sort:

{
  "type": "/music/artist",
  "name": "The Police",
  "album": {
    "name": "Synchronicity",
    "releases": [{
      "release_date":  null,
      "label":         null,
      "catalog_number": null,
      "track": [{
        "name":  null,
        "index": null,
        "sort":  "index",
      }]
    }]
  }
}​

I found the index property in an example. It isn’t in either the track schema or the object schema. It is a generated property used for ordering collections.

Leave a Reply

Your email address will not be published. Required fields are marked *