EXERCISES TUTORIAL SEMANTIC DAYS 2010

For each section there will about 15 minutes to solve exercises. There is probably more work than 15 minutes allows for, but there are exercises of different degree of difficulty, so choose the level you are comfortable with.

1 SPARQL

In these exercises we will write SPARQL queries and execute them in a SPARQL query interface located at http://sws.ifi.uio.no/d2rq/snorql/. The dataset which is queried is an RDF representation of a traditional relational database containing facts about countries, cities, continents and so on in the world1, similar to the RDF we wrote in the previous exercise.

By using the web browser interface to the RDF representation, e.g., Stavanger, you can look at the dataset in a human friendly readable way and see e.g. what properties the different types of resources have. We will come back to this database system in later exercises.

For each of the exercises below write a SPARQL query which returns the desired result when executed on the endpoint.

1.1 Exercise, Getting started

First, to get you started, using a web browser go to the address http://sws.ifi.uio.no/d2rq/snorql/. In the text area on this page you should see the SPARQL query

1:  SELECT DISTINCT * WHERE {
2:    ?s ?p ?o
3:  }
4:  LIMIT 10

Without hesitation, press the "Go!" button.

In less than a second you should see the results of the query execution. The query asks for any 10 distinct triples from the dataset. The result I got was the following table. Note that the results you get might very well not be the same!

spo
db:District/AFG/Kabolrdfs:label"Kabol"
db:District/AFG/Qandaharrdfs:label"Qandahar"
db:District/AFG/Heratrdfs:label"Herat"
db:District/AFG/Balkhrdfs:label"Balkh"
db:District/NLD/Noord-Hollandrdfs:label"Noord-Holland"
db:District/NLD/Zuid-Hollandrdfs:label"Zuid-Holland"
db:District/NLD/Utrechtrdfs:label"Utrecht"
db:District/NLD/Noord-Brabantrdfs:label"Noord-Brabant"
db:District/NLD/Groningenrdfs:label"Groningen"
db:District/NLD/Gelderlandrdfs:label"Gelderland"

1.2 Exercise

List all continents.

Formulated more RDF-friendly this exercise would be "select everything which is of type world:Continent", or perhaps even more friendly: "select all the subjects of triples where rdf:type is the predicate and world:Continent is the object."

1.3 Exercise

What is the name of the capital of Albania?

The predicate world:hasCapital connects a country with its capital. The identifier for the resource Albania is

 <http://sws.ifi.uio.no/d2rq/resource/Country/ALB>

1.4 Exercise

List all the names of cities which have a population of more than 5.000.000.

The predicate connecting a city to its population is world:hasCityPopulation, and world:hasName connects it to its name.

1.5 Exercise

List all the names of Chinese cities which have a population of more than 5.000.000.

The predicate connecting a city to its country is world:isCityInCountry. The identifier for China is

 <http://sws.ifi.uio.no/d2rq/resource/Country/CHN>

1.6 Exercise

List all unique government forms.

1.7 Exercise

List all the countries that lie in more than one continent.

The predicate connecting a country to its continents is world:isCountryInContinent.

1.8 Exercise

List all continents with the number of countries they contain.

Tip: Use the function count and GROUP BY. Even though count is not part of the SPARQL standard, it is often found in the various implementations of the standard.

1.9 Exercise

List all countries which are not independent, i.e, have no independent year (world:hasIndependenceYear).

1.10 Exercise

List all unique government forms with the country which has the maximum value of GNP for this government form. Order the output by the GNP value, the maximum on top.

Footnotes:

1 The database is the same that MySQL provides to their users for experimentation, see http://dev.mysql.com/doc/world-setup/en/world-setup.html. The sample data used in the world database is Copyright Statistics Finland, http://www.stat.fi/worldinfigures.

Author: Martin G. Skjæveland <martige@ifi.uio.no>

Date: 2010-05-30 23:16:57 CEST

HTML generated by org-mode 6.34trans in emacs 23