background preloader

Querying with SPARQL

Facebook Twitter

SPARQL. SPARQL (pronounced "sparkle", a recursive acronym for SPARQL Protocol and RDF Query Language) is an RDF query language, that is, a semantic query language for databases, able to retrieve and manipulate data stored in Resource Description Framework format.[2][3] It was made a standard by the RDF Data Access Working Group (DAWG) of the World Wide Web Consortium, and is recognized as one of the key technologies of the semantic web.

SPARQL

On 15 January 2008, SPARQL 1.0 became an official W3C Recommendation,[4][5] and SPARQL 1.1 in March, 2013.[6] SPARQL allows for a query to consist of triple patterns, conjunctions, disjunctions, and optional patterns.[7] Implementations for multiple programming languages exist.[8] "SPARQL will make a huge difference" making the web machine-readable according to Sir Tim Berners-Lee in a May 2006 interview.[9] Advantages[edit] The example below demonstrates a simple query that leverages the ontology definition "foaf", often called the "friend-of-a-friend" ontology.

Querying Linked Data with SPARQL. SPARQL/RDQL/SPARUL Injection. Querying DBpedia. DBpedia, as its home page tells us, "is a community effort to extract structured information from Wikipedia and to make this information available on the Web.

Querying DBpedia

" That's "available" in the sense of available as data to programs that read and process it, because the data was already available to eyeballs on Wikipedia. This availability is a big deal to the semantic web community because it's a huge amount of valuable (and often, fun) information that the public can now query with SPARQL, the W3C standard query language that is one of the pillars of the semantic web. Although I'd dabbled in SPARQL and seen several sample SPARQL queries against DBpedia in action, I had a little trouble working out how to create my own SPARQL queries against DBpedia data. I finally managed to do it, so I thought I'd describe here how I successfully implemented my first use case. Once I knew the following three things, I could create the SPARQL query: Of course this is just scratching the surface. Learning more about SPARQL. Since I first wrote on sending DBpedia SPARQL queries about Bart's blackboard messages at the start of Simpsons episodes, I've learned a lot more about SPARQL (reading the spec helped) and I wanted to walk through some of the things I've learned by expanding on and refining my original query.

Learning more about SPARQL

I had finished that entry by wondering how to list Bart's blackboard entries for all episodes instead of for just one season. Vaclav Synacek showed me one way, and I recently realized that there's a much simpler way—maybe too simple (all queries shown assume the namespace declarations shown on the SNORQL interface form for sending SPARQL queries to DBpedia): Some answers are URLs, and some are actual strings of what Bart wrote.

How can I tell DBpedia to only give me the latter? What's a portalProperty, and what other values might show up there? Federated SPARQL queries. Much of the promise of RDF and Linked Data is the ease of pulling data from multiple sources and combining it.

Federated SPARQL queries

I recently discovered the SERVICE extension that Jena adds to SPARQL, letting you send subqueries off to multiple SPARQL endpoints and then combine the results. Because a given SPARQL endpoint may be an interface to a triplestore or a relational data store or something else, the ability to query several endpoints with one query is very nice. The ability to query several endpoints with one query is very nice. The Jena project's ARQ - Basic Federated SPARQL Query describes the use of this keyword. Before I start quoting from that page, I wanted to jump right in with an example that worked for me to pull birthday and spouse information about Arnold Schwarzenegger from DBpedia and a list of his movies and their release dates from Linked Movie Database in one query: You can run this query yourself at the sparql.org RDF Query Demo page.