SSSW2011 Linked Data Hands-on Session

"Build a Linked Data Mashup in 90 Minutes"

Code (zip file)

Attribution 3.0 Unported (CC BY 3.0)

Introduction

The goal of this session is to create a simple city guide based on existing sources of Linked Data available on the Web. Your city guide application will be seeded with a single URI identifying the city of your choice (the DBpedia URI for Madrid (http://dbpedia.org/resource/Madrid) is used in the example code, and you're free to use this in your mashup).

In the first step, your application will look up this URI to retrieve an RDF description of the city. You must then write some PHP code to extract interesting URIs from the RDF data and look these up to retrieve additional data. Once you have gathered sufficient data from different data sources you should then use this data to generate a simple Web page describing the city. More detailed implementation instructions are given below.

Implementation Overview

The Moriarty Library and SimpleGraph Class

The implementation of the mashup will be based on the Moriarty library for working with RDF data in PHP. The Moriarty library (and its dependencies) are already installed on the machines being used for the hands-on exercise. In particular, the SimpleGraph class from Moriarty will be used in this exercise. This class provides many useful methods for extracting data from a SimpleGraph (an in-memory representation of an RDF graph), retrieving more RDF data from the Web and adding it to the SimpleGraph. Specific pieces of data can be retrieved from the SimpleGraph for use in your mashup. The Moriarty library also caches remote data on the local disk, so you should notice an increase in performance once you have retrieved data for the first time.

The Thing Class

A new class, thing.class.php, has been created for this exercise. This class extends simplegraph.class.php (local copy of simplegraph.class.php), and therefore inherits the methods provided by that class. The new Thing class also provides a number of additional methods which should be useful for the exercise, such as a method (get_picture()) to get the URI of a picture of the city, and a method (get_same_as_links()) to get owl:sameAs links linking your seed URI to equivalent URIs in other data sets. The sample code provided for the exercise creates a Thing object ($thing) based on a seed URI for your city. You can then use the methods defined by thing.class.php and simplegraph.class.php to retrieve data from other data sets, by looking up URIs. The read_data() method, which takes one URI or an array of URIs as an argument, is particularly useful for this. This retrieved data can then be presented in your Web page.

Instructions

Your task is to create a city guide for a city of your choice, based on sources of Linked Data available on the Web.

  1. Choose a city as the focus of your city guide. The sample code uses Madrid as an example, but you're free to choose a different one. If you choose a different city, find the URI of its wikipedia page and replace http://en.wikipedia.org/wiki/ with http://dbpedia.org/resource/ - this will give you a URI that identifies the city itself and returns RDF when you look it up. Choose whichever city you like, but more obscure locations will have less data about them available, which will make it harder to build an interesting mashup.
  2. Double click the desktop icon labelled "www" to open a file browser window at the location "/var/www/". This is where all the files you will need for the exercise are located.
  3. Double-click the file index.php to open it in the "gedit" text editor. If asked whether you want to Run or Display the file, choose Display.
  4. In index.php, towards the top, enter the URI of your city as the value of the "SEED_URI" constant. The default is the DBpedia URI for Madrid.
  5. Visit index.php in your Firefox Web browser (at http://localhost/index.php - this is also the browser home page) to see the default output for your city.
  6. Use the methods defined in thing.class.php and simplegraph.class.php to output more information about the city from the RDF data that describes your seed URI. (list of SimpleGraph methods). If you're not sure what data is contained in your SimpleGraph, try uncommenting one or both of the lines of code towards the bottom of index.php; these will display the contents of the graph as an array or an HTML table. (View the source of the page to see the structure of the PHP array more clearly).
  7. Use methods of the SimpleGraph class, such as get_resource_triple_values(), to get URIs that when looked up may provide more data about your city. Suggestions of things to look for include URIs of photo collections and owl:sameAs links to other data sources.
  8. Use the read_data() method of SimpleGraph to retrieve other RDF documents and add the triples into your SimpleGraph. read_data() takes a single URI (as a string) or an array of URIs as an argument. If you pass it an array of URIs these will be looked up in parallel, improving the performance of your mashup.
  9. Show the power of your mashup by including data from these additional sources.

Useful Data Sets

Suggestions for Extending Your Mashup

Useful Links