SPARQL Query Forms

23
a division of Publishing Technology SPARQL Query Forms Leigh Dodds, Oxford SWIG, March 2008 Photo Credit: Glen Bowman

description

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

Transcript of SPARQL Query Forms

Page 1: SPARQL Query Forms

a division of Publishing Technology

SPARQL Query Forms

Leigh Dodds, Oxford SWIG, March 2008

Photo Credit: Glen Bowman

Page 2: SPARQL Query Forms

a division of Publishing Technology

Why are there 4 SPARQL Query Forms?

SPARQL Use Cases doesn’t help very much…

Page 3: SPARQL Query Forms

a division of Publishing Technology

…neither does the SPARQL specification

SELECTReturns all, or a subset of, the variables bound in a query pattern match.

CONSTRUCTReturns an RDF graph constructed by substituting variables in a set of triple templates.

ASKReturns a boolean indicating whether a query pattern matches or not.

DESCRIBEReturns an RDF graph that describes the resources found.

Page 4: SPARQL Query Forms

a division of Publishing Technology

What are they for?

Page 5: SPARQL Query Forms

a division of Publishing Technology

SELECT

Equivalent to SQL SELECTReturns a nice, regular table

Page 6: SPARQL Query Forms

a division of Publishing Technology

SELECTPREFIX 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

Page 7: SPARQL Query Forms

a division of Publishing Technology

ASK

Returns a true/false value

Is there data that looks like this?Do you have any information about that?

Page 8: SPARQL Query Forms

a division of Publishing Technology

ASKPREFIX foaf: <http://xmlns.com/foaf/0.1/>

ASK WHERE {

?person a foaf:Person

; foaf:mbox <mailto:[email protected]>.

}

(SPARQL equivalent of a vanity search!)

Page 9: SPARQL Query Forms

a division of Publishing Technology

CONSTRUCT

Returns an RDF graphExtract a specific subset of the queried data

I want this, this, and this

Page 10: SPARQL Query Forms

a division of Publishing Technology

CONSTRUCTPREFIX foaf: <http://xmlns.com/foaf/0.1/>

CONSTRUCT {

?friend a foaf:Person;

foaf:name ?name;

foaf:homepage ?home.

} WHERE {

?person foaf:mbox <mailto:[email protected]>;

foaf:knows ?friend.

?friend foaf:name ?name;

foaf:homepage ?home.

}

Page 11: SPARQL Query Forms

a division of Publishing Technology

DESCRIBE

Returns an RDF graph

Tell me about this or things that look like this…but you decide what’s relevant

Page 12: SPARQL Query Forms

a division of Publishing Technology

DESCRIBEPREFIX foaf: <http://xmlns.com/foaf/0.1/>

DESCRIBE ?friend

WHERE {

?person foaf:mbox “mailto:[email protected]”;

foaf:knows ?friend.

}

Page 13: SPARQL Query Forms

a division of Publishing Technology

Applied Uses

Beyond the basics

Page 14: SPARQL Query Forms

a division of Publishing Technology

DESCRIBE for Prototyping

DESCRIBE <http://example.org/someResource>

Quickly assembling UIsWeb APIs

Page 15: SPARQL Query Forms

a division of Publishing Technology

SELECT for Indexing

Building an ordering over some dataORDER BY, LIMIT

Page 16: SPARQL Query Forms

a division of Publishing Technology

CONSTRUCT for Transformation

…and also simple inferencing

CONSTRUCT could be the XSLT of RDFCurrently limited by lack of expressions in

CONSTRUCT triple templates

Page 17: SPARQL Query Forms

a division of Publishing Technology

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.

}

Page 18: SPARQL Query Forms

a division of Publishing Technology

SPARQL for Validation

XSLT can be used for XML Validation (Schematron)

SPARQL can be used for RDF Validation

Page 19: SPARQL Query Forms

a division of Publishing Technology

Validation – ASK*

ASK WHERE {

#triple patterns that you don’t want to find

}

*Source: Talis Platform Field Predicate Map Validation

Page 20: SPARQL Query Forms

a division of Publishing Technology

Validation – CONSTRUCT*

CONSTRUCT {

#some error message or data

} WHERE {

#triple patterns that you don’t want to find

}

*Source: Alistair Miles, Schemarama 2Jena 2 Validation Support

Page 21: SPARQL Query Forms

a division of Publishing Technology

In Combination?

Page 22: SPARQL Query Forms

a division of Publishing Technology

The ADC Pattern

ASK – DESCRIBE – CONSTRUCT Probe endpoint

Grab default view of dataRefine data extraction and/or apply

transformation

Page 23: SPARQL Query Forms

a division of Publishing Technology

Questions?