Upload
sebastienne-verdier
View
103
Download
0
Embed Size (px)
Citation preview
LANGAGES DU WEB SÉMANTIQUE
SPARQL Protocol And RDF Query Language
SPARQL
www.w3.org/TR/rdf-sparql-query/Pierre-Yves Vandenbussche
LANGAGES DU WEB SÉMANTIQUE
Langage de requête sur les données RDF (recommandé par W3C en 2008).Protocole d’accès (HTML, SOAP)Langage de présentation des résultats (XML(bindings), RDF)
Syntaxe basé sur Turtle (un sous ensemble de N3)
• Appariement de graphes / projection• Principe courant imitant SQL
Possibilité de retourner • un résultat (clause SELECT)• un nouveau graphe de données (clause CONSTRUCT)• un booléen pour savoir si il y a au moins 1 résultat (clause ASK)
SPARQL
LANGAGES DU WEB SÉMANTIQUE
SPARQL - Exemple
@prefix foaf: <http://xmlns.com/foaf/0.1/> ._:a foaf:name "Johnny Lee Outlaw" ._:a foaf:mbox <mailto:[email protected]> ._:b foaf:name "Peter Goodguy" ._:b foaf:mbox <mailto:[email protected]> ._:c foaf:mbox <mailto:[email protected]> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/>SELECT ?name ?mboxWHERE { ?x foaf:name ?name .?x foaf:mbox ?mbox. }
Données
Requête
Résultat
LANGAGES DU WEB SÉMANTIQUE
En 4 blocs:• PREFIX: déclaration des namespaces utilisés• SELECT: clause sélectionnant les variables à retourner• WHERE: pattern de graphe à matcher
• Un jeu de triplets { (sujet prédicat objet .)*}• FILTER: contraintes exprimées avec des fonctions de tests internes
(XPath 2.0) ou externes • LIMIT/ORDER BY: contraintes sur les résultats retournés
Opérateurs:• OPTIONAL: rendre optionnel la correspondance au graphe• UNION: union ensembliste de plusieurs patterns
SPARQL – en détail
LANGAGES DU WEB SÉMANTIQUE
Dans la clause SELECT: distinct
Dans la clause WHERE: @fr , ^^xsd:integer
Dans la clause FILTER:• Comparateurs: <, >, =, <=, >=, !=• Tests sur les binding des variables:
isURI(?x), isBlank(?x), isLiteral(?x), bound(?x)• Filtres à base d'expressions régulières regex(?x, "A.*")• Accès aux attributs/valeur lang(), datatype(), str()• Fonctions de (re-)typage (casting) xsd:integer(?x)• Fonctions externes / extensions• Combinaisons &&, ||
SPARQL – en détail
LANGAGES DU WEB SÉMANTIQUE
Exemple FILTER
SPARQL – en détail
PREFIX ex: <http://ics.upmc.fr/schema#>SELECT ?person ?nameWHERE {?person rdf:type ex:Person .?person ex:name ?name .?person ex:age ?age .FILTER (?age > 17)}
LANGAGES DU WEB SÉMANTIQUE
Exemple OPTIONAL
SPARQL – en détail
PREFIX ex: <http://ics.upmc.fr/schema#>SELECT ?person ?name ?ageWHERE {?person rdf:type ex:Person .?person ex:name ?name .OPTIONAL { ?person ex:age ?age }}
LANGAGES DU WEB SÉMANTIQUE
Exemple UNION
SPARQL – en détail
PREFIX ex: <http://ics.upmc.fr/schema#>SELECT ?nameWHERE {
?person ex:name ?name .{
{ ?person rdf:type ex:Adult . }UNION{ ?person ex:age ?age .FILTER (?age > 17) }
}}
LANGAGES DU WEB SÉMANTIQUE
Exemple ORDER BY, LIMIT, OFFSET
SPARQL – en détail
PREFIX ex: <http://ics.upmc.fr/schema#>SELECT ?person ?nameWHERE {?person rdf:type ex:Person .?person ex:name ?name .}ORDER BY ?nameLIMIT 20OFFSET 20
LANGAGES DU WEB SÉMANTIQUE
Exemple contraintes
SPARQL – en détail
PREFIX ex: <http://ics.upmc.fr/schema#>SELECT ?nameWHERE {?person ex:name ?name .OPTIONAL { ?person ex:hasFriend ?x }FILTER ( ! bound(?x))}
LANGAGES DU WEB SÉMANTIQUE
Exemple ASK
SPARQL – en détail
PREFIX ex: <http://ics.upmc.fr/schema#>ASK{?person ex:age ?age .FILTER (?age > 17)}
LANGAGES DU WEB SÉMANTIQUE
Exemple CONSTRUCT
SPARQL – en détail
PREFIX ex: <http://ics.upmc.fr/schema#>CONSTRUCT{
?person rdf:type ex:Adult}WHERE{
?person ex:age ?age .FILTER (?age > 17)
}
LANGAGES DU WEB SÉMANTIQUE
SPARQL – Résultats
Deux formes possibles pour la présentation de résultats:• le binding i.e. la liste des valeurs sélectionnées pour chaque réponse
rencontrée; (format XML stable ; bien avec XSLT)• les sous graphes des réponses rencontrées en RDF (format RDF/XML ; bien
pour applications utilisant RDF)
LANGAGES DU WEB SÉMANTIQUE
SPARQL – Protocoles d’accès
Deux protocoles d’accès:• Encapsulé dans HTTP
ex: GET /sparql/?query=<encoded query> HTTP/1.1Host: ics.upmc.frUser-agent: my-sparql-client/0.1
• Par un web service SOAP<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"><soapenv:Body><query-request xmlns="http://www.w3.org/2005/09/sparql-protocol-types/#"><query>SELECT ?x ?p ?y WHERE {?x ?p ?y}</query></query-request></soapenv:Body></soapenv:Envelope>