Upload
leigh-dodds
View
5.425
Download
0
Embed Size (px)
DESCRIPTION
Examines the different SPARQL query forms to tease out their uses and applications
Citation preview
a division of Publishing Technology
SPARQL Query Forms
Leigh Dodds, Oxford SWIG, March 2008
Photo Credit: Glen Bowman
a division of Publishing Technology
Why are there 4 SPARQL Query Forms?
SPARQL Use Cases doesn’t help very much…
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.
a division of Publishing Technology
What are they for?
a division of Publishing Technology
SELECT
Equivalent to SQL SELECTReturns a nice, regular table
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
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?
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!)
a division of Publishing Technology
CONSTRUCT
Returns an RDF graphExtract a specific subset of the queried data
I want this, this, and this
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.
}
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
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.
}
a division of Publishing Technology
Applied Uses
Beyond the basics
a division of Publishing Technology
DESCRIBE for Prototyping
DESCRIBE <http://example.org/someResource>
Quickly assembling UIsWeb APIs
a division of Publishing Technology
SELECT for Indexing
Building an ordering over some dataORDER BY, LIMIT
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
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.
}
a division of Publishing Technology
SPARQL for Validation
XSLT can be used for XML Validation (Schematron)
SPARQL can be used for RDF Validation
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
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
a division of Publishing Technology
In Combination?
a division of Publishing Technology
The ADC Pattern
ASK – DESCRIBE – CONSTRUCT Probe endpoint
Grab default view of dataRefine data extraction and/or apply
transformation
a division of Publishing Technology
Questions?