QUERYING Linked Data
1. Three main ways of accessing
remote Linked Data
1. Through HTTP request on the resource URI
2. Through SPARQL queries
3. Get a copy of a dataset
1. Through HTTP request on the
resource URI
• HTTP GET on resource, parse, follow links
– Simple HTTP requests and RDF parsing
– Requires dereferencable URIs
– One request per resource: may require many
requests
• Local caching can be done
• Crawling GET /resource/Amsterdam HTTP/1.1
Host: dbpedia.org
Accept: text/html;q=0.5, application/rdf+xml
I’m ok with HTML… …but I really prefer RDF
• With CURL
– curl -L -H "Accept: application/rdf+xml"
http://dbpedia.org/resource/Madrid
– curl -L -H "Accept: text/turtle"
http://dbpedia.org/resource/Madrid
– curl -L -H "Accept: text/turtle"
http://purl.org/collections/nl/dss/das/voyage-5580_1
• With Sindice inspector (or other tool)
• http://inspector.sindice.com/inspect?url=
• http://inspector.sindice.com/inspect?url=http://dbpedia.or
g/resource/Madrid
2. Through SPARQL queries
• Full-blown query language
• Needs SPARQL endpoint
$query =
"SELECT distinct ?title ?description WHERE {
?x <http://data.open.ac.uk/podcast/ontology/relatesToCourse>
<http://data.open.ac.uk/course/t209>.
?x <http://purl.org/dc/terms/title> ?title.
?x <http://www.w3.org/TR/2010/WD-mediaont-10-20100608/description> ?description }
LIMIT 10
";
$requestURL = 'http://data.open.ac.uk/query?query='.urlencode($query);
$response = request($requestURL);
SPARQL in PHP example
http://www.greenhughes.com/content/approach-consuming-linked-data-php
3. Get a local copy of a dataset
• through SPARQL CONSTRUCT,
• crawling or
• Direct file download
• Save in triple store
– or convert to something else
RDF Libraries
Redland: http://www.librdf.org/ Perl, Python,
PHP, Ruby, C#, Objective-C
Jena: http://jena.sourceforge.net/ Java
RDFLib: http://www.rdflib.net/ Python
ARC2: http://arc2.semsol.net/ PHP
ActiveRDF: http://www.activerdf.org/ Ruby
Handson with SPARQL
SPARQL
A Query-language for the Web of
Data
SPARQL – Querying the Web of Data
• query language for RDF graphs (i.e., linked
data)
• extract specific information out of a dataset
(or several datasets)
• "The SQL for the Web of Data"
SPARQL Endpoint
Reasoning?
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX dce: <http://purl.org/dc/elements/1.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?album ?title ?release_date
WHERE {
?album a mo:Record ;
dce:date ?release_date ;
dce:title ?title .
FILTER (year(?release_date) = 2007 &&
month(?release_date) = 7)
}
ORDER BY ?release_date
SPARQL in a Nutshell
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX dce: <http://purl.org/dc/elements/1.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?album ?title ?release_date
WHERE {
?album a mo:Record ;
dce:date ?release_date ;
dce:title ?title .
FILTER (year(?release_date) = 2007 &&
month(?release_date) = 7)
}
ORDER BY ?release_date
graph pattern
Lets try it ourselves
http://tinyurl.com/getafesparql
Madrid SPARQL handson

Madrid SPARQL handson

  • 1.
  • 2.
    1. Three mainways of accessing remote Linked Data 1. Through HTTP request on the resource URI 2. Through SPARQL queries 3. Get a copy of a dataset
  • 3.
    1. Through HTTPrequest on the resource URI • HTTP GET on resource, parse, follow links – Simple HTTP requests and RDF parsing – Requires dereferencable URIs – One request per resource: may require many requests • Local caching can be done • Crawling GET /resource/Amsterdam HTTP/1.1 Host: dbpedia.org Accept: text/html;q=0.5, application/rdf+xml I’m ok with HTML… …but I really prefer RDF
  • 4.
    • With CURL –curl -L -H "Accept: application/rdf+xml" http://dbpedia.org/resource/Madrid – curl -L -H "Accept: text/turtle" http://dbpedia.org/resource/Madrid – curl -L -H "Accept: text/turtle" http://purl.org/collections/nl/dss/das/voyage-5580_1 • With Sindice inspector (or other tool) • http://inspector.sindice.com/inspect?url= • http://inspector.sindice.com/inspect?url=http://dbpedia.or g/resource/Madrid
  • 5.
    2. Through SPARQLqueries • Full-blown query language • Needs SPARQL endpoint $query = "SELECT distinct ?title ?description WHERE { ?x <http://data.open.ac.uk/podcast/ontology/relatesToCourse> <http://data.open.ac.uk/course/t209>. ?x <http://purl.org/dc/terms/title> ?title. ?x <http://www.w3.org/TR/2010/WD-mediaont-10-20100608/description> ?description } LIMIT 10 "; $requestURL = 'http://data.open.ac.uk/query?query='.urlencode($query); $response = request($requestURL); SPARQL in PHP example http://www.greenhughes.com/content/approach-consuming-linked-data-php
  • 6.
    3. Get alocal copy of a dataset • through SPARQL CONSTRUCT, • crawling or • Direct file download • Save in triple store – or convert to something else
  • 7.
    RDF Libraries Redland: http://www.librdf.org/Perl, Python, PHP, Ruby, C#, Objective-C Jena: http://jena.sourceforge.net/ Java RDFLib: http://www.rdflib.net/ Python ARC2: http://arc2.semsol.net/ PHP ActiveRDF: http://www.activerdf.org/ Ruby
  • 8.
  • 9.
  • 10.
    SPARQL – Queryingthe Web of Data • query language for RDF graphs (i.e., linked data) • extract specific information out of a dataset (or several datasets) • "The SQL for the Web of Data"
  • 11.
  • 12.
    PREFIX mo: <http://purl.org/ontology/mo/> PREFIXdce: <http://purl.org/dc/elements/1.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT DISTINCT ?album ?title ?release_date WHERE { ?album a mo:Record ; dce:date ?release_date ; dce:title ?title . FILTER (year(?release_date) = 2007 && month(?release_date) = 7) } ORDER BY ?release_date
  • 13.
    SPARQL in aNutshell
  • 14.
    PREFIX mo: <http://purl.org/ontology/mo/> PREFIXdce: <http://purl.org/dc/elements/1.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT DISTINCT ?album ?title ?release_date WHERE { ?album a mo:Record ; dce:date ?release_date ; dce:title ?title . FILTER (year(?release_date) = 2007 && month(?release_date) = 7) } ORDER BY ?release_date graph pattern
  • 15.
    Lets try itourselves http://tinyurl.com/getafesparql