Exercise corresponding to a possible exam IKT437 – 2015
Exam lasts 4 hours; all written and printed material is allowed on the exam.
Please note: This is just one example of an exam.

Task 1

The following tables describe the content of a relational database:


(a) Suggest a corresponding UML class diagram that captures the table structure.

(b) Suggest a corresponding UML object diagram for the content of the tables. Use the class diagram from point (a).


(c) Use your class diagram and propose RDF triples to represent it in OWL – use the Turtle notation. Also, represent the object diagram in the same way.

Assuming that a default namespace is defined.

Classes:

:Student rdf:type owl:class .
:Course rdf:type owl:class .
:Teacher rdf:type owl:class .

:studentIdrdf:type owl:DatatypeProperty ;

rdfs:domain :Student ;

rdfs:range xsd:string .

:name rdf:type owl:DatatypeProperty ;

rdfs:range xsd:string .

:address rdf:type owl:DatatypeProperty ;

rdfs:range xsd:string .

:followCourse rdf:type owl:ObjectProperty;

rdfs:domain :Student ;

rdfs:range :Course;

owl:inverseOf : hasStudent .

:hasStudent rdf:type owl:ObjectProperty ;

rdfs:domain :Course;

rdfs:range :Student ;

owl:inverseOf : followCourse .

Etc. …

Individuals( _:x and _:y are blank nodes):

_:x rdf:type :Student ;
:studentId 101 ;
:name «Ola» ;
:address «Groom» ;
:followCourse _:y ;

_:y rdf:type :Course ;
:courseId «IKT413» ;
:name «OOSD» ;
:address «Groos» ;
: hasStudent _:x ;

Etc.

(d) Finally, make corresponding Java classes


Task 2

The following class diagram is given:

See end of document for a list of OCL constructs that you may use.

(a) Make an OCL constraint that ensures that the value of startTime is less than the value of endTime for objects of class Stay. A timeisgiven as the number of milliseconds since 1970.

context Stay inv:
startTimeendTime

(b) Make an OCL constraint that declares beenOnCrimeSceneto be true if the suspect has been located at the crime scene (not necessarily at the time of the crime) otherwise false.
(This means that for an object of type Suspect there should be a linked Stay object, which is linked to the same Location object as the Crime object).

context Suspectinv :
beenOnCrimeScene = stay.stayedAt->includes(crime.crimeScene)

Been on crime scene at time of crime (assuming onCrimeSceneWhenCrime is attribute of

class Suspect) – NOT ASKED FOR ON EXAM:

context Suspectinv :
onCrimeSceneWhenCrime =

stay->select(e | e. startTime >= self.crime.startTime and
e.endTime <= self.crime.endTime).stayedAt->includes(crime.crimeScene)

The University of Oslo (UiO) is also offering a course in semantic web technology (INF3580 - Semantic technologies / INF4580 - Semantic technologies) and they allow us to use their material. Task 3, 4 and 5 are collected from their exams.

Task 3

Consider the RDF document below:

@prefixrdf: < .
@prefix rdfs: < .
@prefix xsd: < .
@prefix foaf: < .
@prefix dbp: < .
@prefix dbp-owl: < .

dbp:Ivo_Caprino a foaf:Person;
dbp-owl:birthPlace _:x ;
dbp-owl:deathPlace _:x ;
dbp-owl:birthDate "1920-02-17"^^xsd:date ;
dbp-owl:deathDate "2001-02-08"^^xsd:date .

_:x a dbp-owl:Place ;
rdfs:label "Oslo"@no, "Oslo"@en ;
dbp-owl:countrydbp:Norway .

Answer the following questions:

(a) Draw a graph representation of this RDF document.

(b) What kind of RDF node does _:x denote in this document?

(c) What kind of RDF node does "1920-02-17"^^xsd:date denote in this document?

(d) The document mentions one resource of type foaf:Person. What does the document say about the name of this person?

(e) Add statements using the given dbp-owl properties and the FOAF vocabulary to say that there is a person who has the name "Fridtjof Nansen", and who is born at the same place as the person already mentioned in the document.

Answer:

(a)Drawing using the following notation:


Proposed Solution:

(b) A blank node. (Representing something named “Oslo” in at least two languages and located in Norway.)

(c) A typed literal. Representing 17 February 1920.

(d) Nothing.

(e) [a foaf:Person ;
foaf:name "Fridtjof Nansen" ;
dbp-owl:birthPlace _:x] .

Task 4

Consider an RDF document that contains information about bands, albums they released, and tracks contained on these albums.

Band names are coded using foaf:name, whereas album and track titles are represented with dc:title. The albums released by a band are given by foaf:made, and the year an album was released with dc:created. Tracks on albums are given with m:hasTrack. Here is an example of some information about one band and some of its recordings:

@prefixrdf: < .
@prefix xsd: < .
@prefix foaf: < .
@prefix dc: < .
@prefix m: < .

m:stones a m:Band;
foaf:name "The Rolling Stones" ;
foaf:madem:aftermath, m:exile, m:licks, m:bang .

m:aftermath a m:Album;
foaf:name "Aftermath" ;
dc:created "1966"^^xsd:integer ;
m:hasTrack m:thumb, m:ladyJane .

m:exile a m:Album;
foaf:name "Exile on Main St." ;
dc:created "1972"^^xsd:integer .

m:licks a m:Album;
dc:title "Forty Licks" ;
dc:created "2005"^^xsd:integer ;
m:hasTrack m:jackFlash, m:thumb, m:satisfaction .

m:thumb a m:Track; dc:title "Under My Thumb" .
m:ladyJane a m:Track; dc:title "Lady Jane" .
m:jackFlash a m:Track; dc:title "Jumping Jack Flash" .
m:satisfaction a m:Track; dc:title "Satisfaction" .

Imagine that we have data about many more bands, albums, and tracks. In the queries you write to answer the following questions, you are not required to write out the PREFIX declarations.

(a) Write a query that lists the names of all albums by a band called “The Beatles”.

(b) Write a query that lists the names of all bands who have released albums over a period of at least twenty years.

(c) Some albums (“compilations”) contain tracks that have been published previously. Write a query to list the titles of all albums containing a track that is also contained in an album that was released earlier.

(d) Without using SPARQL 1.1 features or the BOUND function of SPARQL 1.0, it is not possible to write a query that lists all tracks that have not appeared on an earlier album. Say why such a query would be problematic from a semantic web perspective.

(e) If the same song was recorded by different bands, we consider that to be different tracks. In other words, if the same track (i.e. the same resource) appears on albums released by different artists, that’s a mistake. To test whether our data contains any such mistakes, write a query to list the URI and name of all such tracks.

(f) Bands not only make albums, they also make the tracks on the albums. Write a CONSTRUCT query that builds a triple b foaf:made t for each track t on an album released by the band b.

Answer: In all questions:

The task text says dc:title for album titles, but the example triples mistakenly use foaf:name. Answers using either are OK.

(a) SELECT DISTINCT ?name WHERE {
?b a m:Band;
foaf:name "The Beatles";
foaf:made ?a;
?a a m:Album;
dc:title ?name .
}

(b) SELECT DISTINCT ?name WHERE {
?b a m:Band;
foaf:name ?name;
foaf:made ?a1, ?a2 .
?a1 a m:Album;
dc:created ?y1 .
?a2 a m:Album;
dc:created ?y2 .
FILTER (?y1 - ?y2 >= 20) }

(c) SELECT DISTINCT ?title WHERE { [a m:Album; dc:title ?title; dc:created ?y1; m:hasTack ?t ] . [a m:Album; dc:created ?y2; m:hasTack ?t ] . FILTER (?y2 < ?y1) }

(d) Due to the “open world assumption”, there might be both albums not mentioned in the data, and tracks on albums which are not mentioned. Any number of triples will never entail that some track has not appeared on an earlier album, so any answer given by a query could be invalidated by additional information.

(e) SELECT DISTINCT ?t ?name WHERE { ?t a m:Track; dc:title ?name .}

Task 5

Below is an excerpt from an RDFS document that keeps track of the cars and deliveries of a delivery service. We assume that the namespaces dlv, rdf, xsd and rdfs are given.

dlv:Carrdf:typerdfs:Class .
dlv:AssignedCarrdf:typerdfs:Class .
dlv:AssignedCarrdfs:subsetOfdlv:Car .
dlv:destinationrdfs:domaindlv:AssignedCar .
dlv:destinationrdfs:rangedlv:City .
dlv:removalistrdfs:rangedlv:Employee .
dlv:executiverdfs:rangedlv:Employee .
dlv:moverrdfs:subPropertyOfdlv:removalist .
dlv:driverrdfs:subPropertyOfdlv:removalist .
dlv:deliveryDaterdfs:rangexsd:dateTime .
dlv:AV43634 dlv:destinationdlv:Trondhjem .
dlv:driverdlv:BjarneBerg .
dlv:moverdlv:MagneMo .
dlv:moverdlv:HangHiu .
dlv:executivedlv:LinnLarsson .
dlv:deliveryDate "2010-10-26T21:00:00" .
dlv:HJ14522 dlv:destinationdlv:Grorud .
dlv:driverdlv:LinnLarsson .
dlv:moverdlv:HelgeHareide .
dlv:executivedlv:LinnLarsson .
dlv:deliveryDate "2010-09-11T15:00:00" .
dlv:SU56782 rdf:typedlv:Car .

For each of the triples below, determine whether it is derivable from the statements in the document. Justify your answer.

Answers:

(a)dlv:AV43634 rdf:typedlv:AssignedCar .

Yes, since the rdfs:destination has rdfs:domaindlv:AssignedCar, and dlv:AV43634 has a dlv:destination

(b)dlv:AV43634 rdf:typedlv:Car .

Yes, because of (a) and because dlv:AssignedCar is a rdfs:subClassOfdlv:Car. (rdfs:subsetOf in the problem is a typo. Pointing this out and saying the triple can't be derived is also OK)

(c)dlv:SU56782 rdf:typedlv:AssignedCar .

No, it is only known that it is a dlv:Car

(d)dlv:Trondhjemrdf:typedlv:City .

Yes, because dlv:AV43634dlv:destinationdlv:Trondhjem and dlv:destinationrdfs:rangedlv:City .

(e)dlv:Grorudrdf:typedlv:City .

Yes, for the same reason as before, for dlv:HJ14522

(f)dlv:HJ14522 dlv:removalistdlv:LinnLarsson .

Yes, since dlv:LinnLarsson is dlv:driver for dlv:HJ14522, and dlv:driver is a rdfs:subPropertyOfdlv:removalist.

(g)dlv:AV43634 dlv:removalistdlv:LinnLarsson .

No, dlv:LinnLarsson is dlv:executive for dlv:AV43634 but that is not a sub-property of dlv:removalist.

(h) _:blankdlv:removalistdlv:MagneMo .

Yes. For this to be true, one needs to be able to assign a resource in the given graph to the blank node, such that the resulting triple occurs in the graph. dlv:AV43634 does the trick.

(i)_:blankdlv:removalist _:blank .

No. This is only one blank node with an edge to itself. The triples contain no dlv:removalist edge from any node to itself, and none can be derived.

(j)dlv:destinationrdf:typerdf:Property .
Yes. dlv:destination occurs as the predicate in some triples, so it has rdf:typerdf:Property according to RDFS semantics.