Internet Technologies 1 Master of Information System Management Internet Technologies Lecture 7: SPARQL
Internet Technologies 2 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 3 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 4 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 5 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 6 Master of Information System Management Output sparql --query ex1.rq | url | ========================= |
Internet Technologies 7 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 8 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 9 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 10 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 11 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 12 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 13 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 14 Master of Information System Management Generating XML PREFIX foaf: PREFIX rdf: SELECT ?n FROM WHERE { ?contributor foaf:name ?n. }
Internet Technologies 15 Master of Information System Management From The Command Line sparql --query ex8.rq --results rs/xml <sparql xmlns:rdf=" xmlns:xs=" xmlns=" > John Barstow