internet technologies

22
95-733 Internet Technologies 1 Master of Information System Management Internet Technologies Making Queries on RDF

Upload: kasper-molina

Post on 31-Dec-2015

24 views

Category:

Documents


0 download

DESCRIPTION

Internet Technologies. Making Queries on RDF. Two Approaches. SPARQL - Simple Protocol And RDF Query Language - Looks like SQL - Used by Dbpedia MQL - Metaweb Query Language - Based on JSON - Used by Freebase. Both freebase and Dbpedia - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Internet Technologies

95-733 Internet Technologies1Master of Information System

Management

Internet Technologies

Making Queries on RDF

Page 2: Internet Technologies

95-733 Internet Technologies

Two Approaches

• SPARQL - Simple Protocol And RDF Query Language - Looks like SQL - Used by Dbpedia• MQL - Metaweb Query Language - Based on JSON - Used by Freebase

2Master of Information System Management

Both freebaseand Dbpediamake theirstatements available in RDF.

Page 3: Internet Technologies

95-733 Internet Technologies

Today’s Lecture

• A brief look at SPARQL• A brief look at MQL

3Master of Information System Management

Page 4: Internet Technologies

95-733 Internet Technologies4Master of Information System

Management

SPARQL• SPARQL Simple Protocol and RDF

Query Language• W3C Recommendation January 2008• Queries written using Turtle - Terse

RDF Triple Language• Download Jena and ARQ Query

Engine • For Ruby, see ActiveRDF

Page 5: Internet Technologies

95-733 Internet Technologies5Master of Information System

Management

SPARQL

• Three specifications: (1) A query language (2) A query results XML format (3) A WSDL 2.0 Data Access Protocol using HTTP and SOAP

• SPARQL is read only and cannot modify the RDF data

Page 6: Internet Technologies

95-733 Internet Technologies6Master of Information System

Management

Input<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:rss="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:html="http://www.w3.org/1999/xhtml"> <foaf:Agent rdf:nodeID="id2246040"> <foaf:name>John Barstow</foaf:name> <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> <foaf:weblog> <foaf:Document rdf:about="http://www.nzlinux.org.nz/blogs/"> <dc:title>Visions of Aestia by John Barstow</dc:title> <rdfs:seeAlso> <rss:channel rdf:about="http://www.nzlinux.org.nz/blogs/wp-rdf.php?cat=9"> <foaf:maker rdf:nodeID="id2246040"/> <foaf:topic rdf:resource="http://www.w3.org/2001/sw/"/> <foaf:topic rdf:resource="http://www.w3.org/RDF/"/> </rss:channel> </rdfs:seeAlso> </foaf:Document> </foaf:weblog> <foaf:interest rdf:resource="http://www.w3.org/2001/sw/"/> <foaf:interest rdf:resource="http://www.w3.org/RDF/"/> </foaf:Agent> </rdf:RDF>

This is shortblogger.xml

The file bloggers.xml has many bloggers.

Page 7: Internet Technologies

95-733 Internet Technologies7Master of Information System

Management

Processing

PREFIX foaf: <http://xmlns.com/foaf/0.1/>SELECT ?urlFROM <shortblogger.xml>WHERE { ?contributor foaf:name "John Barstow" . ?contributor foaf:weblog ?url .}

Stored in a file calledex1.rq

Page 8: Internet Technologies

95-733 Internet Technologies8Master of Information System

Management

Outputsparql --query ex1.rq------------------------| url |=========================| <http://www.nzlinux.org.nz/blogs/> |--------------------------------------------

Page 9: Internet Technologies

95-733 Internet Technologies9Master of Information System

Management

ProcessingPREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>SELECT ?urlFROM <shortblogger.xml>WHERE { ?contributor rdf:type foaf:Person . ?contributor foaf:weblog ?url .}

Output

sparql --query ex2.rq-------------------------| url |===============| <http://www.nzlinux.org.nz/blogs/> |-------------------------

Page 10: Internet Technologies

95-733 Internet Technologies10Master of Information System

Management

ProcessingPREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>SELECT ?x ?n FROM <bloggers.xml>WHERE { ?contributor rdf:type foaf:Person . ?contributor foaf:weblog ?x . ?contributor foaf:name ?n}

All three conditionsmust be satisfiedto match the query.

Page 11: Internet Technologies

95-733 Internet Technologies11Master of Information System

Management

Outputsparql --query ex4.rq--------------------------------------------------------------------------------------| x | n |================================================| <http://www.picklematrix.net/semergence/> | "Seth Ladd" || <http://www.wasab.dk/morten/blog/> | "Morten Frederiksen" || <http://www.lassila.org/blog/> | "Ora Lassila" || <http://people.w3.org/~dom/> | "Hazaël-Massieux" || <http://xmlarmyknife.org/blog/> | "Leigh Dodds" || <http://blogs.sun.com/bblfish/> | "Henry Story" || <http://jeenbroekstra.blogspot.com/> | "Jeen Broekstra" || <http://people.w3.org/~djweitzner/blog/?cat=8> | "Danny Weitzner" || <http://danbri.org/words/> | "Dan Brickley" |

Page 12: Internet Technologies

95-733 Internet Technologies12Master of Information System

Management

ProcessingPREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>SELECT DISTINCT ?nFROM <bloggers.xml>WHERE { ?contributor foaf:name ?n}

Output-----------------------------------------| n |=================| ”Mike McCarthy" || "Pasquale Popolizio" || "Dean Allemang" |::

Page 13: Internet Technologies

95-733 Internet Technologies13Master of Information System

Management

ProcessingPREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>SELECT DISTINCT ?nFROM <bloggers.xml>WHERE { ?contributor foaf:name ?n} ORDER BY ?n

----------------------| n |=============| "Alexandre Passant" || "Alistair Miles" || "Andrew Matthews" || "Benjamin Nowack" ::

Page 14: Internet Technologies

95-733 Internet Technologies14Master of Information System

Management

Semi-Structured Data

• Definition: If two nodes of the same type are allowed to hold different sets of properties the data is called semi-

structured. • SPARQL uses the OPTIONAL

keyword to process semi-structured data.

Page 15: Internet Technologies

95-733 Internet Technologies15Master of Information System

Management

ProcessingPREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>SELECT DISTINCT ?n ?interestFROM <bloggers.xml>WHERE { ?contributor foaf:name ?n . OPTIONAL { ?contributor foaf:interest ?interest }} ORDER BY ?n "Tetherless World Constellation group RPI" <http://www.w3.org/2001/sw/>

"Tetherless World Constellation group RPI" <http://www.w3.org/RDF/> "Tim Berners-Lee" "Uldis Bojars" <http://www.w3.org/2001/sw/> "Uldis Bojars" <http://www.w3.org/RDF/>

Page 16: Internet Technologies

95-733 Internet Technologies16Master of Information System

Management

Generating XMLPREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>SELECT ?n FROM <shortblogger.xml>WHERE { ?contributor foaf:name ?n .}

Page 17: Internet Technologies

95-733 Internet Technologies17Master of Information System

Management

From The Command Linesparql --query ex8.rq --results rs/xml

<?xml version="1.0"?><sparql xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xs="http://www.w3.org/2001/XMLSchema#" xmlns="http://www.w3.org/2005/sparql-results#" > <head> <variable name="n"/> </head> <results> <result> <binding name="n"> <literal>John Barstow</literal> </binding> </result> </results></sparql>

Page 18: Internet Technologies

95-733 Internet Technologies

MQL

• Metaweb Query Language• Make queries against the freebase

data store.• The input and outputs are JSON

strings.

18Master of Information System Management

Page 19: Internet Technologies

95-733 Internet Technologies

Using MQL In A URL

19Master of Information System Management

Example from the MQL documentation.

Enter the following in your browser:

https://api.freebase.com/api/service/mqlread?query={“query”:{“type”:”/music/artist”,”name”:”The Police”,”album”:[]}}

This is a query to freebase represented in JSON.

Page 20: Internet Technologies

95-733 Internet Technologies

Output{ "code": "/api/status/ok", "result": { "album": [ "Outlandos d'Amour", "Reggatta de Blanc", "Zenyatt\u00e0 Mondatta” "The Police Live!" ], "name": "The Police", "type": "/music/artist" }, "status": "200 OK", "transaction_id”:"cache;cache03.p01.sjc1:8101;2011-10-13T15” }

20Master of Information System Management

Many morealbums in the real query result.

Page 21: Internet Technologies

95-733 Internet Technologies

Another look at the query.

{ "query": { "type":"/music/artist", "name":"The Police", "album":[] }}

21Master of Information System Management

Page 22: Internet Technologies

95-733 Internet Technologies

Use The Query Editor

http://www.freebase.comqueryeditor

22Master of Information System Management