Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chungnam National University DataBase System Lab. 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014.

Similar presentations


Presentation on theme: "Chungnam National University DataBase System Lab. 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014."— Presentation transcript:

1 Chungnam National University DataBase System Lab SPARQL Query Language for RDF

2 Chungnam National University DataBase System Lab. Contents SPARQL Status SPARQL Overview SPARQL Feature Summary References Appendix 2

3 Chungnam National University DataBase System Lab. SPARQL Status SPARQL Query Language for RDF W3C, /http://www.w3.org/TR/2007/WD-rdf-sparql-query / Published W3C Working Draft 26 March 2007 SPARQL Protocol for RDF W3C, /http://www.w3.org/TR/2006/CR-rdf-sparql-protocol / Published W3C Candidate Recommendation 6 April 2006 SPARQL Query Results XML Format W3C, /http://www.w3.org/TR/2006/CR-rdf-sparql-XMLres / Published W3C Candidate Recommendation 6 April

4 Chungnam National University DataBase System Lab. SPARQL Overview RDF Resource Description Framework Flexible and extensible way to represent information about WWW resources SPARQL SPARQL Protocol And RDF Query Language Query Language + Protocol + XML Results Format Product of the RDF Data Access Working Group A query language for access and query RDF graphs A protocol for issuing queries via HTTP GET, HTTP POST, or SOAP Perfect for mashing up disparate data sources representable as RDF 4

5 Chungnam National University DataBase System Lab. SPARQL Overview It provides facilities to: Extract information in the form of URIs, blank nodes, plain and typed literals Extract RDF subgraphs Construct new RDF graphs based on information in the queried graphs Feature Matching graph patterns Variables – global scope; indicated by ? or $ Query terms – based on Turtle syntax Terms delimited by "<>" are relative URI references Data description format - Turtle 5

6 Chungnam National University DataBase System Lab. SPARQL Query Example Listing 1. SPARQL query to find the URL of a contributor's blog PREFIX foaf: SELECT ?url FROM WHERE { ?contributor foaf:name "Jon Foobar". ?contributor foaf:weblog ?url. } 6 Figure 1. Basic graph structure for a single contributor in bloggers.rdf Find the URL of the blog by the person named Jon Foobar Result

7 Chungnam National University DataBase System Lab. Graph Patterns RDF Dataset Result Forms Testing Values Inference Data Virtualization Access Multiple Sources SPARQL Protocol Walkthrough SPARQL Features

8 Chungnam National University DataBase System Lab. Graph Patterns Set of Triple Patterns Triple Pattern – similar to an RDF Triple (subject, predicate, object), but any component can be a query variable; literal subjects are allowed Matching a triple pattern to a graph: bindings between variables and RDF Terms 8 xv rdf:typerdf:Property rdf:type rdf:type rdf:Property SELECT ?x ?v WHERE { ?x ?x ?v } ?book dc:title ?title

9 Chungnam National University DataBase System Lab. Graph Pattern - Multiple Matches 9 PREFIX foaf: SELECT ?name ?mbox WHERE { ?x foaf:name ?name. ?x foaf:mbox ?mbox foaf:. _:a foaf:name "Johnny Lee Outlaw". _:a foaf:mbox. _:b foaf:name "Peter Goodguy". _:b foaf:mbox. namembox "Johnny Lee Outlaw" "Peter Goodguy" Group Graph Pattern (set of graph patterns) also! Data Query Query Result

10 Chungnam National University DataBase System Lab. RDF Dataset The RDF data model expresses information as a graph Many RDF data stores hold a multiple RDF graphs There is one graph which does not have a name, called the background graph, and zero or more named graphs, identified by URI reference 10 # Default dc:. dc:publisher "Bob". dc:publisher "Alice". # Named graph: foaf:. _:a foaf:name "Bob". _:a foaf:mbox.

11 Chungnam National University DataBase System Lab. Querying the Dataset 11 # Graph: foaf:. _:a foaf:name "Alice". _:a foaf:mbox. _:a foaf:knows _:b. _:b foaf:name "Bob". _:b foaf:mbox. _:b foaf:age 32. _:b foaf:PersonalProfileDocument. # Graph: foaf:. _:1 foaf:mbox. _:1 foaf:PersonalProfileDocument. _:1 foaf:age 35.

12 Chungnam National University DataBase System Lab. Accessing Graph Labels 12 PREFIX foaf: PREFIX data: SELECT ?src ?age WHERE GRAPH ?src { ( ?x foaf:mbox ) ( ?x foaf:age ?age ) } srcage PREFIX foaf: PREFIX data: SELECT ?age WHERE GRAPH data:bobFoaf { ( ?x foaf:mbox ) ( ?x foaf:age ?age ) } age 35

13 Chungnam National University DataBase System Lab. Result Forms SPARQL has a number of query forms for returning results SELECT Returns all, or a subset of the variables bound in a query pattern match Formats : XML or RDF/XML CONSTRUCT Returns an RDF graph constructed by substituting variables in a set of triple templates DESCRIBE Returns an RDF graph that describes the resources found ASK Returns whether a query pattern matches or not 13

14 Chungnam National University DataBase System Lab. Testing Values Named functions and syntactically constructed operations: Operands: subset of XML Schema DataTypes {xsd:string, xsd:decimal, xsd:double, xsd:dateTime} and types derived from xsd:decimal. Subset of XQuery 1.0 and XPath 2.0 functions and operators Operands: xs:string, xs:double, xs:float, xs:decimal, xs:integer, xs:dateTime Additional operators: sop:RDFterm-equal, sop:bound, sop:isURI, sop:isBlank, sop:isLiteral, sop:str, sop:lang, sop:datatype, sop:logical-or, sop:logical-and Type Promotion : xs:double, xs:float, xs:decimal Each of the numeric types is promoted to any type higher in the above list when used as an argument to function expecting that higher type 14

15 Chungnam National University DataBase System Lab. Inference An RDF graph may be backed by inference OWL, RDFS, application, rules 15 PREFIX rdf: SELECT ?type WHERE { ?x rdf:type ?type. } :x rdf:type :C. :C rdfs:subClassOf :D | type | ===== | :C | | :D |

16 Chungnam National University DataBase System Lab. Data Virtualization SPARQL as integrator Data remains where it is Existing applications untouched Data appears as RDF, query to native form SPARQL to SQL Direct mapping of tables Semi-automatic generation of mapping SquirrelRDF (also does LDAP) Modelled: D2RQ High-quality mapping, manually developed 16

17 Chungnam National University DataBase System Lab. Federated Query Single Point of Access Inputs: Service Description Information Directory Request Outputs: Unified results 17 Query Broker SPARQL => SPARQL Doc DB Corp LDAP RDF SPARQL Query

18 Chungnam National University DataBase System Lab. Access Multiple Sources Find the name and addresses of authors of a paper Query tech reports first, then go to LDAP for more information. SQL database; LDAP server 18 PREFIX dc: PREFIX ldap: PREFIX foaf: SELECT ?name ? { ?doc dc:title ?title. FILTER regex(?title, SPARQL). ?doc dc:creator ?reseacher. ?researcher ldap: ? . ?researcher ldap:name ?name }

19 Chungnam National University DataBase System Lab. Access Multiple Sources Find the reports written by the person with address Go to LDAP first, then the reports database 19 PREFIX dc: PREFIX ldap: PREFIX foaf: SELECT ?name { ?doc dc:title ?title. ?doc dc:creator ?reseacher. ?researcher ldap: . }

20 Chungnam National University DataBase System Lab. 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 20

21 Chungnam National University DataBase System Lab. 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) 21

22 Chungnam National University DataBase System Lab. 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 22

23 Chungnam National University DataBase System Lab. HTTP Binding Example HTTP Binding Get methods 23 GET /sparql/?query=EncodedQuery &default-graph-uri= &named-graph-uri=http://my.example/bob &named-graph-uri=http://my.example/alice HTTP/1.1Host: my.example User-agent: sparql-client/0.1

24 Chungnam National University DataBase System Lab. WSDL Description File Example 24 WSDL description file: (HTTP binding part)

25 Chungnam National University DataBase System Lab. SOAP Binding Example 25 HTTP/ OK Date: Wed, 27 Dec :48:25 GMT Server: Apache/ (Unix) PHP/4.3.4 DAV/1.0.3 Connection: closeContent-Type: application/sparql-results+xml; charset=utf-8 … …

26 Chungnam National University DataBase System Lab. Walkthrough Example(1) XML File 26 Henry Story Tim Bray Jonathan Story

27 Chungnam National University DataBase System Lab. Walkthrough Example(1) SPARQL 27 [ a :Person; :name "Henry Story"; :mbox ; :knows [ a :Person; :name "Tim Bray"; :mbox ]; ].

28 Chungnam National University DataBase System Lab. Graph Representation 28

29 Chungnam National University DataBase System Lab. Walkthrough Example(2) XML File 29 Jonathan Story France Tim Bray Canada

30 Chungnam National University DataBase System Lab. Walkthrough Example(2) SPARQL 30 [ a :Person; :name "Tim Bray"; :mbox :address [ a :Address; :country ] ]. [ a :Person; :name "Jonathan Story"; :mbox :address [ a :Address; :country ] ].

31 Chungnam National University DataBase System Lab. Graph Representation 31

32 Chungnam National University DataBase System Lab. Merge Graph Representation 32

33 Chungnam National University DataBase System Lab. Summary SPARQL (SPARQL Protocol And RDF Query Language) is a query language for getting information from RDF graphs It provides facilities to: Extract information in the form of URIs, bNodes, Plain and typed literals Extract RDF subgraphs Construct new RDF graphs based on information in the queried graphs 33

34 Chungnam National University DataBase System Lab. References W3C, SPARQL Query Language for RDF /, 26, March / IBM Developerworks, Search RDF data with SPARQL 128.ibm.com/developerworks/java/library/j-sparql/, 10, May. 2005http://www- 128.ibm.com/developerworks/java/library/j-sparql/ Oreillynet, SPARQL: Web 2.0 Meet the Semantic Web _web_20_meet_the_semanti.html, 16, September _web_20_meet_the_semanti.html 34

35 Chungnam National University DataBase System Lab. Appendix-01 SPARQL Update Future HP proposal to W3C 35 INSERT { book:newBook dc:title More about SPARQL. book:newBook dc:creator [ foaf:mbox ; foaf:name Alex Author ] } DELETE { ?book dc:title ?title ; dc:creator ?c } WHERE { ?book dc:title ?title ; dc:creator ?c FILTER regex(?title, first edition) }

36 Chungnam National University DataBase System Lab. Appendix-02 SPARQL: Web 2.0 Meet the Semantic Web RDF is pretty foundational to the Semantic Web Most Web 2.0 applications and services involve a REST protocol or interface REST offers a standard set of operations GET, PUT, POST, DELETE No standard way to execute an arbitrary query A Web 2.0 app or services dataset Get back a representation of that resource 36

37 Chungnam National University DataBase System Lab. Appendix-02 SW and Web 2.0 need a data access protocol Using WSDL 2.0, SPARQL Protocol for RDF describes a very simple web service with one operation, query Available with both HTTP and SOAP bindings The way you send SPARQL queries to other sites The way you get back the results Imagine having one query language, and one client, which lets you arbitrarily slice the data of Web 2.0 sites, all FOAF files, all of the RSS 1.0 feeds A good SPARQL client implementation in Javascript, along with some conventions for building and moving queries around in an AJAX-friendly way SPARQL over AJAX just by itself is so cool it gives me a headache! 37


Download ppt "Chungnam National University DataBase System Lab. 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014 1 4 2014."

Similar presentations


Ads by Google