EXERCISES INF3580 SPRING 2010 WEEK 3

A bird.

A bird.

This document contains exercises made for INF3580. Please send any comments, errors, bug or improvement reports to this exercise set to martige@ifi.uio.no. Feedback is most welcome! Alphabetically thanks to Audun Stolpe, Espen H. Lian, Martin Giese and Rune Dahl for feedback.

The main curriculum for INF3580 spring 2010 is Semantic Web Programming by John Hebeler et al., Wiley Publishing, 2009. They have a website with additional articles and all source code used in the book at http://semwebprogramming.org/. Auxiliary curriculum is the book Foundations of Semantic Web Technologies by Hitzler, Krützsch, Rudolph, CRC Press 2009.

Keep all the work you do for these exercises in a safe place. Setting up a version control system like cvs, svn or git for the work you do is smart. You can create a svn repository on IfI's svn server, see their help section for more information. There is also a walk-through from old INF3120 on how to set up a svn repository and connect it to Eclipse, but news is that you'll need the plug-in subclipse to make it work. Please contact me if you have any smart tips to share.

1 Jena

Read

  • Semantic Web Programming: chapters 3, 2.

This week's exercises will give you the first looks on the Jena API. Use the book to look for examples, but look also at the Jena Framework javadoc, there might be better ways to do things than what is used in the book.

Other resources:

1.1 Creating RDF models with Jena

In this set of exercises we will learn how to create models with Jena. First, we will create the model "by hand", i.e., writing triples like in last week's exercises, then we will do the same using a Jena java program.

1.1.1 Exercise

Slide 7 of the lecture set for the RDF lecture, lecture no. 2, contains a graph which is also found in Figure \ref{fig:graph}. Write an RDF representation of the graph. Add also some of the names of the the resources in the graphs in different languages, e.g., "Cat" spells "Katt" in Norwegian and "Katze" in German.

Use whatever namespace you prefer. The important thing is that you get a good idea of how the file should look like as you will need that in the next exercise.

Graph.

Graphs are suitable for encoding meaning.

1.1.2 Exercise

Write a java program which creates the same RDF model as you made in the previous exercise and writes the model to a file in the same RDF serialisation language as you used.

1.2 RDF serialisation converter

RDF may be written in different ways, in different serialisations. The common serialisations are RDF/XML, Turtle and N3.

1.2.1 Exercise

Write a Java program which can convert between four serialisations of RDF: RDF/XML, Turtle, N3 and N-TRIPLE. The program should take two arguments, input file and output format, where the file extension of the input file indicate which RDF syntax the file has and the output format specifies the format to convert to. The converted output shall be written to standard output. The common file extensions for RDF/XML, Turtle, N3 and N-TRIPLE are .rdf, .ttl, .n3 and .nt, respectively.

Running

java your_java_program test.n3 RDF/XML > test.rdf

should convert the file test.n3, which is assumed written in N3, to RDF/XML format and write to the file test.rdf.

1.2.2 Exercise

Using your RDF syntax converter program, convert the Simpsons RDF graph you wrote in last week's exercise to RDF/XML.

1.2.3 Exercise

Using your RDF syntax converter program, convert the Simpsons RDF graph you wrote in last week's exercise to Turtle.

1.2.4 Exercise

Using your RDF syntax converter program, convert the Simpsons RDF graph you wrote in last week's exercise to N3.

1.2.5 Exercise

Using your RDF syntax converter program, convert the Simpsons RDF graph you wrote in last week's exercise to N-Triples.

1.2.6 Exercise

Explain the differences between the four RDF serialisations. Illustrate your points with examples from the RDF conversions done in these exercises.

See also http://www.w3.org/DesignIssues/Notation3.html.

1.3 Browsing RDF using Jena

In these exercises we will learn more about Jena by making a program that browses FOAF RDF graphs for friends.

1.3.1 Exercise

Make a java program which reads a FOAF file and lists the names of all the persons the FOAF person knows and the names of who they again know, i.e., all friends and the friends of these friends. The program should not use queries. You can assume that the name of a person is located in a foaf:name element and the foaf file of a person is located in a rdfs:seeAlso element—just like how your own FOAF file should look like if generated by the FOAF-a-Matic.

1.3.1.1 Tip

Running your program on Martin G. Skj?veland's FOAF file should give you something like this

Martin G. Skj?veland's friends:
   Martin Giese
      Arild Waaler
      Bruno Buchberger
      Roar Fjellheim
      David Norheim
      Renate Schmidt
      Reiner H?hnle
      Kjetil Kjernsmo
   Robert Engels

1.3.2 Exercise

Run your program on your own FOAF file.

1.4 RDF summary program

When opening OWL ontologies in ontology editors it is common to be presented with some metrics about the ontology, e.g., how many classes and relationships there are and what kinds of axioms are used. In this exercise we will create a similar program, but for RDF graphs.

1.4.1 Exercise

Write a program which reads an RDF file and outputs

  • the total number of triples in the file
  • the number of distinct subjects, predicates and objects in the graph
  • all types, e.g., all objects in a triple where rdf:type is the predicate, and the distinct members of these types
1.4.1.1 Tip

Running your program with the following graph as input

1:  @prefix :    <http://example.com/> .
2:  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3:  
4:   :m rdf:type :A .
5:   :n rdf:type :A .
6:   :m :r       :o .
7:   :q :r       :n .

should give a result equivalent of the following:

RDF metrics: summary_test.n3
No. of triples: 4
No. of subject: 3
No. of predicates: 2
No. of objects: 3

TYPES:
http://example.com/A
   http://example.com/n
   http://example.com/m

1.4.2 Exercise

Use your program to analyse your FOAF file.

1.4.3 Exercise

Use your program to analyse Martin Giese's FOAF file.

1.4.4 Exercise

Use your program to analyse your Simpsons RDF file.

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

Date: 2010-03-12 15:36:35 CET

HTML generated by org-mode 6.34trans in emacs 23