Master MIASHS UFR SHS, Université Grenoble Alpes
Manuel Atencia 2017-‐2018
Web Sémantique
TD 1 -‐ RDF Exercice 1 La table suivante (Table 1) montre un échantillon de données d’une base de données relationnelle sur des produits. Dessinez un graphe qui reflète le contenu dans la table. Sérialisez le graphe en format N-‐Triples. (Vous n’avez pas besoin de compléter le graphe RDF entier ni sa sérialisation)
Product
ID
Model Number
Division
Product Line
Manufacture Location
SKU
Available
1 ZX-3 Manufacturing Support
Paper Machine
Sacramento FB3524 23
2 ZX-3P Manufacturing Support
Paper Machine
Sacramento KD5243 4
3 B-1430 Control engineering
Feedback line
Elizabeth KS4520 23
4 DBB-12 Accessories Monitor Hong Kong ND5520 100 5 SP-1234 Safety Safety Value Cleveland HI4554 5
Table 1 Correction :
Avec N-Triples : <http://www.mycompany.com/data/product1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.mycompany.com/ontology#Product> . <http://www.mycompany.com/data/product1> <http://www.mycompany.com/ontology#id> "1"^^http://www.w3.org/2001/XMLSchema#int . <http://www.mycompany.com/data/product1> <http://www.mycompany.com/ontology#modelNumber> "ZX-3"^^http://www.w3.org/2001/XMLSchema#string . ...
"1"^^http://www.w3.org/2001/XMLSchema#int
http://www.mycompany.com/data/product1
"ZX-3"^^http://www.w3.org/2001/XMLSchema#string
http://www.mycompany.com/ontology#modelNumber
http://www.mycompany.com/ontology#Product
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.mycompany.com/ontology#id
...
Exercice 2 Considérons le graphe de la Figure 1.
Figure 1
1. Est-‐il bien formé ? Pourquoi ? Non, parce qu'un literal (“La peste”) ne peut pas être le sujet d’une déclaration RDF.
2. Proposez une alternative.
3. Donnez la signification intuitive de ce graphe. Quelqu’un, dont son nom est “Albert”, a écrit un roman dont son titre est “La Peste”.
4. Sérializez-‐le en format Turtle. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntaxns#> . @prefix dcterms: <http://purl.org/dc/terms/> . @prefix liv: <http://www.exemple.org/livres#> . [ foaf:name "Albert" ; liv:aEcrit [ rdf:type liv:Roman ; dcterms:title "La Peste" . ] .
Exercice 3
Représentez le document suivant sous forme de graphe RDF : <?xml version=“1.0”?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntaxns#" xmlns:lib="http://www.example.org/library#"> <rdf:Description rdf:about="http://www.example.org/library#RD"> <rdf:type rdf:resource="http://www.example.org/library#Author"/>
"Albert" "La peste"foaf:name ex:aEcrit
ex:Roman
rdf:type
"Albert"foaf:name ex:aEcrit
ex:Roman
rdf:type
"La Peste"
dcterms:title
<lib:firstName>Roald</lib:firstName> <lib:lastName>Dahl</lib:lastName> <lib:books> <rdf:Bag> <rdf:_1 rdf:resource="http://www.example.org/library#Matilda"/> <rdf:_2 rdf:resource="http://www.example.org/library#TheBFG"/> </rdf:Bag> </lib:books> </rdf:Description> <lib:Author rdf:about="http://www.example.org/library#JC"> <lib:firstName>Joseph</lib:firstName> <lib:lastName>Conrad</lib:lastName> <lib:books> <rdf:Bag> <rdf:li rdf:resource="http://www.example.org/library#HeartOfDarkness"/> <rdf:li rdf:resource="http://www.example.org/library#LordJim"/> </rdf:Bag> </lib:books> </lib:Author> <lib:Book rdf:about="http://www.example.org/library#Matilda"> <lib:pages rdf:datatype="http://www.w3.org/2001/XMLSchema#int">240</lib:pages> <lib:copy> <rdf:Seq> <rdf:li rdf:resource="http://www.example.org/library#M124"/> <rdf:li rdf:resource="http://www.example.org/library#M125"/> <rdf:li rdf:resource="http://www.example.org/library#M126"/> </rdf:Seq> </lib:copy> </lib:Book> <lib:Book rdf:about="http://www.example.org/library#TheBFG" lib:pages="208"> <lib:copy rdf:resource="http://www.example.org/library#B458"/> </lib:Book> <lib:Book rdf:about="http://www.example.org/library#HeartOfDarkness" lib:pages="110"> <lib:copy rdf:resource="http://www.example.org/library#H16"/> </lib:Book> <lib:Book rdf:about="http://www.example.org/library#LordJim" lib:pages="314"> <lib:copy rdf:resource="http://www.example.org/library#L187"/> </lib:Book> </rdf:RDF> Exercice 4
Représentez les faits suivants sous la forme de graphe puis en Turtle et RDF/XML :
1. Marie est la femme de Jean. Avec RDF/XML : <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntaxns#" xmlns:fam="http://www.exemple.org/famille#"> <rdf:Description rdf:about="http://www.exemple.org/famille#Marie"> <fam:estFemmeDe rdf:resource="http://www.exemple.org/famille#Jean"> </rdf:Description> Une alternative : <?xml version="1.0"?> <!DOCTYPE rdf:RDF [ <!ENTITY fam "http://www.exemple.org/famille#"> ]> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntaxns#" xmlns:fam="http://www.exemple.org/famille#”> <rdf:Description rdf:about="&fam;Marie"> <fam:estFemmeDe rdf:resource="&fam;Jean"> </rdf:Description>
Avec Turtle : @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntaxns#> . @prefix fam: <http://www.exemple.org/famille#> . fam:Marie fam:estFemmeDe fam:Jean .
2. L'image :
http://upload.wikimedia.org/wikipedia/commons/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg
décrit une peinture d’un artiste appelé Leonardo Da Vince, né en 1452 et mort en 1519. Avec RDF/XML : <?xml version=”1.0”?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntaxns#" xmlns:imgOnt="http://www.exemple.org/images/ontologie#">
<rdf:Description rdf:about="http://upload.wikimedia.org/wikipedia/commons/e/ec/ Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg"> <rdf:type rdf:resource="http://www.exemple.org/images/ontologie#Image"> <imgOnt:decrit rdf:nodeID="P167"> </rdf:Description> <rdf:Description rdf:nodeID="P167"> <rdf:type rdf:resource="http://www.exemple.org/images/ontologie#Peinture"> <imgOnt:aEtePeintPar rdf:nodeID="A78"> </rdf:Description> <rdf:Description rdf:nodeID="A78"> <rdf:type rdf:resource="http://www.exemple.org/images/ontologie#Artiste"> <imgOnt:nom>Leonardo Da Vince</img:nom> <imgOnt:ne>1452</img:ne> <imgOnt:mort>1519</img:mort> </rdf:Description> Avec Turtle : @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntaxns#> . @prefix imgOnt: <http://www.exemple.org/images/ontologie#> .
<http://upload.wikimedia.org/wikipedia/commons/e/ec/ Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg> a img:Image; img:decrit [ a Peinture ; img:aEtePeintPar [ a Artiste ; imgOnt:nom "Leonardo" ; imgOnt:ne "1452" ; imgOnt:mort "1519" . ] . ] . ou
<http://upload.wikimedia.org/wikipedia/commons/e/ec/ Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg> a img:Image; imgOnt:decrit _:P167 . _:P167 a Peinture ; imgOnt: aEtePeintPar _:A78 . _A78 a Artiste ; imgOnt:nom "Leonardo" ; imgOnt:ne "1452" ; imgOnt:mort "1519" .
3. Le quatre-‐quarts (aussi appelé quatre-‐quart ou encore pound cake en anglais) contient 3 oeufs, 200g de farine, 200g de sucre, 200g de beurre.
Avec RDF/XML :
<?xml version=”1.0”?> <!DOCTYPE rdf:RDF [ <!ENTITY xsd “http://www.w3.org/2001/XMLSchema#”> <!ENTITY rcp “http://www.example.org/recipes#”> ] > <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntaxns#" xmlns:rcp="http://www.example.org/recipes#"> <rdf:Description rdf:about="&rcp;quatre-quarts"> <rcp:name rdf:datatype="&xsd;string">Quatre-Quarts</rcp:name> <rcp:name rdf:datatype="&xsd;string">Pound Cake<rcp:name> <rcp:ingredients rdf:parseType="Collection”/> <rdf:Description rdf:parseType="Resource"> <rdf:type rdf:resource="&rcp;Ingredient"/> <rcp:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">oeufs</rcp:name> <rcp:quantity rdf:datatype="http://www.w3.org/2001/XMLSchema#int">3</rcp:quantity> </rdf:Description> <rdf:Description rdf:parseType="Resource"> <rdf:type rdf:resource="http://www.example.org/recipes#Ingredient"/> <rcp:name rdf:datatype="&xsd;string">farine</rcp:name> <rcp:quantity rdf:datatype=”&xsd;int">200</rcp:quantity> <rcp:unit rdf:datatype="&xsd;string">grames</rcp:unit> </rdf:Description> <rdf:Description rdf:parseType="Resource"> <rdf:type rdf:resource="&rcp;Ingredient"/> <rcp:name rdf:datatype="&xsd;string">sucre</rcp:name> <rcp:quantity rdf:datatype=”&xsd;int">200</rcp:quantity> <rcp:unit rdf:datatype="&xsd;string">grames</rcp:unit> </rdf:Description> <rdf:Description rdf:parseType="Resource"> <rdf:type rdf:resource="&rcp;Ingredient"/> <rcp:name rdf:datatype="&xsd;string">beurre</rcp:name> <rcp:quantity rdf:datatype=”&xsd;int">200</rcp:quantity> <rcp:unit rdf:datatype="&xsd;string">grames</rcp:unit> </rdf:Description> </rcp:ingredients> </rdf:Description> </rdf:RDF> Avec Turtle : @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntaxns#>. @prefix rcp: <http://www.example.org/recipes#>. @prefix xsd: <http://www.w3.org/2001/XMLSchema#>. <http://www.example.org/recipes#quatre-quarts> rcp:name "Quatre-Quarts", "Pound Cake"; rcp:ingredients (_:igd1 _:igd2 _igd3 _:igd4). _:igd1 a rcp:Ingredient; rcp:name "oeufs"; rcp:quantity "3"^^xsd:int. _:igd2 a rcp:Ingredient; rcp:name "farine”; rcp:quantity "200"^^xsd:int; rcp:unit "grammes"^^xsd:string. _:igd3 a rcp:Ingredient; rcp:name "sucre"; rcp:unit "grammes"^^xsd:string. _:igd4 a rcp:Ingredient; rcp:name "beurre"; rcp:unit "grammes"^^xsd:string.
4. Un des livres écrit par Henry Chivas déclare que Mr. Jack Daniel connait quelqu'un qui connait également Johnnie Walker.
Avec RDF/XML : <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntaxns#" xmlns:whi="http://www.example.org/whisky#">
<rdf:Description rdf:nodeID="bn1"> <rdf:type rdf:resource="http://www.example.org/whisky#Book"/> <whi:author> <rdf:Description rdf:about="http://www.example.org/whisky#HenryChivas"> <whi:firstName>Henry</whi:firstName> <whi:lastName>Chivas</whi:lastName> </rdf:Description> </whi:author> <whi:asserts> <rdf:Description rdf:parseType="Resource"> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntaxns#Statement"/> <rdf:Subject> <rdf:Description rdf:about="http://www.example.org/whisky#JackDaniel"> <whi:firstName>Jack</whi:firstName> <whi:lastName>Daniel</whi:lastName> </rdf:Description> </rdf:Subject> <rdf:Predicate rdf:resource:"http://www.example.org/whisky#knows"/> <rdf:Object> <rdf:Description rdf:parseType="Resource"> <whi:knows> <rdf:Description rdf:about="http://www.example.org/whisky#JohnyWalker"> <whi:firstName>Jonhy</whi:firstName> <whi:lastName>Walker</whi:lastName> </rdf:Description> </whi:knows> </rdf:Description> </rdf:Object> </rdf:Description> </whi:asserts> </rdf:Description> </rdf:RDF> Avec Turtle : @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntaxns#>. @prefix whi: <http://www.example.org/whisky#>. _:bn1 a whi:Book; whi:author <http://www.example.org/whisky#HenryChivas>; whi:asserts _:st1. <http://www.example.org/whisky#HenryChivas> whi:firstName "Henry"; whi:lastName "Chivas". <http://www.example.org/whisky#JackDaniel> whi:firstName "Jack"; whi:lastName "Daniel". _:st1 a rdf:Statement; rdf:Subject <http://www.example.org/whisky#JackDaniel>; rdf:Predicate <http://www.example.org/whisky#knows>; rdf:Object _:bn2.
_:bn2 whi:knows <http://www.example.org/whisky#JohnyWalker>.