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 RDF

In these exercises we will use the RDF serialisation format Turtle to write RDF.

1.1 Exercise

1.1.1 Getting started

Open a plain text editor, e.g., textpad, gedit, and start the file with the following prefix declarations (ignore the line numbers):

1:  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
2:  @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3:  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
4:  @prefix ex: <http://www.example.org#> .
5:  @prefix w: <http://sws.ifi.uio.no/ont/world.owl#> .

1.1.2 Triples

Continue by adding triples that capture the statements:

  • Norway is called "Norway", using the predicate rdfs:label,
  • Oslo is called "Oslo",
  • Oslo is the capital of Norway—use the predicate w:isCapitalOfCountry,
  • Stavanger is called "Stavanger", and
  • Stavanger is a city in Norway—use the predicate w:isCityInCountry.

Use the namespace prefixed ex: for the resources Norway, Oslo and Stavanger, e.g., ex:Norway.

1.1.3 Validate

Validate your finished RDF file using the RDF Validator and Converter. Paste the contents of your RDF file in the text area on the website and set the input format drop-down menu to "Notation 3 (or N-Triples/Turtle)" and click "Validate!". Sort out any errors in your RDF "code" that the validator reports.

1.1.4 Visualise

When your RDF validates, the website will, in addition to giving you a thumbs up, return an RDF/XML rendering of your file. Copy this RDF/XML, save it to a file—you might need it later, open the W3C's RDF validator, and paste the RDF/XML into the text area. Under Display Result Options select "Triples and Graph" and click "Parse RDF". See the nice graph that appears!

1.2 Exercise

Extend the RDF file, i.e., add more triples, to express that

  • Stavanger is City, and Rogaland is a Region—use the predicate rdf:type and the resources w:City and w:Region,
  • Rogaland is a region in Norway, and
  • Stavanger is a city in Rogaland.

Create predicates similar to the predicates in the previous exercise, e.g., isCapitalOfCountry to capture the two last bullet points.

Make sure your extended RDF file validates.

1.3 Exercise

Further extend your RDF file to contain that:

Norway is a country with a population of 4800000. The head of state is "King Harald V". Norway has two local names, one in the language "Norwegian bokmål" (language code @nb): "Norge", and one the the language "Norwegian nynorsk" (@nn): "Noreg".

Again, create new predicates for the relations between Norway and the information about Norway. It is natural to use literals for the RDF representation of the statements; try also to specify the datatype or language of the literals where appropriate.

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

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

HTML generated by org-mode 6.34trans in emacs 23