Interroger le Web de données

Interroger le Web de données

UDOS - 10 juillet 2015

Pierre-Antoine Champin (UCBL/LIRIS)

http://champin.net/2015/udos

Web de données

Qu'est-ce que le Web?

Un espace documentaire

  • décentralisé (HTTP)
  • interconnecté (URL)
  • interopérable (HTML)

Qu'est-ce que le Web?

Un espace documentaire

  • décentralisé (HTTP 2014, HTTP 2.0)
  • interconnecté (URL, URI, IRI)
  • interopérable (HTML5, CSS, JS)

Limites

  • Combien Woody Allen a-t-il réalisé de films avec Mia Farrow ?

    13

  • Combien de réalisateurs ont remporté plusieurs fois la palme d’or ?

    7

  • Combiens d’acteurs ont joué dans au moins deux films récompensés par la palme d’or ?

    13

  • Combiens d’acteurs ont joué dans au moins trois films récompensés par la palme d’or ?

    Aucun

  • Combien d’acteurs ont joué dans au moins deux films du même réalisateur récompensés par la palme d’or ?

    2

Vers un Web de données

Un espace de données

  • décentralisé (HTTP)
  • interconnecté (URL)
  • interopérable (?)

Vers un Web de données

Un espace de données

  • décentralisé (HTTP)
  • interconnecté (URL)
  • interopérable (RDF)
_images/Le-bourgeois-gentilhomme.jpg

RDF

Vocabulaire / Ontologie

  • Ensemble d’IRIs décrivant
    • les catégories du domaine (classes)
    • les propriétés (attributs, relations)
    • les objets du domain

SPARQL

Principe

Décrire les relations entre les données que l’on cherche sous forme d’un sous-graphe.

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"]
}

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"]
}

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>

...

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

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"]
}

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 }

par opposition à

<http://champin.net/#pa> foaf:knows ?x.
?x schema:address ?addr .

Filtres

<http://champin.net/#pa> foaf:knows ?x.
?x foaf:age ?a.
FILTER ( 18 <= ?a && ?a < 62 )

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"]
}

À vous de jouer

http://champin.net/2015/udos/tuto

Pour aller plus loin

Trouver des sources de données

Yasgui, fonctions avancées

  • représentations graphiques
  • tableau croisé

Requêtes fédérées

PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?artist ?work WHERE {
    ?artist dbo:birthPlace dbr:Lyon.
    SERVICE <http://dbtune.org/musicbrainz/sparql> {
      ?a2 owl:sameAs ?artist ; foaf:maker ?work.
    }
}

Linked Data Fragments

http://linkeddatafragments.org/

RDB 2 RDF

Choisir un vocabulaire

http://lov.okfn.org/

Merci