SPARQL in a nutshell

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

5 comments

Comments 1 - 5 of 5 previous next Post a comment

  • + novathn novathn 7 months ago
    It’s a great slide :)
    Ur slide’s simple and easy to understand :)

    Thx a lot
  • + fabien_gandon Fabien Gandon 2 years ago
    sorry 'guest9159040' but I don’t see your point.
  • + guest9159040 guest9159040 2 years ago
    Hi the query in slide 28 is not correct. If we have this rdf file (turtle format):
    @prefix : .
    :A a :Person .
    :B a :Person .
    :C a :Person .
    :A :knows 'java' .
    :B :knows 'python' .
    :B :knows 'java' .
    :C :knows 'c++' .
    :C :knows 'python'.
    The right query is :
    PREFIX :
    SELECT DISTINCT ?1 ?x
    FROM
    WHERE {
    ?1 a :Person.

    OPTIONAL {
    ?1 :knows ?x
    FILTER (?x = 'java').
    }
    FILTER (!BOUND(?x)).


    }

    The Answer is C
    Thanks for your helpful material

    Antonio Penta
    a.penta@unina.it
  • + fabien_gandon Fabien Gandon 2 years ago
    Thanks ! I’ll try to update the ones that are changing like RDFa and OWL 1.1
  • + guest2616c8 guest2616c8 2 years ago
    Thanks a lot Fabien your slides about the semantic web are really helpful, keep up the good work!
Post a comment
Embed Video
Edit your comment Cancel

10 Favorites & 2 Groups

SPARQL in a nutshell - Presentation Transcript

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

+ Fabien GandonFabien Gandon, 2 years ago

custom

4318 views, 10 favs, 1 embeds more stats

Tutorial on SPARQL

More info about this document

CC Attribution License

Go to text version

  • Total Views 4318
    • 4303 on SlideShare
    • 15 from embeds
  • Comments 5
  • Favorites 10
  • Downloads 192
Most viewed embeds
  • 15 views on http://www-sop.inria.fr

more

All embeds
  • 15 views on http://www-sop.inria.fr

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories

Groups / Events