Internet Technologies 1 Master of Information System Management Internet Technologies Making Queries on RDF
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 2 Master of Information System Management Both freebase and Dbpedia make their statements available in RDF.
Internet Technologies Today’s Lecture A brief look at SPARQL A brief look at MQL 3 Master of Information System Management
Internet Technologies 4 Master 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
Internet Technologies 5 Master 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
Internet Technologies 6 Master of Information System Management Input <rdf:RDF xmlns:rdf=" xmlns:foaf=" xmlns:rdfs=" xmlns:rss=" xmlns:dc=" xmlns:html=" John Barstow Visions of Aestia by John Barstow This is shortblogger.xml The file bloggers.xml has many bloggers.
Internet Technologies 7 Master of Information System Management Processing PREFIX foaf: SELECT ?url FROM WHERE { ?contributor foaf:name "John Barstow". ?contributor foaf:weblog ?url. } Stored in a file called ex1.rq
Internet Technologies 8 Master of Information System Management Output sparql --query ex1.rq | url | ========================= |
Internet Technologies 9 Master of Information System Management Processing PREFIX foaf: PREFIX rdf: SELECT ?url FROM WHERE { ?contributor rdf:type foaf:Person. ?contributor foaf:weblog ?url. } Output sparql --query ex2.rq | url | =============== |
Internet Technologies 10 Master of Information System Management Processing PREFIX foaf: PREFIX rdf: SELECT ?x ?n FROM WHERE { ?contributor rdf:type foaf:Person. ?contributor foaf:weblog ?x. ?contributor foaf:name ?n } All three conditions must be satisfied to match the query.
Internet Technologies 11 Master of Information System Management Output sparql --query ex4.rq | x | n | ================================================ | | "Seth Ladd" | | | "Morten Frederiksen" | | | "Ora Lassila" | | | "Hazaël-Massieux" | | | "Leigh Dodds" | | | "Henry Story" | | | "Jeen Broekstra" | | | "Danny Weitzner" | | | "Dan Brickley" |
Internet Technologies 12 Master of Information System Management Processing PREFIX foaf: PREFIX rdf: SELECT DISTINCT ?n FROM WHERE { ?contributor foaf:name ?n } Output | n | ================= | ”Mike McCarthy" | | "Pasquale Popolizio" | | "Dean Allemang" | :
Internet Technologies 13 Master of Information System Management Processing PREFIX foaf: PREFIX rdf: SELECT DISTINCT ?n FROM WHERE { ?contributor foaf:name ?n } ORDER BY ?n | n | ============= | "Alexandre Passant" | | "Alistair Miles" | | "Andrew Matthews" | | "Benjamin Nowack" :
Internet Technologies 14 Master 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.
Internet Technologies 15 Master of Information System Management Processing PREFIX foaf: PREFIX rdf: SELECT DISTINCT ?n ?interest FROM WHERE { ?contributor foaf:name ?n. OPTIONAL { ?contributor foaf:interest ?interest } } ORDER BY ?n "Tetherless World Constellation group RPI" "Tim Berners-Lee" "Uldis Bojars"
Internet Technologies 16 Master of Information System Management Generating XML PREFIX foaf: PREFIX rdf: SELECT ?n FROM WHERE { ?contributor foaf:name ?n. }
Internet Technologies 17 Master of Information System Management From The Command Line sparql --query ex8.rq --results rs/xml <sparql xmlns:rdf=" xmlns:xs=" xmlns=" > John Barstow
Internet Technologies MQL Metaweb Query Language Make queries against the freebase data store. The input and outputs are JSON strings. 18 Master of Information System Management
Internet Technologies Using MQL In A URL 19 Master of Information System Management Example from the MQL documentation. Enter the following in your browser: {“query”:{“type”:”/music/artist”,”name”:”The Police”,”album”:[]}} This is a query to freebase represented in JSON.
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; T15” } 20 Master of Information System Management Many more albums in the real query result.
Internet Technologies Another look at the query. { "query": { "type":"/music/artist", "name":"The Police", "album":[] } 21 Master of Information System Management
Internet Technologies Use The Query Editor 22 Master of Information System Management