Semantic Web Technologies labs
The page for the lectures can be found here.
This page contains the exercises for the labs which are on
Wednesdays from 14:00 - 16:00 in computer room E331.
Please send your solutions for the exercises by email
to jos.debruijn AT deri.org by the next Tuesday. The
format for the solutions is mentioned under the heading
Output for each exercise.
The goal of the lab exercises is to give you hands-on
experience in using Semantic Web Technologies. The tools we use
in the labs are Protege, an ontology
modeling tool, Jena, a Java framework for
RDF and OWL, and FLORA-2, an F-Logic reasoner
based on XSB.
Contents
- Your first ontology
- Querying your ontology
- Extending your ontology to OWL
- Manipulating your ontology with Jena
- F-Logic Modeling and Reasoning with FLORA-2
- Information Integration with FLORA-2
- Service Discovery with FLORA-2
1. Your first ontology (26 April 2006)
Use Protege to
model an ontology. The domain to model is the university domain.
Model universities, faculties, courses, university employees,
professors, students, etc. Make sure to include also some
instance information; include at least the university of Bolzano,
yourself, a number of courses and a number of professors you know
at the university, and the relations between them.
Save the project as RDF files and have a look inside. You will
see an RDFS file which contains the ontology and an RDF file
which contains the instance data.
Output
Make sure to create an "RDF" project in Protege. The output
consists of all the files generated by Protege.
Make sure to select "plain RDF" when saving the project.
The output of the exercise consists of the RDF and RDFS files
included in the project.
Reading
2. Querying your ontology (3 May 2006)
Use Jena to
query your ontology. Find a simple introduction into using Jena to query SPARQL
here.
You can use the ARQ command line utilities
to test SPARQL queries. You may have to download the ARQ distribution separately to obtain the command line
utilities.
Create a Java application to query your ontology (both RDF and RDFS files). Issue (variants of) the
following queries:
- Retrieve all classes
- Retrieve universities with at least two employees
- A query where you show the use of the OPTIONAL attribute
- A query where you use the BOUND filter in a meaningful way
Output
The output of the exercise consists of the java sources which you used to query the ontology, the queries
in a separate file and RDF data and, finally, a file containing
the query results. Please include some comments in the query files to indicate what the query is meant to do.
Reading
3. Extending your ontology to OWL (10 May 2006)
Use the OWL functionality of Protege to extend your ontology with
constraints and Boolean class combinations.
In order to use the full OWL functionality of Protege, follow the following steps:
- Open your RDFS ontology
- Choose File -> Export to Format -> OWL to export your ontology in OWL format.
- Close your project
- Create a new project of type OWL Files and make sure to check the box Create from Existing Sources.
- Select the OWL file which you exported
- As default namespace choose http://example.org/name-of-ontology#.
- Choose the language profile OWL DL.
- Choose the Logic View
Extend the universities using property restrictions and boolean conclusions as you see fit. Make sure you use at least
some cardinality restrictions, some existential and universal restrictions and some boolean combinations.
Output
The OWL files of the ontology.
Reading
4. Manipulating your ontology with Jena (17 May 2006)
Use the Jena 2 ontology API to
manipulate your ontology using a Java program:
- Extend your ontology with at
least one additional class and one property,
- add the instance data from the RDF file created in the first exercise to the
ontology using the Jena 2 RDF API, and
- save the ontology to an OWL file.
Output
- Java sources of the program
- OWL and RDF files used as input
- Output OWL file
Reading
5. F-Logic Modeling and Reasoning with FLORA-2 (24 May 2006)
Create an F-Logic ontology and use FLORA-2 to reason over this ontology. Consult the
FLORA-2 manual to check the actual syntax and the commands to use for loading
F-Logic files into FLORA-2 and executing these queries.
Model the following information using FLORA-2 F-Logic syntax:
- Airbus and Boeing are airplane manufacturers.
- Airplane manufacturers have a name and they manufacture airplanes.
- Airbus manufactures the airplanes a310, a330 and a380. Boeing manufactures the airplanes
b747, b777. a310, a330, a380, b747, and b777 are airplanes.
- Lufthansa and british airways are airlines.
- Lufthansa has three airplanes of type b747 with serial numbers x345, x567, x789, and 2 of type a380 with serial numbers a8766, and
a578; British airways has one airplane of type a330 with serial number a234.
- Each airplane has a total number of flights and a number of flights since the last maintenance.
- If an airplane has had more than 15 flights since the last maintenance, it is scheduled for maintenance.
- The maintenance schedule of each airplane includes information about the date of each
maintenance and the total number of flights the plane has had when the maintenance was done.
- If the last maintenance was more than 100 days ago, the plane is scheduled for maintenance.
- If an airplane has not had maintenance for over 150 days, the plane is grounded.
- Model the planes such that at least one has had more than 15 flights since the last maintenance,
at least one had its last maintenance between 100 and 150 days ago, and one had its maintenance more than 150
days age.
Write queries to check the following:
- Query the manufacturers of which Lufthansa owns airplanes.
- Query which airplanes are scheduled for services at Lufthansa, and British Airways, respectively
- Query which airplanes are grounded at Lufthansa, and British Airways, respectively
Make sure the programs use the extension flr, e.g. myOntology.flr. Load the program in flora
using flLoad myOntology. Execute query by entering the body of the query, following by a dot '.', e.g.
?- X:person.
Any term starting with a capital is a variable! Object identifiers start with a lower-case letter!
End every fact and every rule with a dot '.'!
Find an example program here. Queries you might want to try
are ?- X:person. and ?- X:singleParent. Find example output for the query
?- X:person. here
Output
- FLORA-2 program
- A separate file for each query with the query and the answers
Reading
6. Information Integration with FLORA-2 (31 May 2006)
Use FLORA-2 to create mappings between ontologies in an information
integration scenarion. You are provided with one central ontology, without instance data,
and two local ontologies which contain instance information (see Figure 1 for an overview).
Your task is to implement mappings between the local ontologies and the global ontology.

Figure 1: Global and local ontologies
In detail, do the following:
- import the cars, carsmanufacturing, and
carssales ontologies in the main module and the modules carsmanufacturing,
and carssales, respectively. You can load a file in a particular module using flora2 ?- [file>>modulename]. You can
load a file in the main module using flora2 ?- flLoad file..
- create a file mapping.flr which contains the mapping rules from the local ontologies to
the global ontology. Use @modulenameafter a molecule to indicate the module. For example:
X:car :- X:car@cars-sales. specifies a mapping between the class 'cars' in the modules cars-sales,
to the class 'cars' in the module cars.
- Query the global ontology for all cars, with all part, all customers and the size of the cars. Make sure this includes also all
smallCars and all bigCars.
Output
- mapping.flr
- A separate file for each query with the query and the answers
Reading
7. Service Discovery with FLORA-2 (6 June 2006)
Use FLORA-2 to model ontologies and services and implement
a simple discovery mechanism. A simple services ontology in which services and goals can be described using
categories and preconditions/effects can be found here.
The example file also contains services categories in the
areas of book selling and computer selling. Additionally, a number of preconditions and effects
are given. For simplicity, conditions are simply constants organized in a hierarchy using ::.
The example file additionally contains an example goal description
and an example service description, as well as a simple matching mechanism based on categories. You
will see that the example goal and service match.
Assignment
- Create a service and a goal description which do not match using the simple category mechanism.
- Implement a matching mechanism based on preconditions and effects such that if the precondition of
the goal is a subclass of the precondition of the service and the effect of the service is a
subclass of the effect of the goal, then the service and the goal match.
- You will see that the example service and goal do not match using this new matching
mechanism. Create two service descriptions with different preconditions and effects which both
match with either the example goal or the goal created in step 1.
Output
- the extended services.flr
Reading