Semantic Web Overview
Jump to navigation
Jump to search
Exercises
RDFexamples
1. Family example
<!--
@prefix : <http://www.example.org/> .
:john a :Person .
:john :hasMother :susan .
:john :hasFather :richard .
:richard :hasBrother :luke .
-->
<rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mns="http://www.example.org/#">
<mns:Person rdf:about="http://www.example.org/#john">
<mns:hasMother rdf:resource="http://www.example.org/#susan" />
<mns:hasFather>
<rdf:Description rdf:about="http://www.example.org/#richard">
<mns:hasBrother rdf:resource="http://www.example.org/#luke" />
</rdf:Description>
</mns:hasFather>
</mns:Person>
</rdf>
2. "Breeding" an aunt [-;
@prefix : <http://www.example.org/> .
:richard :hasSister :rebecca
{ ?a :hasFather ?b . ?b :hasSister ?c . } => { ?a :hasAunt ?c } .
3. Uncle is finally "cloned"! Rephrasing the paternity [=
<!--
@prefix : <http://www.example.org/> .
:john a :Person .
:john :hasMother :susan .
:richard :hasBrother :luke .
:richard :isFather :john .
-->
Exercise:
Define this ":john :hasFather :richard .", but in similar way to ":hasAunt".
Define 'luke is an uncle to john'.
Write rdf-schema for it.
4. SPARQL queries
My Apartment
@prefix ex: <http://example.org/> .
@prefix taubz: <http://razor.occams.info/index.html#> .
taubz:me ex:own taubz:my_apartment .
taubz:me ex:own taubz:my_computer .
taubz:my_apartment ex:contains taubz:my_computer .
taubz:my_apartment ex:contains taubz:friends_junk .
taubz:my_apartment ex:location <http://example.org/Philadelphia> .
taubz:me ex:own taubz:my_desk .
taubz:my_desk ex:contains taubz:my_pens_and_pencils .
Ex1
Which resources are in my apartment?
?what
-----------------
taubz:my_computer
taubz:friends_junk
QUERY:
@prefix ex: <http://example.org/> .
@prefix taubz: <http://razor.occams.info/index.html#> .
select ?what
where {
taubz:my_apatement ex:contains ?what.
}
Ex2
Which resources are in my apartment?
Filter the results to contain only the resources that I own.
Ex3
Find resources contained in any object I own.
Ex3.1. Rewrite previous solution: pair ?container and ?what in select clause.