Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SPARQL in a nutshell

17,490 views

Published on

Tutorial on SPARQL

Published in: Technology
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/2F4cEJi ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ❶❶❶ http://bit.ly/2F4cEJi ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Fact: Penis Enlargement CAN Work. Here's How. ♣♣♣ https://tinyurl.com/yy3nfggr
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • System for lasting clear skin, How to get flawless complexion ex-sufferer reveals his secrets ♥♥♥ https://bit.ly/2xJfKi2
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Are You Heartbroken? Don't be upset, let Justin help you get your Ex back. ◆◆◆ http://t.cn/R50e2MX
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

SPARQL in a nutshell

  1. 1. S PAR QL in a nutshell fabien, gandon, inria
  2. 2. RDF triple model <ul><li>is the first layer of the semantic web standards </li></ul>
  3. 3. SPARQL on top... <ul><li>an R D F query language and data access protocol </li></ul>
  4. 4. SPARQL stands for <ul><li>S PARQL P rotocol and R DF Q uery L anguage </li></ul>
  5. 5. SPARQL in 3 parts <ul><li>part 1: query language part 2: result format part 3: access protocol </li></ul>
  6. 6. SPARQL query <ul><li>SELECT ... </li></ul><ul><li>FROM ... </li></ul><ul><li>WHERE { ... } </li></ul>
  7. 7. SELECT clause <ul><li>to identify the values to be returned </li></ul>
  8. 8. FROM clause <ul><li>to identify the data sources to query </li></ul>
  9. 9. WHERE clause <ul><li>the triple/graph pattern to be matched against the triples/graphs of RDF </li></ul>
  10. 10. WHERE clause <ul><li>a conjunction of triples: { ?x rdf:type ex:Person </li></ul><ul><li>?x ex:name ?name } </li></ul>
  11. 11. PREFIX <ul><li>to declare the schema used in the query </li></ul>
  12. 12. example <ul><li>persons and their names </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?person ?name WHERE { ?person rdf:type ex:Person ?person ex:name ?name . }
  13. 13. example <ul><li>of result </li></ul><?xml version=&quot;1.0&quot;?> <sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot; > <head> <variable name=&quot; person &quot;/> <variable name=&quot; name &quot;/> </head> <results ordered=&quot;false&quot; distinct=&quot;false&quot;> <result> <binding name=&quot; person &quot;> <uri>http://inria.fr/schema#fg</uri> </binding> <binding name=&quot; name &quot;> <literal>gandon</literal> </binding> </result> <result> ...
  14. 14. FILTER <ul><li>to add constraints to the graph pattern (e.g., numerical like X>17 ) </li></ul>
  15. 15. example <ul><li>persons at least 18-year old </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?person ?name WHERE { ?person rdf:type ex:Person ?person ex:name ?name . ?person ex:age ?age . FILTER (?age > 17) }
  16. 16. FILTER <ul><li>can use many operators, functions (e.g., regular expressions), and even users' extensions </li></ul>
  17. 17. OPTIONAL <ul><li>to make the matching of a part of the pattern optional </li></ul>
  18. 18. example <ul><li>retrieve the age if available </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?person ?name ?age WHERE { ?person rdf:type ex:Person ?person ex:name ?name . OPTIONAL { ?person ex:age ?age } }
  19. 19. UNION <ul><li>to give alternative patterns in a query </li></ul>
  20. 20. example <ul><li>explicit or implicit adults </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?name WHERE { ?person ex:name ?name . { { ?person rdf:type ex:Adult } UNION { ?person ex:age ?age FILTER (?age > 17) } } }
  21. 21. Sequence & modify <ul><li>ORDER BY to sort LIMIT result number OFFSET rank of first result </li></ul>
  22. 22. example <ul><li>results 21 to 40 ordered by name </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?person ?name WHERE { ?person rdf:type ex:Person ?person ex:name ?name . } ORDER BY ?name LIMIT 20 OFFSET 20
  23. 23. UNBOUND <ul><li>test a variable is not bound ; used for negation as failure </li></ul>
  24. 24. example <ul><li>persons who are not known authors </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?name WHERE { ?person ex:name ?name . OPTIONAL { ?person ex:author ?x } FILTER ( ! bound(?x) ) }
  25. 25. negation is tricky and errors can easily be made.
  26. 26. ? <ul><li>does this find persons who do not know &quot;java&quot; ? </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?name WHERE { ?person ex:name ?name . ?person ex:knows ?x FILTER ( ?x != &quot;Java &quot; ) }
  27. 27. NO! <ul><li>also persons who know something else ! </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?name WHERE { ?person ex:name ?name . ?person ex:knows ?x FILTER ( ?x != &quot;Java&quot; ) } fabien ex:knows &quot;Java&quot; fabien ex:knows &quot;C++&quot; fabien is a answer...
  28. 28. YES! <ul><li>persons who are not known to know &quot;java&quot; ... negation of an option... </li></ul>PREFIX ex: < http://inria.fr/schema# > SELECT ?name WHERE { ?person ex:name ?name . OPTIONAL { ?person ex:knows ?x FILTER ( ?x = &quot;Java&quot; ) } FILTER ( ! bound(?x) ) }
  29. 29. ASK <ul><li>to check just if there is at least one answer ; result is &quot;true&quot; or &quot;false&quot; </li></ul>
  30. 30. example <ul><li>is there a person older than 17 ? </li></ul>PREFIX ex: < http://inria.fr/schema# > ASK { ?person ex:age ?age FILTER (?age > 17) }
  31. 31. CONSTRUCT <ul><li>return a specific RDF graph for each result </li></ul>
  32. 32. example <ul><li>return instances of adults for persons older than 17 </li></ul>PREFIX ex: < http://inria.fr/schema# > CONSTRUCT { ?person rdf:type ex:Adult } WHERE { ?person ex:age ?age FILTER (?age > 17) }
  33. 33. SPARQL protocol <ul><li>sending queries and their results accross the web </li></ul>
  34. 34. example <ul><li>with HTTP Binding </li></ul>GET /sparql/?query= <encoded query> HTTP/1.1 Host: www.inria.fr User-agent: my-sparql-client/0.1
  35. 35. example <ul><li>with SOAP Binding </li></ul><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <soapenv:Envelope xmlns:soapenv=&quot;http://www.w3.org/2003/05/soap-envelope/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; > <soapenv:Body> <query-request xmlns=&quot;http://www.w3.org/2005/09/sparql-protocol-types/#&quot; > <query>SELECT ?x ?p ?y WHERE {?x ?p ?y}</query> </query-request> </soapenv:Body> </soapenv:Envelope>
  36. 36. Take-away summary of SPARQL
  37. 37. SPARQL is... <ul><li>... a query language ... </li></ul><ul><li>... a result format ... </li></ul><ul><li>... an access protocol ... </li></ul><ul><li>... for RDF </li></ul>
  38. 38. SPARQL query language <ul><li>based on the triple model ?x ?p ?y </li></ul><ul><li>filters to add constraints </li></ul><ul><li>optional parts and alternative parts </li></ul>
  39. 39. fabien, gandon

×