SPARQL Query Forms Leigh Dodds, Oxford SWIG, March 2008 Photo Credit:  Glen Bowman
Why are there 4 SPARQL Query Forms? SPARQL  Use Cases  doesn’t help very much…
…neither does the SPARQL specification <ul><li>SELECT </li></ul><ul><li>Returns all, or a subset of, the variables bound i...
What are they for?
SELECT Equivalent to SQL SELECT Returns a nice, regular table
SELECT PREFIX table: <http://www.daml.org/2003/01/periodictable/PeriodicTable#> SELECT ?name ?weight WHERE { ?element tabl...
ASK Returns a true/false value Is there data that looks like  this ? Do you have any information about  that ?
ASK PREFIX foaf: <http://xmlns.com/foaf/0.1/> ASK WHERE { ?person a foaf:Person ; foaf:mbox <mailto:leigh@ldodds.com>. } (...
CONSTRUCT Returns an RDF graph Extract a specific subset of the queried data I want  this ,  this , and  this
CONSTRUCT PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT { ?friend a foaf:Person; foaf:name ?name; foaf:homepage ?hom...
DESCRIBE Returns an RDF graph Tell me about  this  or  things that look like this … but you decide what’s relevant
DESCRIBE PREFIX foaf: <http://xmlns.com/foaf/0.1/> DESCRIBE ?friend  WHERE { ?person foaf:mbox “mailto:leigh@ldodds.com”; ...
Applied Uses Beyond the basics
DESCRIBE for Prototyping DESCRIBE <http://example.org/someResource>  Quickly assembling UIs Web APIs
SELECT for Indexing Building an ordering over some data ORDER BY, LIMIT
CONSTRUCT for Transformation … and also simple inferencing CONSTRUCT could be the XSLT of RDF Currently limited by lack of...
CONSTRUCT for Transformation PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX ex: <http://www.example.org/blogger/> CONSTR...
SPARQL for Validation XSLT can be used for XML Validation (Schematron) SPARQL can be used for RDF Validation
Validation – ASK * ASK WHERE { #triple patterns that you don’t want to find } *Source: Talis Platform  Field Predicate Map...
Validation – CONSTRUCT * CONSTRUCT { #some error message or data } WHERE { #triple patterns that you don’t want to find } ...
In Combination?
The ADC Pattern ASK – DESCRIBE – CONSTRUCT  Probe endpoint Grab default view of data Refine data extraction and/or apply t...
Questions?
Upcoming SlideShare
Loading in...5
×

SPARQL Query Forms

6,688

Published on

Examines the different SPARQL query forms to tease out their uses and applications

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,688
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
133
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • SPARQL Query Forms

    1. 1. SPARQL Query Forms Leigh Dodds, Oxford SWIG, March 2008 Photo Credit: Glen Bowman
    2. 2. Why are there 4 SPARQL Query Forms? SPARQL Use Cases doesn’t help very much…
    3. 3. …neither does the SPARQL specification <ul><li>SELECT </li></ul><ul><li>Returns all, or a subset of, the variables bound in a query pattern match. </li></ul><ul><li>CONSTRUCT </li></ul><ul><li>Returns an RDF graph constructed by substituting variables in a set of triple templates. </li></ul><ul><li>ASK </li></ul><ul><li>Returns a boolean indicating whether a query pattern matches or not. </li></ul><ul><li>DESCRIBE </li></ul><ul><li>Returns an RDF graph that describes the resources found. </li></ul>
    4. 4. What are they for?
    5. 5. SELECT Equivalent to SQL SELECT Returns a nice, regular table
    6. 6. SELECT PREFIX table: <http://www.daml.org/2003/01/periodictable/PeriodicTable#> SELECT ?name ?weight WHERE { ?element table:name ?name; table:atomicWeight ?weight. } ORDER BY DESC(?weight) LIMIT 10
    7. 7. ASK Returns a true/false value Is there data that looks like this ? Do you have any information about that ?
    8. 8. ASK PREFIX foaf: <http://xmlns.com/foaf/0.1/> ASK WHERE { ?person a foaf:Person ; foaf:mbox <mailto:leigh@ldodds.com>. } (SPARQL equivalent of a vanity search!)
    9. 9. CONSTRUCT Returns an RDF graph Extract a specific subset of the queried data I want this , this , and this
    10. 10. CONSTRUCT PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT { ?friend a foaf:Person; foaf:name ?name; foaf:homepage ?home. } WHERE { ?person foaf:mbox <mailto:leigh@ldodds.com>; foaf:knows ?friend. ?friend foaf:name ?name; foaf:homepage ?home. }
    11. 11. DESCRIBE Returns an RDF graph Tell me about this or things that look like this … but you decide what’s relevant
    12. 12. DESCRIBE PREFIX foaf: <http://xmlns.com/foaf/0.1/> DESCRIBE ?friend WHERE { ?person foaf:mbox “mailto:leigh@ldodds.com”; foaf:knows ?friend. }
    13. 13. Applied Uses Beyond the basics
    14. 14. DESCRIBE for Prototyping DESCRIBE <http://example.org/someResource> Quickly assembling UIs Web APIs
    15. 15. SELECT for Indexing Building an ordering over some data ORDER BY, LIMIT
    16. 16. CONSTRUCT for Transformation … and also simple inferencing CONSTRUCT could be the XSLT of RDF Currently limited by lack of expressions in CONSTRUCT triple templates
    17. 17. CONSTRUCT for Transformation PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX ex: <http://www.example.org/blogger/> CONSTRUCT { ?person a ex:Blogger. } WHERE { ?person foaf:weblog ?blog. }
    18. 18. SPARQL for Validation XSLT can be used for XML Validation (Schematron) SPARQL can be used for RDF Validation
    19. 19. Validation – ASK * ASK WHERE { #triple patterns that you don’t want to find } *Source: Talis Platform Field Predicate Map Validation
    20. 20. Validation – CONSTRUCT * CONSTRUCT { #some error message or data } WHERE { #triple patterns that you don’t want to find } *Source: Alistair Miles, Schemarama 2 Jena 2 Validation Support
    21. 21. In Combination?
    22. 22. The ADC Pattern ASK – DESCRIBE – CONSTRUCT Probe endpoint Grab default view of data Refine data extraction and/or apply transformation
    23. 23. Questions?
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×