ConceptioArchiveW3C TR
W3C TRopen access

sparql11 overview

W3C · w3c_tr
W3C TR · Standards · License: Open Access
Open Source ↗
w3c, standard

SPARQL 1.1 Overview @import url("local.css");

code { font-family: monospace; }

div.constraint, div.issue, div.note, div.notice { margin-left: 2em; }

ol.enumar { list-style-type: decimal; } ol.enumla { list-style-type: lower-alpha; } ol.enumlr { list-style-type: lower-roman; } ol.enumua { list-style-type: upper-alpha; } ol.enumur { list-style-type: upper-roman; }

div.exampleInner pre { margin-left: 1em; margin-top: 0em; margin-bottom: 0em} div.exampleOuter {border: 4px double gray; margin: 0em; padding: 0em} div.exampleInner { background-color: #d5dee3; border-top-width: 4px; border-top-style: double; border-top-color: #d3d3d3; border-bottom-width: 4px; border-bottom-style: double; border-bottom-color: #d3d3d3; padding: 4px; margin: 0em } div.exampleWrapper { margin: 4px } div.exampleHeader { font-weight: bold; margin: 4px}

em.rfc2119 { text-transform: lowercase; font-variant: small-caps; font-style: normal; } This version: http://www.w3.org/TR/2013/REC-sparql11-overview-20130321/ Latest version: http://www.w3.org/TR/sparql11-overview/ Previous version: http://www.w3.org/TR/2012/PR-sparql11-overview-20121108/ Editor: The W3C SPARQL Working Group, see Acknowledgements <[email protected]> Please refer to the errata See also translations Copyright W3C ® MIT ERCIM Keio Beihang liability trademark document use This document is an overview of SPARQL 1.1. It provides an introduction to a set of W3C specifications that facilitate querying and manipulating RDF graph content on the Web or in an RDF store. May Be Superseded This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index Set of Documents This document is one of eleven SPARQL 1.1 Recommendations produced by the SPARQL Working Group SPARQL 1.1 Overview SPARQL 1.1 Query Language SPARQL 1.1 Update SPARQL1.1 Service Description SPARQL 1.1 Federated Query SPARQL 1.1 Query Results JSON Format SPARQL 1.1 Query Results CSV and TSV Formats SPARQL Query Results XML Format (Second Edition) SPARQL 1.1 Entailment Regimes SPARQL 1.1 Protocol SPARQL 1.1 Graph Store HTTP Protocol No Substantive Changes There have been no substantive changes to this document since the previous version change log color-coded diff Please Send Comments Please send any comments to [email protected] public archive SPARQL Working Group errata [email protected] public archive Endorsed By W3C This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web. Patents This document was produced by a group operating under the 5 February 2004 W3C Patent Policy public list of any patent disclosures Essential Claim(s) section 6 of the W3C Patent Policy 1 Introduction Example SPARQL 1.1 Query Language Different query results formats supported by SPARQL 1.1 (XML, JSON, CSV, TSV) SPARQL 1.1 Federated Query SPARQL 1.1 Entailment Regimes SPARQL 1.1 Update Language SPARQL 1.1 Protocol for RDF SPARQL 1.1 Service Description SPARQL 1.1 Graph Store HTTP Protocol Acknowledgements References SPARQL 1.1 is a set of specifications that provide languages and protocols to query and manipulate RDF graph content on the Web or in an RDF store. The standard comprises the following specifications: SPARQL 1.1 Query Language SPARQL 1.1 Query Results JSON Format SPARQL 1.1 Query Results CSV and TSV Formats SPARQL-XML-Result SPARQL 1.1 Federated Query SPARQL 1.1 Entailment Regimes SPARQL 1.1 Update Language SPARQL 1.1 Protocol for RDF SPARQL 1.1 Service Description SPARQL 1.1 Graph Store HTTP Protocol SPARQL 1.1 Test Cases In the following, we will illustrate the use of SPARQL's languages, protocols, and related specifications with a small example. Some RDF graph published on the Web at the URL ' http://example.org/alice' Turtle Graph: http://example.org/alice @prefix foaf: < http://xmlns.com/foaf/0.1/ http://www.w3.org/2000/01/rdf-schema# http://example.org/alice#me http://example.org/alice#me http://example.org/alice#me mailto:[email protected] http://example.org/alice#me http://example.org/bob#me http://example.org/bob#me http://example.org/alice#me http://example.org/bob#me http://example.org/alice#me http://example.org/charlie#me http://example.org/charlie#me http://example.org/alice#me http://example.org/charlie#me http://example.org/alice#me http://example.org/snoopy http://example.org/snoopy With SPARQL 1.1 one can query such graphs, load them into RDF stores and manipulate them in various ways. Assuming the graph data from above is loaded into a SPARQL service (i.e., an HTTP service endpoint that can process SPARQL queries), the SPARQL 1.1 Query Language PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name (COUNT(?friend) AS ?count) WHERE {  ?person foaf:name ?name .  ?person foaf:knows ?friend . } GROUP BY ?person ?name Just like in the earlier SPARQL1.0 specification [ SPARQL-Query Compared to SPARQL1.0, SPARQL 1.1 adds a number of new features to the query language, including subqueries, value assignment, path expressions, or aggregates - such as COUNT, as used in the above example query - etc. The SPARQL 1.1 Query Language Results of SELECT queries in SPARQL comprise bags of mappings from variables to RDF terms, often conveniently represented in tabular form. For instance, the query from Section 2 has the following results: ?name ?count "Alice" 3 "Bob" 1 "Charlie" 1 XML JSON CSV TSV the SPARQL Query Results XML Format please, particularly note that the SPARQL 1.1 WG has made some minor Errata the SPARQL 1.1 Query Results JSON Format the SPARQL 1.1 Query Results CSV and TSV Formats These documents specify details of how particular solutions and RDF terms occurring in solutions are encoded in the respective target formats. The results of our example query, in these three formats look as follows. XML: <?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="name"/> <variable name="count"/> </head> <results> <result> <binding name="name"> <literal>Alice</literal> </binding> <binding name="count"> <literal datatype="http://www.w3.org/2001/XMLSchema#integer">3</literal> </binding> </result> <result> <binding name="name"> <literal>Bob</literal> </binding> <binding name="count"> <literal datatype="http://www.w3.org/2001/XMLSchema#integer">1</literal> </binding> </result> <result> <binding name="name"> <literal>Charlie</literal> </binding> <binding name="count"> <literal datatype="http://www.w3.org/2001/XMLSchema#integer">1</literal> </binding> </result> </results> </sparql> JSON: { "head": { "vars": [ "name" , "count" ] } , "results": { "bindings": [ { "name": { "type": "literal" , "value": "Alice" } , "count": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "3" } } , { "name": { "type": "literal" , "value": "Bob" } , "count": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "1" } } , { "name": { "type": "literal" , "value": "Charlie" } , "count": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "1" } } ] } } CSV: name,count Alice,3 Bob,1 Charlie,1 TSV: ?name<TAB>?count "Alice"<TAB>3 "Bob"<TAB>1 "Charlie"<TAB>1 ( Note: <TAB> here for illustration only. The SPARQL 1.1 Federated Query SPARQL 1.1 Query Language For instance, in our example, one may want to know whether there is anyone among Alice's friends with the same name as the resource identified by the IRI < http://dbpedia.org/resource/Snoopy http://dbpedia.org/sparql http://dbpedia.org/resource/Snoopy SERVICE PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE { <http://example.org/alice#me> foaf:knows [ foaf:name ?name ] . SERVICE <http://dbpedia.org/sparql> { <http://dbpedia.org/resource/Snoopy> foaf:name ?name } } with the following result: ?name "Snoopy"@en Here, the first part of the pattern in the WHERE SERVICE SPARQL could be used together with ontological information in the form of, for example, RDF Schema or OWL axioms. For instance, let us assume that - apart from the data about Alice - some ontological information in the form of RDF Schema [ RDF-Schema OWL2-Overview The FOAF @prefix foaf: < http://xmlns.com/foaf/0.1/ http://www.w3.org/2000/01/rdf-schema# The following query asks for labels of persons: SELECT ?label WHERE { ?person rdfs:label ?label } A SPARQL engine that does not consider any special entailment regimes (on top of standard simple entailment ?label "Alice" "Bob" "Charlie" "Snoopy"@en since foaf:name rdfs:label The SPARQL 1.1 Entailment Regimes RDF-MT OWL2-Overview RIF-Overview The SPARQL 1.1 Update For instance, the following request inserts a new friend of Alice named Dorothy into the default graph of our example SPARQL service and thereafter deletes all names of Alice's friends with an English language tag. PREFIX foaf: <http://xmlns.com/foaf/0.1/> .

INSERT DATA { <http://www.example.org/alice#me> foaf:knows [ foaf:name "Dorothy" ]. } ; DELETE { ?person foaf:name ?mbox } WHERE { <http://www.example.org/alice#me> foaf:knows ?person . ?person foaf:name ?name FILTER ( lang(?name) = "EN" ) .} As the second operation shows, insertions and deletions can be dependent on the results of queries to the Graph Store; the respective syntax used in the WHERE part is derived from the SPARQL 1.1 Query Language The SPARQL 1.1 Protocol For instance, the query from Section 3 above issued against a SPARQL query service hosted at http://www.example.org/sparql/ GET /sparql/?query=PREFIX%20foaf%3A%20%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0ASELECT%20%3Fname%20%28COUNT%28%3Ffriend%29%20AS%20%3Fcount%29%0AWHERE%20%7B%20%0A%20%20%20%20%3Fperson%20foaf%3Aname%20%3Fname%20.%20%0A%20%20%20%20%3Fperson%20foaf%3Aknows%20%3Ffriend%20.%20%0A%7D%20GROUP%20BY%20%3Fperson%20%3Fname HTTP/1.1 Host: www.example.org User-agent: my-sparql-client/0.1 Details about response encoding and different operations for query and update requests, as well as supported HTTP methods, are described in the Protocol specification. The SPARQL 1.1 Service Description SPARQL 1.1 Protocol for RDF According to this specification, a service endpoint, when accessed via an HTTP GET operation without further (query or update request) parameters should return an RDF description of the service provided. For instance, the following HTTP request: GET /sparql/ HTTP/1.1 Host: www.example.org issued against the SPARQL endpoint hosted at http://www.example.org/sparql/ For many applications and services that deal with RDF data, the full SPARQL 1.1 Update SPARQL 1.1 Graph Store HTTP Protocol For instance, the first part of the update request in Section 4 above is a simple insertion of triples into an RDF graph. On a service supporting this protocol, such insertion can - instead of via a SPARQL 1.1 update request - directly be performed via an HTTP POST operation taking the RDF triples to be inserted as payload: POST /rdf-graphs/service?graph=http%3A%2F%2Fwww.example.org%2Falice HTTP/1.1 Host: example.org Content-Type: text/turtle @prefix foaf: <http://xmlns.com/foaf/0.1/> . <http://www.example.org/alice#me> foaf:knows [ foaf:name "Dorothy" ] . SPARQL 1.1 Graph Store HTTP Protocol SPARQL 1.1 Query SPARQL 1.1 Update The members of the W3C SPARQL Working group who actively contributed to the SPARQL 1.1 specifications are: Carlos Buil Aranda, Universidad Politécnica de Madrid Olivier Corby, Institut National de Recherche en Informatique et en Automatique (INRIA) Souripriya Das, Oracle Corporation Lee Feigenbaum, Cambridge Semantics Paula Gearon, Revelytix Inc Birte Glimm, Universität Ulm Steve Harris, Garlik Ltd Sandro Hawke, W3C Ivan Herman, W3C Nicholas Humfrey, BBC Nico Michaelis, Dreamlab Technologies AG Chimezie Ogbuji, Invited Expert Matthew Perry, Oracle Corporation Alexandre Passant, DERI, National University of Ireland, Galway Axel Polleres, Siemens AG Eric Prud'hommeaux, W3C Andy Seaborne, The Apache Software Foundation Gregory Todd Williams, Rensselaer Polytechnic Institute SPARQL Query Results XML Format (Second Edition) Latest version RDF Vocabulary Description Language 1.0: RDF Schema RDF Semantics OWL 2 Web Ontology Language Document Overview RIF Overview Turtle - Terse RDF Triple Language SPARQL Query Language for RDF Change Log Changes since Proposed Recommendation Removed reference to obsolete document Changes since Last Call Remove use of term "REST"; updated references.

Related documents

Record · ID 19473 · SHA-256 f47e4fbfe9c72f3f
Conceptio Open Knowledge Archive — every document is proof-bundled with source, license, and retrieval metadata.