Mise à jour du 6/11/2013
SELECT
et CONSTRUCT
), ainsi que le mécanisme de contraintes FILTER
./$JENAROOT/bin/sparql
et ses options, en donnantFROM
contient le chemin (ou l'URL) du fichier de données$JENAROOT/bin/sparql --query le_chemin_de_la_requête
$JENAROOT/bin/sparql --data
chemin_données
--query chemin_requête
--results XML
"FROM
" de votre
requête contienne une URL accessible depuis le réseau.)CONSTRUCT
)SELECT
vcard1.rq
PREFIX vcard:
<http://www.w3.org/2001/vcard-rdf/3.0#>
SELECT ?prenom
FROM
<http://pagesperso-systeme.lip6.fr/Jean-Francois.Perrot/inalco/XML/RDF/Exemples/vcardCat.rdf>
WHERE {
?x vcard:N ?c .
?c vcard:Given ?prenom .
}
vcardCat.rdf
"
(ci-dessus) toutes les chaînes (ici désignées par "?prenom
")?x vcard:N ?c
" et "?c
vcard:Given ?prenom
",?c
".%/$JENAROOT/bin/sparql
--query
vcard1.rq
-------------
| prenom |
=============
| "Rebecca" |
| "Matthew" |
| "Sarah" |
| "John" |
-------------
vcard3.rq
PREFIX vcard:
<http://www.w3.org/2001/vcard-rdf/3.0#>
SELECT ?prenom ?x ?c
FROM <vcardCat.rdf>
WHERE {
?x vcard:N ?c .
?c vcard:Given ?prenom .
}
%/$JENAROOT/bin/sparql
--query
vcard3.rq
-------------------------------------------------------
|
prenom |
x
| c |
=======================================================
| "Rebecca" | <http://somewhere/RebeccaSmith/> | _:b0 |
| "Matthew" |
<http://somewhere/MattJones/>
| _:b1 |
| "Sarah" |
<http://somewhere/SarahJones/> | _:b2
|
| "John" |
<http://somewhere/JohnSmith/>
| _:b3 |
-------------------------------------------------------
%/$JENAROOT/bin/sparql
--query
vcard1.rq --results XML
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="prenom"/>
</head>
<results>
<result>
<binding
name="prenom">
<literal>Rebecca</literal>
</binding>
</result>
<result>
<binding
name="prenom">
<literal>Matthew</literal>
</binding>
</result>
<result>
<binding
name="prenom">
<literal>Sarah</literal>
</binding>
</result>
<result>
<binding
name="prenom">
<literal>John</literal>
</binding>
</result>
</results>
</sparql>
ExWiki.rdf
(base-source)<?xml version="1.0" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<foaf:Person
rdf:about="http://example.net/Paul_Dupont">
<foaf:name>Paul
Dupont</foaf:name>
<foaf:img
rdf:resource="http://example.net/Paul_Dupont.jpg"/>
<foaf:knows
rdf:resource="http://example.net/Pierre_Dumoulin"/>
</foaf:Person>
<foaf:Person
rdf:about="http://example.net/Pierre_Dumoulin">
<foaf:name>Pierre
Dumoulin</foaf:name>
<foaf:img
rdf:resource="http://example.net/Pierre_Dumoulin.jpg"/>
</foaf:Person>
<foaf:Image
rdf:about="http://example.net/Paul_Dupont.jpg">
<dc:description>Photo
d'identité de Paul Dupont</dc:description>
</foaf:Image>
<foaf:Image
rdf:about="http://example.net/Pierre_Dumoulin.jpg">
<dc:description>Photo
d'identité de Pierre Dumoulin</dc:description>
</foaf:Image>
</rdf:RDF>
@prefix dc:
<http://purl.org/dc/elements/1.1/> .
@prefix rdf:
<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://example.net/Pierre_Dumoulin>
a
foaf:Person ;
foaf:img
<http://example.net/Pierre_Dumoulin.jpg> ;
foaf:name "Pierre Dumoulin" .
<http://example.net/Paul_Dupont>
a
foaf:Person ;
foaf:img
<http://example.net/Paul_Dupont.jpg> ;
foaf:knows
<http://example.net/Pierre_Dumoulin> ;
foaf:name "Paul Dupont" .
<http://example.net/Paul_Dupont.jpg>
a
foaf:Image ;
dc:description "Photo d'identité de
Paul Dupont" .
<http://example.net/Pierre_Dumoulin.jpg>
a
foaf:Image ;
dc:description "Photo d'identité de
Pierre Dumoulin" .
ExWiki.rq
(requête SPARQL)PREFIX rdf:
<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT DISTINCT ?nom ?image ?description
FROM
<http://pagesperso-systeme.lip6.fr/Jean-Francois.Perrot/inalco/XML/RDF/ExWiki.rdf>
WHERE {
?personne rdf:type foaf:Person .
?personne foaf:name ?nom .
?image rdf:type foaf:Image .
?personne foaf:img ?image .
?image dc:description ?description
}
--------------------------------------------------------------------------------------------------------
|
nom
|
image
|
description
|
========================================================================================================
| "Pierre Dumoulin" | <http://example.net/Pierre_Dumoulin.jpg> |
"Photo d'identité de Pierre Dumoulin" |
| "Paul Dupont" |
<http://example.net/Paul_Dupont.jpg> |
"Photo d'identité de Paul Dupont" |
--------------------------------------------------------------------------------------------------------
ExWiki.sparql
)<?xml version="1.0" ?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="nom"/>
<variable name="image"/>
<variable
name="description"/>
</head>
<results ordered="false" distinct="true">
<result>
<binding
name="nom">
<literal>Pierre Dumoulin</literal>
</binding>
<binding
name="image">
<uri>http://example.net/Pierre_Dumoulin.jpg</uri>
</binding>
<binding
name="description">
<literal>Photo d'identité de Pierre
Dumoulin</literal>
</binding>
</result>
<result>
<binding
name="nom">
<literal>Paul Dupont</literal>
</binding>
<binding
name="image">
<uri>http://example.net/Paul_Dupont.jpg</uri>
</binding>
<binding
name="description">
<literal>Photo d'identité de Paul
Dupont</literal>
</binding>
</result>
</results>
</sparql>
binding
: <!ELEMENT sparql (head, results)>
<!ATTLIST sparql xmlns CDATA #REQUIRED>
<!ELEMENT head (variable*)>
<!ELEMENT variable EMPTY>
<!ATTLIST variable name CDATA #REQUIRED>
<!ELEMENT results (result*)>
<!ATTLIST results ordered (true|false) #IMPLIED>
<!ATTLIST results distinct (true|false) #IMPLIED>
<!ELEMENT result (binding*)>
<!ELEMENT binding (literal|uri)>
<!ATTLIST binding name CDATA #REQUIRED>
<!ELEMENT literal (#PCDATA)>
<!ELEMENT uri (#PCDATA)>
CONSTRUCT
SELECT
renvoie la liste plate des
systèmes de liaisons variable - valeur.CONSTRUCT
est de produire directement
ce graphe RDF contenant les valeurs des variables.vcard:FN
), PREFIX foaf:
<http://xmlns.com/foaf/0.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
CONSTRUCT { ?x vcard:FN ?y }
FROM
<http://pagesperso-systeme.lip6.fr/Jean-Francois.Perrot/inalco/XML/RDF/ExWiki.rdf>
WHERE { ?x foaf:name ?y }
@prefix vcard:
<http://www.w3.org/2001/vcard-rdf/3.0#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://example.net/Pierre_Dumoulin>
vcard:FN
"Pierre Dumoulin" .
<http://example.net/Paul_Dupont>
vcard:FN
"Paul Dupont" .
<?xml version="1.0" ?>
<rdf:RDF
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"
>
<rdf:Description
rdf:about="http://example.net/Pierre_Dumoulin">
<vcard:FN>Pierre Dumoulin</vcard:FN>
</rdf:Description>
<rdf:Description
rdf:about="http://example.net/Paul_Dupont">
<vcard:FN>Paul Dupont</vcard:FN>
</rdf:Description>
</rdf:RDF>
PREFIX foaf:
<http://xmlns.com/foaf/0.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
CONSTRUCT { ?x foaf:firstName ?y .
?x
foaf:lastName ?z .
}
FROM
<http://pagesperso-systeme.lip6.fr/Jean-Francois.Perrot/inalco/XML/RDF/Exemples/vcardCat.rdf>
WHERE
{ ?x vcard:N ?u .
?u vcard:Given
?y .
?u vcard:Family
?z.
}
@prefix vcard:
<http://www.w3.org/2001/vcard-rdf/3.0#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://somewhere/RebeccaSmith/>
foaf:firstName "Rebecca" ;
foaf:lastName "Smith" .
<http://somewhere/JohnSmith/>
foaf:firstName "John" ;
foaf:lastName "Smith" .
<http://somewhere/SarahJones/>
foaf:firstName "Sarah" ;
foaf:lastName "Jones" .
<http://somewhere/MattJones/>
foaf:firstName "Matthew" ;
foaf:lastName "Jones" .
PREFIX foaf:
<http://xmlns.com/foaf/0.1/>
PREFIX dc:
<http://purl.org/dc/elements/1.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
CONSTRUCT { ?auteur foaf:pastProject _:oeuvre .
_:oeuvre
dc:title ?nom .
_:oeuvre
dc:publisher ?editeur .
?auteur foaf:firstName ?p .
?auteur foaf:lastName ?n .
}
FROM
<http://pagesperso-systeme.lip6.fr/Jean-Francois.Perrot/inalco/XML/RDF/Frantext/RRb.rdf>
WHERE
{ ?oe
dc:creator ?auteur .
?oe dc:title
?nom .
?oe
dc:publisher ?editeur .
?auteur vcard:N ?vc .
?vc
vcard:Family ?n .
?vb
vcard:Given ?p .
}
@prefix vcard:
<http://www.w3.org/2001/vcard-rdf/3.0#> .
@prefix dc:
<http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://inalco/M2-Trad/poetes#Théodore_de_BANVILLE>
foaf:firstName "Théodore" ;
foaf:lastName "de BANVILLE" ;
foaf:pastProject
[ dc:publisher "Paris : M. Levy, 1859." ;
dc:title "Odes funambulesques"
] .
FILTER
FILTER
introduit une expression booléenne que
les solutions à la requête doivent satisfaire.foaf:knows
).X foaf:knows X
".vcard:N
" soient différentes. PREFIX foaf:
<http://xmlns.com/foaf/0.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
CONSTRUCT { ?x foaf:knows ?y }
FROM
<http://pagesperso-systeme.lip6.fr/Jean-Francois.Perrot/inalco/XML/RDF/Exemples/vcardCat.rdf>
WHERE
{ ?x
vcard:N ?va .
?va
vcard:Family ?f .
?y
vcard:N ?vb .
?vb
vcard:Family ?f .
FILTER (?va != ?vb )
}
@prefix vcard:
<http://www.w3.org/2001/vcard-rdf/3.0#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://somewhere/RebeccaSmith/>
foaf:knows
<http://somewhere/JohnSmith/> .
<http://somewhere/JohnSmith/>
foaf:knows
<http://somewhere/RebeccaSmith/> .
<http://somewhere/SarahJones/>
foaf:knows
<http://somewhere/MattJones/> .
<http://somewhere/MattJones/>
foaf:knows
<http://somewhere/SarahJones/> .
X foaf:knows Y
", inutile d'ajouter "Y
foaf:knows X
" !STR
va convertir une URI en chaîne, à
laquelle on va pouvoir appliquer la comparaison selon l'ordre
lexicographique.FILTER (?va != ?vb &&
STR(?x) < STR(?y) )
@prefix vcard:
<http://www.w3.org/2001/vcard-rdf/3.0#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://somewhere/JohnSmith/>
foaf:knows
<http://somewhere/RebeccaSmith/> .
<http://somewhere/MattJones/>
foaf:knows
<http://somewhere/SarahJones/> .