W3C logo
slanted W3C logo
 Cover page images (keys)

BioRDF SPARQL Overview

Eric Prud'hommeaux, RDF Data Access Working Group team contact



RDF Data Access Working Group

Pictorial: Graph Pattern

Query laguage for RDF matching triple patterns:

SPARQL query

against RDF graphs:

RDF graph

Semi-Pictorial Pattern

SPARQL query
?who foaf:mbox  .
?who foaf:know ?whom .
?whom foaf:mbox ?addrm .

Textual Example


@prefix foaf:  <http://xmlns.com/foaf/0.1/> .

_:a  foaf:name   "Johnny Lee Outlaw" .
_:a  foaf:mbox   <mailto:jlow@example.com> .
_:b  foaf:name   "Peter Goodguy" .
_:b  foaf:mbox   <mailto:peter@example.org> .


PREFIX foaf:   <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
  { ?x foaf:name ?name .
    ?x foaf:mbox ?mbox }

Query Result:

name mbox
"Johnny Lee Outlaw" <mailto:jlow@example.com>
"Peter Goodguy" <mailto:peter@example.org>

SPARQL Example

Give me the name and homepage (if known) of joe@host.example :

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?homepage
 WHERE { ?someone foaf:mbox <mailto:joe@host.example> .
         ?someone foaf:name ?name .
         OPTIONAL { ?someone foaf:homepage ?homepage }

Find solutions like:

name homepage
"Joe Svenopolous" <http://host.example/People/Joe/>

Result Formats

SPARQL has three defined result formats:

The Query Controls the Result Format

The Query Controls the Result Format

The Query Controls the Result Format

RDF Graph Results

RDF Graph Results Example

A query like:

PREFIX w5: <http://www.w3.org/2004/10/18-RDF-WWW2005/>
 WHERE {?author  w5:Author_name      "Sean M. McNee" .
        ?author  w5:Author_paper     ?paper .
        ?paper   w5:Paper_name       ?name . 
        ?paper   w5:Paper_session    ?session .
        ?session w5:Session_room     ?room .
        ?room    w5:Room_description ?roomDesc .
        ?program w5:Program_session  ?session .
        ?program w5:Program_start1    ?start .
        ?program w5:Program_start1    ?end }

can be written as a URL.

RDF Graph Results Example

Requesting variables

PREFIX w5: <http://www.w3.org/2004/10/18-RDF-WWW2005/>
SELECT ?name ?room ?roomDesc ?start ?end

would get an XML document of solutions.

   <head><variable name="name" />
         <variable name="room" />
         <variable name="roomDesc" />
         <variable name="start" />
         <variable name="end" /></head>
         <binding name="name"><literal>Improving Recommendation Lists Through Topic Diver</literal></binding>
         <binding name="room"><uri href="http://www.w3.org/2004/10/18-RDF-WWW2005/Room__id_6"/></binding>
         <binding name="roomDesc"><literal>Room 301</literal></binding>
         <binding name="start"><literal>2005-05-11 10:50:00</literal></binding>
         <binding name="end"><literal>2005-05-11 10:50:00</literal></binding>