Consuming RDF: Nuts and Bolts

Materials for a hands-on session at the Web of Data Practicioners Day.

Update, 9 Nov 2008: Johannes Hercher of FH Postsdam has created a mindmap of the material presented in the session, which includes live links for many of the queries and examples. Thanks, Johannes!

Thumbnail of Johannes' mind map

Links and Tools

RDF/XML Validator
Can show triples and draw a graph
N3 Validator
Seems to be down today :-(
triplr.org - fast converter between different data formats
RDF/XML, N3, N-Triples, RSS, GRDDL, JSON, ...; input must be on the Web, output will be a new URI
Babel - converter between different data formats
Has Exhibit preview; can mix several input files
Tabluator Firefox Extension
The first Linked Data browser
Marbles Linked Data Browser
Shows provenance in mixed descriptions
Exhibit faceted browser
Displays Exhibit data files (JSON); easy to embed in your own sites/pages
Sindice search engine
Finds RDF and microformat documents. Has an API.
cURL - HTTP command line tool
Useful for looking up and debugging URIs

Exploring the WOD-PD Dataset

Yves Raimon
http://api.talis.com/stores/wod-pd-sandbox/items/People/YvesRaimond
Snorql - a SPARQL explorer
http://dowhatimean.net/wod-pd/
SPARQL Endpoint
http://api.talis.com/stores/wod-pd-sandbox/services/sparql
Yves and all his attributes - Run this in Snorql
SELECT ?property ?value
WHERE {
  people:YvesRaimond ?property ?value
}
Exploring classes
SELECT DISTINCT ?class
WHERE { ?x a ?class }
Exploring properties
SELECT DISTINCT ?property
WHERE { ?s ?property ?o }
List all people
SELECT *
WHERE {
  ?person a foaf:Person
}
List only the people added yesterday
SELECT *
WHERE {
  ?person a foaf:Person
  FILTER (REGEX(STR(?person), "^http://api.talis.com/stores/wod-pd-sandbox/items/People/"))
}
Which properties are used to describe people?
SELECT DISTINCT ?property
WHERE {
  ?person a foaf:Person .
  ?person ?property ?value .
  FILTER (REGEX(STR(?person), "^http://api.talis.com/stores/wod-pd-sandbox/items/People/"))
}
ORDER BY ?property
Show people with one of the properties
SELECT DISTINCT ?person ?value
WHERE {
  ?person a foaf:Person .
  ?person foaf:nick ?value .
  FILTER (REGEX(STR(?person), "^http://api.talis.com/stores/wod-pd-sandbox/items/People/"))
}
List people with additional attributes
SELECT *
WHERE {
  ?person a foaf:Person .
  ?person foaf:name ?name .
  OPTIONAL { ?person foaf:nick ?nick . }
  OPTIONAL { ?person foaf:homepage ?homepage . }
  FILTER (REGEX(STR(?person), "^http://api.talis.com/stores/wod-pd-sandbox/items/People/"))
}
Browsing Yves
... in Tabulator and Marbles
Who knows whom?
SELECT *
WHERE {
  ?person1 foaf:knows ?person2 .
  FILTER (REGEX(STR(?person1), "^http://api.talis.com/stores/wod-pd-sandbox/items/People/"))
}
Extracting the foaf:knows statements
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT {
  ?person1 foaf:knows ?person2 .
}
WHERE {
  ?person1 foaf:knows ?person2 .
  FILTER (REGEX(STR(?person1), "^http://api.talis.com/stores/wod-pd-sandbox/items/People/"))
}
Link
Extracting descriptions of all people
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
DESCRIBE ?person
WHERE {
  ?person a foaf:Person .
  FILTER (REGEX(STR(?person), "^http://api.talis.com/stores/wod-pd-sandbox/items/People/"))
}
Link
Showing all people in Exhibit
Go to Babel, select from RDF/XML to Exhibit JSON, then the data is on some web sites, paste the URI from the link above, and click Retrieve and Preview

Mashing up some data

Country data
http://dowhatimean.net/wod-pd/countries.n3
Country data converted to RDF/XML using Triplr
http://triplr.org/rdf/dowhatimean.net/wod-pd/countries.n3
Combining this with the people data in Exhibit
Go to Babel, select from RDF/XML to Exhibit JSON, then the data is on some web sites and Add Another URL, paste the the link to the People RDF and the link to the Countries RDF, and click Retrieve and Preview

RDF data formats

Formatstoresgoodbad
RDF/XMLRDF graph"the" RDF standard, ubiquituous supportugly, hard to read+write
N3, TurtleRDF graphcompact, readableno W3C standard, not supported everywhere
N-TriplesRDF graphvery simple, good for dumpsvery verbose
HTML+RDFaWeb page, embedded RDF graphW3C standard, builds on HTMLstill new, not many tools, tagsoup issues
SPARQL results in XMLSPARQL SELECT result
SPARQL results in JSONSPARQL SELECT result

MIME types

RDF/XML
application/rdf+xml
N3
text/rdf+n3; charset=utf-8
N-Triples
text/plain
SPARQL results in XML
application/sparql-results+xml
SPARQL results in JSON
application/sparql-results+json

Using cURL to look up URIs

Get content (or status message)
curl http://api.talis.com/stores/wod-pd-sandbox/items/People/YvesRaimond
Get HTTP response headers (-I)
curl -I http://api.talis.com/stores/wod-pd-sandbox/items/People/YvesRaimond
Follow redirects (-L)
curl -L http://api.talis.com/stores/wod-pd-sandbox/items/People/YvesRaimond
Ask for specific MIME type
curl -H "Accept: text/plain" http://api.talis.com/stores/wod-pd-sandbox/items/People/YvesRaimond
Status codes
200 OK
3XX Redirect
4XX Client error
5XX Server error