Jump to content

SPARQL

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Kjetil (talk | contribs) at 16:36, 12 July 2013 (Mention read-write). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

SPARQL
ParadigmQuery language
DeveloperW3C
First appeared2008
Stable release
1.1 / 2013-03-21
Website[1]
Major implementations
C#, Java, C

SPARQL (pronounced "sparkle", a recursive acronym for SPARQL Protocol and RDF Query Language) is an RDF query language, that is, a query language for databases, able to retrieve and manipulate data stored in Resource Description Framework format.[1][2] It was made a standard by the RDF Data Access Working Group (DAWG) of the World Wide Web Consortium, and is considered as one of the key technologies of the semantic web. On 15 January 2008, SPARQL 1.0 became an official W3C Recommendation,[3][4] and SPARQL 1.1 in March, 2013.[5]

SPARQL allows for a query to consist of triple patterns, conjunctions, disjunctions, and optional patterns.[6]

Implementations for multiple programming languages exist.[7] "SPARQL will make a huge difference" according to Sir Tim Berners-Lee in a May 2006 interview.[8]

There exist tools that allow one to connect and semi-automatically construct a SPARQL query for a SPARQL endpoint, for example ViziQuer.[9] In addition, there exist tools that translate SPARQL queries to other query languages, for example to SQL[10] and to XQuery.[11]

Advantages

SPARQL allows users to write unambiguous queries. For example, the following query returns names and emails of every person in the dataset:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?email
WHERE {
  ?person a foaf:Person.
  ?person foaf:name ?name.
  ?person foaf:mbox ?email.
}

This query can be distributed to multiple SPARQL endpoints (services that accept SPARQL queries and return results), computed, and results gathered, a procedure known as federated query.

Query forms

In the case of queries that read data from the database, the SPARQL language specifies four different query variations for different purposes.

SELECT query
Used to extract raw values from a SPARQL endpoint, the results are returned in a table format.
CONSTRUCT query
Used to extract information from the SPARQL endpoint and transform the results into valid RDF.
ASK query
Used to provide a simple True/False result for a query on a SPARQL endpoint.
DESCRIBE query
Used to extract an RDF graph from the SPARQL endpoint, the contents of which is left to the endpoint to decide based on what the maintainer deems as useful information.

Each of these query forms takes a WHERE block to restrict the query although in the case of the DESCRIBE query the WHERE is optional.

SPARQL 1.1 specifies a language for updating the database with several new query forms.

Example

Another SPARQL query example that models the question "What are all the country capitals in Africa?":

PREFIX abc: <http://example.com/exampleOntology#>
SELECT ?capital ?country
WHERE {
  ?x abc:cityname ?capital ;
     abc:isCapitalOf ?y .
  ?y abc:countryname ?country ;
     abc:isInContinent abc:Africa .
}

Variables are indicated by a "?" or "$" prefix. Bindings for ?capital and the ?country will be returned.

The SPARQL query processor will search for sets of triples that match these four triple patterns, binding the variables in the query to the corresponding parts of each triple. Important to note here is the "property orientation" (class matches can be conducted solely through class-attributes or properties - see Duck typing)

To make queries concise, SPARQL allows the definition of prefixes and base URIs in a fashion similar to Turtle. In this query, the prefix "abc" stands for “http://example.com/exampleOntology#”.

Extensions

SPARUL, or SPARQL/Update, is an extension to the SPARQL query language that provides the ability to add, update, and delete RDF data held within a triple store.

GeoSPARQL is intended to provide a standardized interchange basis for geospatially linked data based on well-understood OGC standards (GML, WKT, Simple Features, etc.) which can support both quantitative and qualitative spatial reasoning and querying through SPARQL.[12]

SPARQL implementations

This list shows triplestore, APIs, and other storages that have implemented the SPARQL query language.

References

  1. ^ Jim Rapoza (2 May 2006). "SPARQL Will Make the Web Shine". eWeek. Retrieved 17 January 2007.
  2. ^ Segaran, Toby; Evans, Colin; Taylor, Jamie (2009). Programming the Semantic Web. O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. p. 84. ISBN 978-0-596-15381-6.
  3. ^ "W3C Semantic Web Activity News - SPARQL is a Recommendation". W3.org. 15 January 2008. Retrieved 1 October 2009.
  4. ^ "XML and Semantic Web W3C Standards Timeline" (PDF). 4 February 2012.
  5. ^ "Eleven SPARQL 1.1 Specifications are W3C Recommendations". w3.org. 21 March 2013. Retrieved 25 April 2013.
  6. ^ "XML and Web Services In The News". xml.org. 6 October 2006. Retrieved 17 January 2007.
  7. ^ "SparqlImplementations - ESW Wiki". Esw.w3.org. Retrieved 1 October 2009.
  8. ^ Reuters (22 May 2006). "Berners-Lee looks for Web's big leap". zdnet.co.uk. Archived from the original on 30 September 2007. Retrieved 17 January 2007. {{cite news}}: |author= has generic name (help)
  9. ^ "ViziQuer a tool to construct SPARQL queries automaticly". lumii.lv. Retrieved 25 February 2011.
  10. ^ "D2R Server". Retrieved 2012- 02-4. {{cite web}}: Check date values in: |accessdate= (help)
  11. ^ "SPARQL2XQuery Framework". Retrieved 2012- 02-4. {{cite web}}: Check date values in: |accessdate= (help)
  12. ^ Battle, Robert; Kolas, Dave (2012). "Enabling the geospatial Semantic Web with Parliament and GeoSPARQL" (PDF). Semantic Web. 3 (4). IOS Press: 355–370. doi:10.3233/SW-2012-0065. Retrieved 21 November 2012.
  13. ^ Github - LuposDate
  14. ^ LuposDate Demo-Applet
  15. ^ "Profium Sense". 18 June 2012.
  16. ^ "NoSQL Graph Store". 27 April 2012.