05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
-
Upload
myles-anthony -
Category
Documents
-
view
232 -
download
0
Transcript of 05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
22/04/23
SPARQL
SPARQL Protocol and RDF Query Language
S. Garlatti
Computer Science Department Semantic Web in Actionpage 2
Outline
SPARQL
Computer Science Department Semantic Web in Actionpage 3
SPARQL: SPARQL Protocol and RDF Query Language
SPARQL
• pronounced "sparkle" [1]) is an RDF query language; its name is a recursive acronym that stands for SPARQL Protocol and RDF Query Language. It is standardized by the RDF Data Access Working Group (DAWG) of the World Wide Web Consortium, and is considered a component of the semantic web.
• Initially released as a Candidate Recommendation in April 2006, but returned to Working Draft status in October 2006, due to two open issues. [2] In June 2007, SPARQL advanced to Candidate Recommendation once again. [3] On 12th November 2007 the status of SPARQL changed into Proposed Recommendation. [4] On 15th January 2008, SPARQL became an official W3C Recommendation. [5]
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
SPARQL =
• A Query Language
• A Result Form
• An Access Protocol
Linked Data & Social Webpage 4
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
The Query Language: query forms
• « Select » clause returns all or subset of the variables bound in a query pattern match
• « Construct » returns an RDF graph constructed by substituting variables in a set of triple templates
• « Ask » returns a boolean indicating whether a query pattern matches
• « Describe » returns an RDF graph that describe the resources found
Linked Data & Social Webpage 5
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
« Select » equivalent to « SQL Select » returns a regular table
Select …From … Identify data sources to query
Where { … } The triple/graph pattern to be matched against the triple/graphs of RDF A conjunction of triples
PREFIX to declare the schema used in the query
Linked Data & Social Webpage 6
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
FROM <http://example.org/foaf/aliceFoaf>
WHERE { ?x foaf:name ?name } Result:
Linked Data & Social Webpage 7
name
« Alice »
Computer Science Department Semantic Web in Actionpage 8
SPARQL: SPARQL Protocol and RDF Query Language
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX : <http://dbpedia.org/resource/> PREFIX dbpedia2: <http://dbpedia.org/property/> PREFIX dbpedia: <http://dbpedia.org/>
SELECT distinct ?name ?birth ?person
FROM <http://dbpedia.org/>
WHERE
{ ?person dbpedia2:birthPlace <http://dbpedia.org/resource/Berlin>.
?person dbpedia2:birth ?birth .
?person foaf:name ?name .
}
Computer Science Department Semantic Web in Actionpage 9
SPARQL: SPARQL Protocol and RDF Query Language
SPARQL results: namebirthperson« ":Dru_Berrymore/birth/birth_date_and_age :Dru_Berrymore "Dru
Berrymore"@de:Dru_Berrymore/birth/birth_date_and_age :Dru_Berrymore "Walter Benjamin"@de:Berlin :Walter_Benjamin "Walter Benjamin"@de:Germany :Walter_Benjamin
Name Birth Person
« Dru Berrymore »
Computer Science Department Semantic Web in Actionpage 10
SPARQL: SPARQL Protocol and RDF Query Language
SELECT distinct ?name ?person FROM <http://dbpedia.org/> WHERE { ?person dbpedia2:birthPlace <http://dbpedia.org/resource/Berlin> . ?person foaf:name ?name .}
SELECT distinct ?name ?birth ?death ?person FROM <http://dbpedia.org/> WHERE { ?person dbpedia2:birthPlace <http://dbpedia.org/resource/Berlin> . ?person dbpedia2:birth ?birth . ?person foaf:name ?name . ?person dbpedia2:death ?death.}
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
A constraint, expressed by the keyword “FILTER”, is a restriction on solutions over the whole group in which the filter appears
PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX ns: <http://example.org/ns#>
SELECT ?title ?price
WHERE { ?x ns:price ?price . FILTER (?price < 30.5) ?x dc:title ?title . }
Linked Data & Social Webpage 11
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
“regex” matches only plain literals with no language tag
{ ?x foaf:name ?name . ?x foaf:mbox ?mbox . FILTER regex(?name, "Smith") }
PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?title WHERE { ?x dc:title ?title FILTER regex(?title, "web", "i" ) }
Linked Data & Social Webpage 12
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
Optional parts of the graph pattern may be specified syntactically with the “OPTIONAL” keyword applied to a graph pattern
SELECT distinct ?name ?birth ?death ?person FROM <http://dbpedia.org/> WHERE { ?person dbpedia2:birthPlace <http://dbpedia.org/resource/Berlin> . ?person dbpedia2:birth ?birth . ?person foaf:name ?name . OPTIONAL {?person dbpedia2:death ?death} }
Linked Data & Social Webpage 13
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
Matching alternative
• Pattern alternatives are syntactically specified with the UNION keyword
SELECT distinct ?name ?birth ?death ?person WHERE { {?person dbpedia2:birthPlace <http://dbpedia.org/resource/Berlin> }UNION {?person dbpedia2:death ?death} ?person foaf:name ?name . ?person dbpedia2:birth ?birth . }
Linked Data & Social Webpage 14
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
Sequence & Modify
• « Order By » to sort,
• « LIMIT » result number,
• « OFFSET » rank of first result
SELECT distinct ?name ?person WHERE {?person dbpedia2:birthPlace <http://dbpedia.org/resource/Berlin>.?person foaf:name ?name.} ORDER BY ?name LIMIT 20 OFFSET 20
Linked Data & Social Webpage 15
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
« Construct »
• The CONSTRUCT query form returns a single RDF graph specified by a graph template.
- The result is an RDF graph formed by taking each query solution in the solution sequence, substituting for the variables in the graph template, and combining the triples into a single RDF graph by set union.
• Useful for aggregating data from multiple sources and merging it into a local store (from Ingenta)
Linked Data & Social Webpage 16
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
PREFIX foaf: <http://xmlns.com/foaf/0.1/>FROM <http://molene.enstb.org/mlearning09/wp-content/plugins/wp-rdfa/foaf.php
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.}
Linked Data & Social Webpage 17
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
ASK• Returns a true/false value: test whether or not a query pattern
has a solution.
• No information is returned about the possible query solutions, just whether or not a solution exists
• Is there data that looks like this? Do you have any information about that? (from Ingenta)
PREFIX foaf: <http://xmlns.com/foaf/0.1/> ASK WHERE {?person a foaf:Person; foaf:mbox <mailto:ab@telecom-bretagne>. }
Semantic Web in Actionpage 18
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
DESCRIBE• The DESCRIBE form returns a single result RDF
graph containing RDF data about resources.
• CONSTRUCT but with less control
- Tell me about this or things that look like this … but you decide what’s relevant (from Ingenta)
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
DESCRIBE ?friend
WHERE {
?person foaf:mbox “mailto:ab@telecom-bretagne”; foaf:knows ?friend.}
Semantic Web in Actionpage 19
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
Applied uses (from Ingenta)
• 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
Semantic Web in Actionpage 20
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
Applied uses (from Ingenta)
• CONSTRUCT for transformation and also simple inferencing
- CONSTRUCT could be the XSLT of RDF
- Currently limited by lack of expressions in CONSTRUCT triple templates
• ASK for validation
• ASK – DESCRIBE – CONSTRUCT Pattern:
- Probe endpoint, Grab default view of data, Refine data extraction and/or apply transformation
Semantic Web in Actionpage 21
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
SPARQL Protocol (from F. Gandon, INRIA)
• Sending queries and their results accross the web
Example with HTTP binding
• GET /sparql/?query=<encoded query> HTTP/1.1 Host: www.inria.fr User-agent: my-sparql-client/0.1
Semantic Web in Actionpage 22
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
Example with SOAP binding (from F. Gandon)
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body><query-request xmlns="http://www.w3.org/2005/09/sparql-protocol-types/#">
<query> SELECT ?x ?p ?y WHERE {?x ?p ?y} </query>
</query-request> </soapenv:Body> </soapenv:Envelope>
Semantic Web in Actionpage 23
Computer Science Department
SPARQL: SPARQL Protocol and RDF Query Language
Access to Data on the web• http://dbpedia.org/snorql/
• http://dbpedia.org/sparql
• http://demo.openlinksw.com/rdfbrowser2/
• http://dataviewer.zitgist.com/
• Etc.
Twinkle : a sparql query tool
• http://www.ldodds.com/projects/twinkle
Linked Data & Social Webpage 24
Computer Science Department Semantic Web in Actionpage 25
SPARQL: SPARQL Protocol and RDF Query Language
Resources
• http://en.wikipedia.org/wiki/SPARQL
• http://www.w3.org/TR/rdf-sparql-query/
• http://jena.sourceforge.net/ARQ/Tutorial/
• http://esw.w3.org/topic/SparqlImplementations
• http://arc.semsol.org/home
• http://virtuoso.openlinksw.com/wiki/main/Main/