Internet Technologies Lecture 7 SPARQL 95 733 Internet

  • Slides: 15
Download presentation
Internet Technologies Lecture 7: SPARQL 95 -733 Internet Technologies Master of Information System Management

Internet Technologies Lecture 7: SPARQL 95 -733 Internet Technologies Master of Information System Management 1

SPARQL • SPARQL Simple Protocol and RDF Query Language • W 3 C Recommendation

SPARQL • SPARQL Simple Protocol and RDF Query Language • W 3 C Recommendation January 2008 • Queries written using Turtle Terse RDF Triple Language • Download Jena and ARQ Query Engine • For Ruby, see Active. RDF 95 -733 Internet Technologies Master of Information System Management 2

SPARQL • Three specifications: (1) A query language (2) A query results XML format

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 95 -733 Internet Technologies Master of Information System Management 3

Input <? xml version="1. 0" encoding="UTF-8"? > <rdf: RDF xmlns: rdf="http: //www. w 3.

Input <? xml version="1. 0" encoding="UTF-8"? > <rdf: RDF xmlns: rdf="http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#" xmlns: foaf="http: //xmlns. com/foaf/0. 1/" xmlns: rdfs="http: //www. w 3. 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. w 3. org/1999/xhtml"> <foaf: Agent rdf: node. ID="id 2246040"> <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: see. Also> <rss: channel rdf: about="http: //www. nzlinux. org. nz/blogs/wp-rdf. php? cat=9"> <foaf: maker rdf: node. ID="id 2246040"/> <foaf: topic rdf: resource="http: //www. w 3. org/2001/sw/"/> <foaf: topic rdf: resource="http: //www. w 3. org/RDF/"/> </rss: channel> </rdfs: see. Also> </foaf: Document> </foaf: weblog> <foaf: interest rdf: resource="http: //www. w 3. org/2001/sw/"/> <foaf: interest rdf: resource="http: //www. w 3. org/RDF/"/> 95 -733 Internet Technologies </foaf: Agent> Master of Information System </rdf: RDF> Management This is shortblogger. xml The file bloggers. xml has many bloggers. 4

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> SELECT ? url FROM <shortblogger. xml> WHERE

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> SELECT ? url FROM <shortblogger. xml> WHERE { ? contributor foaf: name "John Barstow". ? contributor foaf: weblog ? url. } Stored in a file called ex 1. rq 95 -733 Internet Technologies Master of Information System Management 5

Output sparql --query ex 1. rq ------------| url | ============= | <http: //www. nzlinux.

Output sparql --query ex 1. rq ------------| url | ============= | <http: //www. nzlinux. org. nz/blogs/> | ---------------------- 95 -733 Internet Technologies Master of Information System Management 6

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#> SELECT ? url FROM <shortblogger. xml> WHERE { ? contributor rdf: type foaf: Person. ? contributor foaf: weblog ? url. } Output sparql --query ex 2. rq ------------| url | ======== | <http: //www. nzlinux. org. nz/blogs/> | 95 -733 Internet Technologies ------------7 Master of Information System Management

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#> SELECT ? x ? n FROM <bloggers. xml> WHERE { All three conditions ? contributor rdf: type foaf: Person. must be satisfied ? contributor foaf: weblog ? x. to match the query. ? contributor foaf: name ? n } 95 -733 Internet Technologies Master of Information System Management 8

Output sparql --query ex 4. rq -------------------------------------------|x |n | ======================== | <http: //www. picklematrix.

Output sparql --query ex 4. 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. w 3. 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. w 3. org/~djweitzner/blog/? cat=8> | "Danny Weitzner" | | <http: //danbri. org/words/> | "Dan Brickley" | 95 -733 Internet Technologies Master of Information System Management 9

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#> SELECT DISTINCT ? n FROM <bloggers. xml> WHERE { ? contributor foaf: name ? n Output --------------------} |n ========= | ”Mike Mc. Carthy" | "Pasquale Popolizio" | "Dean Allemang" : : 95 -733 Internet Technologies Master of Information System Management | | 10

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#> SELECT DISTINCT ? n FROM <bloggers. xml> WHERE { ? contributor foaf: name ? n -----------} ORDER BY ? n 95 -733 Internet Technologies Master of Information System Management |n | ======= | "Alexandre Passant" | | "Alistair Miles" | | "Andrew Matthews" | | "Benjamin Nowack" : 11 :

Semi-Structured Data • Definition: If two nodes of the same type are allowed to

Semi-Structured Data • Definition: If two nodes of the same type are allowed to hold different sets of properties the data is called semistructured. • SPARQL uses the OPTIONAL keyword to process semistructured data. 95 -733 Internet Technologies Master of Information System Management 12

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22

Processing PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#> SELECT DISTINCT ? n ? interest FROM <bloggers. xml> WHERE { ? contributor foaf: name ? n. OPTIONAL { ? contributor foaf: interest ? interest } } ORDER BY ? n "Tetherless World Constellation group RPI" <http: //www. w 3. org/2001/sw/> "Tetherless World Constellation group RPI" <http: //www. w 3. org/RDF/> "Tim Berners-Lee" "Uldis Bojars" <http: //www. w 3. org/2001/sw/> "Uldis Bojars" <http: //www. w 3. org/RDF/> 95 -733 Internet Technologies Master of Information System Management 13

Generating XML PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3.

Generating XML PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX rdf: <http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#> SELECT ? n FROM <shortblogger. xml> WHERE { ? contributor foaf: name ? n. } 95 -733 Internet Technologies Master of Information System Management 14

From The Command Line sparql --query ex 8. rq --results rs/xml <? xml version="1.

From The Command Line sparql --query ex 8. rq --results rs/xml <? xml version="1. 0"? > <sparql xmlns: rdf="http: //www. w 3. org/1999/02/22 -rdf-syntax-ns#" xmlns: xs="http: //www. w 3. org/2001/XMLSchema#" xmlns="http: //www. w 3. org/2005/sparql-results#" > <head> <variable name="n"/> </head> <results> <result> <binding name="n"> <literal>John Barstow</literal> </binding> </results> </sparql> 95 -733 Internet Technologies Master of Information System Management 15