380 likes | 576 Views
SPARQL. A. Emrah Sanön. RDF. RDF is quite committed to Semantic Web. Data model Serialization by means of XML Formal semantics Still something is missing! A standard query language. A way for the queries and their respective results to be transported between applications / services.
E N D
SPARQL A. Emrah Sanön
RDF • RDF is quite committed to Semantic Web. • Data model • Serialization by means of XML • Formal semantics • Still something is missing! • A standard query language. • A way for the queries and their respective results to be transported between applications / services.
…result SPARQL
What is SPARQL • Simple Protocol and RDF Query Language • Sparkle /'spär-k&l/ • A Protocol • A standard RDF Query Language (QL)
SPARQL as a Protocol • GET /sparql/?query=EncodedQuery&default-graph-uri=http://my.example/publishers&named-graph-uri=http://my.example/bob&named-graph-uri=http://my.example/aliceHTTP/1.1Host: my.exampleUser-agent: sparql-client/0.1
SPARQL as a Protocol • A way of communication between parties that run SPARQL queries. • Defining a way of invoking the service. • Bindings of a transport protocol for that goal.
SPARQL Protocol (1) • WSDL description file: • Description of the protocol. • Not for human understanding. • HTTP binding: • Specify how to encode SPARQL queries in URLs with GET and POST methods. • SOAP binding: • Specify the SOAP message format (XML message exchange format for queries)
WSDL Descriptionfile • WSDL description file: (HTTP binding part) <binding name="queryHttp" interface="tns:SparqlQuery“ … > <fault name="MalformedQuery" whttp:zode="400"/> <!-- the GET binding for query operation --> <operation ref="tns:query" whttp:method="GET" whttp:inputSerialization=“…" /> </binding>
SPARQL Protocol (2) • Interface SparqlQuery • Only one operation: query • For transferring string query • Data types: via XML schema • Bindings: HTTP / SOAP binding for invokable operations. • A service must support SparqlQuery interface • support the bindings as described in the WSDL.
SPARQL Protocol Examples • Examples after we cover SPARQL Query Language for RDF.
SPARQL Query Language • A standard query language in the form of expressive query against the RDF data model… • Data access language • Graph patterns • Powerful than XML queries in some aspects
SPARQL Query Language (1) • SQL: • Internals of DB (tables, fields, data, meaning) • Impossible to query databases on the WILDWILDWEB. • So, what does SPARQL propose? • URIs. • Querying databases globally. • Combining data globally. • Value of data grows exponentially with the ways you combine it.
The Wild Wild Web SQL SPARQL XML
SPARQL Query Language (2) • Data structure definitions are being developed worldwide in a distributed manner. • Common ontologies (Dublin Core, Foaf, DOAP, etc.) • A database publishes the ontologies it exports to • An application queries it using those ontologies.
Power of SPARQL Illustrated • Ask fotograf.com if it has a picture which matches some constraints such as title, date, size, and some other tag… • Then ask google for URLs in relation to the tag we specified. • And turn the results of these two uncoordinated data as an RSS feed on your site. • All this in just two-three SPARQL queries.
Power of SPARQL (2) • Ask music cds of price less than 10 • You can run this query against hepsiburada.com, amazon, e-bay, gittigidiyor.com or any other seller on earth who has a website and a database. • No seller needs to change their databases. • Seller needs: Conversion layer between ontologies and database. • Client needs: connectivity framework (like JDBC) for java.
Power of SPARQL (2) Imp. • PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX ns: <http://example.org/ns#> • SELECT ?title ?price WHERE { ?x ns:price ?price . FILTER (?price < 10) . ?x dc:title ?title . }
SPARQL Syntax -brief-1 • URIs • <URI> in < > • or@PREFIXprefix:<http://....> • prefix:name for full URI • Literals • “Literal“ or “Literal”@language • Blank Node • _:name or[] for a Blank Node used just once
SPARQL Syntax -brief-2 • Triples and . • :x :y :z . :t :q :s . • Common predicate and subject: • :x :y :z, :t .which is the same as :x :y :z . :x :y :t . • Common subject: • RDF Collections • :x :y ( :z :t :q :s )which is short for many triples(as lists in LISP)
A walkthrough example illustrating the power of SPARQL XML/SQL SPARQL
Walkthrough example (1xml) <Person> <name>Henry Story</name><mbox>hs@bblfish.net</mbox><knows><Person><name>Tim Bray</name> <mbox>tb@eg.com</mbox> </Person><Person><name>Jonathan Story</name> <mbox>js@eg.edu</mbox> </Person> </knows> </Person>
Walkthrough example (1sparql) [ a :Person; :name "Henry Story"; :mbox <mailto:hs@insead.edu>; :knows [ a :Person; :name "Tim Bray"; :mbox <mailto:tb@eg.com]; :knows [ a :Person; :name "Jonathan Story"; :mbox <mailto:js@eg.edu> ]; ] .
Walkthrough example (2) <AddressBook><Person> <name>Jonathan Story</name> <mbox>Jonathan.Story@eg.edu</mbox><address><Country>France</Country> </address> </Person> <Person> <name>Tim Bray</name> <mbox>Tim.Bray@eg.Com</mbox> <address><Country>Canada</Country> </address> </Person> </AddressBook>
Walkthrough example (2sparql) [ a :Person; :name "Tim Bray"; :mbox <mailto:Tim.Bray@eg.com> :address [ a :Address; :country "Canada"@en ] ]. [ a :Person; :name "Jonathan Story"; :mbox <mailto:Jonathan.Story@eg.edu> :address [ a :Address; :country "France"@en ] ].
Walkthrough example (2) These graphs can be mergedinto the following graph especially if the mbox relation is stated as being inverse functional
Walkthrough example (2) "Who does Henry know who lives in Canada, and what is their e-mail address?" Can only be answered by aggregating data from both documents. Can not be done using the XML query languages, which can only work on the surface of the document.
Walkthrough example (2sparql) SELECT ?name ?mail WHERE { [a :Person; :name "Henry Story"; :knows [ :name ?name; :mbox ?mail; :address [ a :Address;:country "Canada"@en; ] ] ]. }
Walkthrough example (3sparql) Names and websites of contributors to PlanetRDF PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?website FROM <http://planetrdf.com/bloggers.rdf> WHERE { ?person foaf:weblog ?website ; foaf:name ?name . ?website a foaf:Document }
Protocol Example (1) PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?who ?g ?mbox FROM <http://my.example/publishers> FROM NAMED <http://my.example/alice> FROM NAMED <http://my.example/bob> WHERE { ?g dc:publisher ?who . GRAPH ?g { ?x foaf:mbox ?mbox } }
Protocol Example (1) HTTP/1.1 200 OK Date: Wed, 27Dec 2005 12:48:25 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: closeContent-Type: application/sparql-results+xml; charset=utf-8 <?xml version="1.0"?> <sparql xmlns=“…"> … … </sparql>
References • http://www.w3.org/2004/Talks/17Dec-sparql/intro/all.html • http://jena.sourceforge.net/ARQ/Tutorial/ • http://blogs.sun.com/roller/page/bblfish • http://xmlarmyknife.org/api/rdf/sparql • http://xml.com/lpt/a/2005/11/16/introducing-sparql-querying-semantic-web-tutorial.html • http://www.w3.org/2005/Talks/12May-SPARQL/all.html
References (2) • http://www-128.ibm.com/developerworks/xml/library/j-sparql/ • http://www.w3.org/TR/rdf-sparql-protocol/ • http://www.w3.org/2004/Talks/17Dec-sparql/intro/ex1.rq • http://www.oreillynet.com/pub/wlg/7823
Thank you… For your attendance and patience