W3C logo
slanted W3C logo
 Cover page images (keys)

BioRDF SPARQL Overview

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

Outline

DAWG?

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

Data:

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

_:a  foaf:name   "Johnny Lee Outlaw" .
_:a  foaf:mbox   <mailto:[email protected]> .
_:b  foaf:name   "Peter Goodguy" .
_:b  foaf:mbox   <mailto:[email protected]> .

Query:

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

Query Result:

name mbox
"Johnny Lee Outlaw" <mailto:[email protected]>
"Peter Goodguy" <mailto:[email protected]>

SPARQL Example

Give me the name and homepage (if known) of [email protected] :

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?homepage
 WHERE { ?someone foaf:mbox <mailto:[email protected]> .
         ?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/>
CONSTRUCT *
 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.

<sparql
 xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result#">
   <head><variable name="name" />
         <variable name="room" />
         <variable name="roomDesc" />
         <variable name="start" />
         <variable name="end" /></head>
   <results>
      <result>
         <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>
      </result>
   </results>
</sparql>

Protocol

Tools