SPARQL

From Wikipedia, the free encyclopedia
  (Redirected from Sparql)
Jump to: navigation, search

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 considered as one of the key technologies of semantic web. On 15 January 2008, SPARQL 1.0 became an official W3C Recommendation.[3]

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

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

There exist tools that allow one to connect and semi-automatically construct a SPARQL query for a SPARQL endpoint, for example ViziQuer.[7]

Contents

[edit] Benefits

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.

[edit] Query forms

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.

[edit] 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#”.

[edit] References

  1. ^ Jim Rapoza (2 May 2006). "SPARQL Will Make the Web Shine". eWeek. http://www.eweek.com/article2/0,1759,1965980,00.asp. Retrieved 2007-01-17. 
  2. ^ Segaran, Toby; Evans, Colin; Taylor, Jamie (2009) (in english). 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. 2008-01-15. http://www.w3.org/blog/SW/2008/01/15/sparql_is_a_recommendation. Retrieved 2009-10-01. 
  4. ^ "XML and Web Services In The News". xml.org. 6 October 2006. http://www.xml.org/xml/news/archives/archive.10062006.shtml#5. Retrieved 2007-01-17. 
  5. ^ "SparqlImplementations - ESW Wiki". Esw.w3.org. http://esw.w3.org/topic/SparqlImplementations. Retrieved 2009-10-01. 
  6. ^ Reuters (22 May 2006). "Berners-Lee looks for Web's big leap". zdnet.co.uk. Archived from the original on 2007-09-30. http://web.archive.org/web/20070930221904/http://news.zdnet.co.uk/internet/0,1000000097,39270671,00.htm. Retrieved 2007-01-17. 
  7. ^ "ViziQuer a tool to construct SPARQL queries automaticly". lumii.lv. http://viziquer.lumii.lv/. Retrieved 2011-02-25. 

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages