Redland Rasqal RDF Query Demonstration (original) (raw)

This is a demonstration of usingRasqalto 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 theRedland Perllanguage 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:

  1. A FOAF query that finds all people with a name and an IRC nick
    Data: http://www.dajobe.org/foaf.rdf
    Query:
    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
  2. An RSS 1.0 query that finds all the items in the feed
    Data: http://www.w3.org/2000/08/w3c-synd/home.rss
    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 3. Print the description of a project and maintainer(s) using DOAP
Data: http://librdf.org/raptor/raptor.rdf
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 descriptiondescription descriptionmaintainerName
WHERE {
$project rdf:type doap:Project .
projectdoap:descriptionproject doap:description projectdoap:descriptiondescription .
projectdoap:maintainerproject doap:maintainer projectdoap:maintainerm .
mfoaf:namem foaf:name mfoaf:namemaintainerName
}
Run this query 4. Print the names and optional nicks of people in my FOAF file where available
Data: http://www.dajobe.org/foaf.rdf
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 5. What are the Noble Gases?
Data: http://www.daml.org/2003/01/periodictable/PeriodicTable.owl
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 6. What are the last 10 updated items in an atom feed?
Data: http://www.tbray.org/ongoing/ongoing.atom
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 10
Run this query 7. Find the most recent 10 news items about Redland from multiple RSS 1.0 feeds
Data: http://librdf.org/NEWS.rdf http://librdf.org/raptor/NEWS.rdf http://librdf.org/rasqal/NEWS.rdf http://librdf.org/bindings/NEWS.rdf
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 10
Run this query

The source code of this demonstration is available in the Redland bindings distribution as demos/query.pl or from theRedland website


Made withRedland 1.0.17,Rasqal 0.9.32 andRaptor 2.0.15

Dave Beckett