Principe
Décrire les relations entre les données que l’on cherche
sous forme d’un sous-graphe .
homogénéité entre le langage de description des données
et le langage de requête
digraph exemple1 {
udos [label="udos"]
i [label="?i"]
n [label="?n" fillcolor=lightblue]
a [label="?a" fillcolor=lightblue]
i -> udos [label="intervient"]
i -> n [label="nom"]
i -> a [label="adresse"]
}
Trouver les noms et adresses des intervenants d’UDOS.
digraph exemple2 {
pa [label="pa.champin"]
k [label="?k"]
c [label="?c"]
n [label="?n" fillcolor=lightblue]
pa -> k [label="connais"]
c -> k [label="fondateur"]
c -> n [label="siren"]
}
Trouver les numéros de SIREN des entreprises fondées par les gens que je connais.
Préfixes
PREFIX s: <http://schema.org/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
# ...
s:Event
→ <http://schema.org/Event>
s:startDate
→ <http://schema.org/startDate>
s:endDate
→ <http://schema.org/endDate>
owl:sameAs
→ <http://www.w3.org/2002/07/owl#sameAs>
...
mécanisme similaire aux NS XML → préfixe indifférent
évite de manipuler de long IRIs
on peut toujours utiliser des IRIs complets au besoin
Termes
s:Event
IRI abrégé
<http://example.org/>
IRI complet
"hello world"
Litéral chaîne
42 3.14 1e-10
Litéraux numérique
?x
Variable
liste incomplète
mais suffisante pour ce tutoriel
Triplet
Chaque arc du graphe est représenté par un triplet :
<http://champin.net/#pa> rdf:type s:Person .
digraph triplet {
s[label="http://champin.net/#pa"]
o[label="s:Person"]
s->o[label="rdf:type"]
}
Sujet Prédicat Objet
Notez le point ;
les espaces ou retours à la ligne ne sont pas significatifs
Graphe
Le graphe requête est l’union des arcs.
<http://champin.net/#pa> rdf:type s:Person .
<http://champin.net/#pa> foaf:knows ?x .
?x foaf:surname "Zigmann" .
digraph graphe {
person[label="s:Person"]
me[label="http://champin.net/#pa"]
x[label="?x"]
zigmann[label="\"Zigmann\"" shape=rect]
me -> person [label="rdf:type"]
me -> x [label="foaf:knows"]
x -> zigmann [label="foaf:surname"]
}
Factorisation (1)
Même sujet :
<http://champin.net/#pa>
rdf:type s:Person ;
foaf:knows ?x .
digraph factorisation1 {
person[label="s:Person"]
me[label="http://champin.net/#pa"]
x[label="?x"]
me -> person [label="rdf:type"]
me -> x [label="foaf:knows"]
}
Factorisation (2)
Même sujet et même prédicat :
<http://champin.net/#pa> foaf:knows ?x , ?y .
digraph factorisation2 {
me[label="http://champin.net/#pa"]
x[label="?x"]
y[label="?y"]
me -> x [label="foaf:knows"]
me -> y [label="foaf:knows"]
}
Sous-graphe optionnel
<http://champin.net/#pa> foaf:knows ?x .
OPTIONAL { ?x schema:address ?addr }
digraph optional {
"http://champin.net/#pa" -> "?x" [label="foaf:knows"]
"?x" -> "?addr" [label="schema:address",style=dotted]
"?addr"[style=dotted]
}
par opposition à
<http://champin.net/#pa> foaf:knows ?x .
?x schema:address ?addr .
digraph non_optional {
"http://champin.net/#pa" -> "?x" [label="foaf:knows"]
"?x" -> "?addr" [label="schema:address"]
}
récupère toutes les personnes que je connais
et leur adresse si elles en ont une, null
sinon
jointure à gauche vs. jointure
Filtres
<http://champin.net/#pa> foaf:knows ?x .
?x s:birthDate ?bd .
FILTER ( STR ( ?bd ) > "1999-06" )
Sélection
SELECT ?p ?n {
<http://champin.net/#pa> foaf:knows ?x .
?x foaf:givenName ?p ;
foaf:suename ?n ;
foaf:age ?a .
FILTER ( ?a >= 18 )
}
digraph factorisation1 {
filter1 [label="?a >= 18" shape=note]
me[label="http://champin.net/#pa"]
x[label="?x"]
p[label="?p" fillcolor=lightblue]
n[label="?n" fillcolor=lightblue]
a[label="?a"]
me -> x [label="foaf:knows"]
x -> p [label="foaf:givenName"]
x -> n [label="foaf:surname"]
x -> a [label="foaf:age"]
}
la clause SELECT
autour du sous-graphe est obligatoire
Comme en SQL, on peut également utiliser SELECT *
pour garder toutes les variables du sous-graphe