16
QUERYING Linked Data

Madrid SPARQL handson

Embed Size (px)

Citation preview

Page 1: Madrid SPARQL handson

QUERYING Linked Data

Page 2: Madrid SPARQL handson

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

Page 3: Madrid SPARQL handson

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

Page 4: Madrid SPARQL handson

• 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

Page 5: Madrid SPARQL handson

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

Page 6: Madrid SPARQL handson

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

Page 7: Madrid SPARQL handson

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

Page 8: Madrid SPARQL handson

Handson with SPARQL

Page 9: Madrid SPARQL handson

SPARQL

A Query-language for the Web of Data

Page 10: Madrid SPARQL handson

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"

Page 11: Madrid SPARQL handson

SPARQL Endpoint

Reaso

nin

g?

Page 12: Madrid SPARQL handson

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

Page 13: Madrid SPARQL handson

SPARQL in a Nutshell

Page 14: Madrid SPARQL handson

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

Page 15: Madrid SPARQL handson

Lets try it ourselves

http://tinyurl.com/getafesparql

Page 16: Madrid SPARQL handson