Redland Rasqal RDF Query Demonstrationby Dave Beckett |
|
This is a demonstration of using Rasqal to perform queries in either of the SPARQL languages over RDF data. The data is loaded into a Redland model and then queried and results accessed via the Redland Perl language binding.
The query must be in SPARQL and needs a URI of some RDF content to query and run it. The example query is for FOAF and finds the names of all the people in the graph. There are other example queries further down the page.
Some RDF content you can use could be my FOAF file at:
http://www.dajobe.org/foaf.rdf
or the W3C's RSS 1.0 file at:
http://www.w3.org/2000/08/w3c-synd/home.rss
Documentation on SPARQL is available in the SPARQL Query Language for RDF, W3C Working Draft, 12 October 2004
NOTE Not all of SPARQL is implemented. See the status of SPARQL support in Rasqal. Current unimplemented features include UNION
and full XSD datatype comparisons (dates, decimal) and promotions, GRAPH
and deeply grouped graph patterns {
...}
.
Some other SPARQL example queries:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?nick, ?name WHERE { ?x rdf:type foaf:Person . ?x foaf:nick ?nick . ?x foaf:name ?name }Run this query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX rss: <http://purl.org/rss/1.0/> SELECT ?title ?description WHERE { ?item rdf:type rss:item . ?item rss:title ?title . ?item rss:description ?description }Run this query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX doap: <http://usefulinc.com/ns/doap#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT $description $maintainerName WHERE { $project rdf:type doap:Project . $project doap:description $description . $project doap:maintainer $m . $m foaf:name $maintainerName }Run this query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?nick WHERE { ?x rdf:type foaf:Person . ?x foaf:name ?name . OPTIONAL { ?x foaf:nick ?nick } }Run this query
PREFIX table: <http://www.daml.org/2003/01/periodictable/PeriodicTable#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?name ?symbol ?weight ?number WHERE { ?element table:group ?group . ?group table:name "Noble gas"^^xsd:string . ?element table:name ?name . ?element table:symbol ?symbol . ?element table:atomicWeight ?weight . ?element table:atomicNumber ?number } ORDER BY ASC(?name)Run this query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX rss: <http://purl.org/rss/1.0/> PREFIX atom: <http://www.w3.org/2005/Atom> SELECT ?item ?title ?date WHERE { ?item rdf:type rss:item . ?item rss:title ?title . ?item atom:updated ?date } ORDER BY DESC(?date) LIMIT 10Run this query
PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX rss: <http://purl.org/rss/1.0/> SELECT ?item ?title ?date WHERE { ?item a rss:item ; rss:title ?title ; dc:date ?date } ORDER BY DESC(?date) LIMIT 10Run this query
The source code of this demonstration is available in the Redland bindings distribution as demos/query.pl or from the Redland website