1 / 28

SPARQL

SPARQL. Semantic Web - Spring 2008 Computer Engineering Department Sharif University of Technology. Outline. SPARQL Syntax Semantics. Introduction. W3C recommendation 15 January 2008 for RDF query language Builds on previous RDF query languages such as rdfDB, RDQL, and SeRQL.

Télécharger la présentation

SPARQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SPARQL Semantic Web - Spring 2008 Computer Engineering Department Sharif University of Technology

  2. Outline • SPARQL • Syntax • Semantics

  3. Introduction • W3C recommendation 15 January 2008 • for RDF query language • Builds on previous RDF query languages such as rdfDB, RDQL, and SeRQL. • SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF via middleware. • SPARQL contains capabilities for querying required and optional graph patterns along with their conjunctions and disjunctions.

  4. Making simple queries • Most forms of SPARQL query contain a set of triple patterns called a basic graph pattern. • Triple patterns are like RDF triples except that each of the subject, predicate and object may be a variable. • A basic graph pattern matches a subgraph of the RDF data when RDF terms from that subgraph may be substituted for the variables and the result is RDF graph equivalent to the subgraph.

  5. Example

  6. Multiple matches

  7. Blank node labels in query results

  8. Building RDF graphs

  9. RDF term constraints

  10. Restricting numeric values

  11. Optional match

  12. Multiple optional graph patterns

  13. Matching alternatives

  14. Example RDF

  15. Example • Simple Query: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?url FROM <bloggers.rdf> WHERE { ?contributor foaf:name "Jon Foobar" . ?contributor foaf:weblog ?url . }

  16. Example (cont.) • Optional block: PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?depiction WHERE { ?person foaf:name ?name . OPTIONAL { ?person foaf:depiction ?depiction . } }

  17. Example (cont.) • Alternative matches: PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?name ?mbox WHERE { ?person foaf:name ?name . { { ?person foaf:mbox ?mbox } UNION { ?person foaf:mbox_sha1sum ?mbox } } } • There are many other features in SparQL which is out of scope for this class. Refer to references for more information.

  18. Semantics • A SPARQL graph pattern expression is defined recursively as follows: • (1) A tuple from (IL[V )×(I[V )×(IL[V) is a graph pattern (a triple pattern). • (2) If P1 and P2 are graph patterns, then expressions (P1 AND P2), (P1 OPT P2), and (P1 UNION P2) are graph patterns. • (3) If P is a graph pattern and R is a SPARQL built-in condition, then the expression (P FILTER R) is a graph pattern.

  19. Semantics (cont.) • Semantics of SPARQL is defined using a mapping mechanism • A shorthand notation is used to denote the triple obtained by replacing the variables in t according to • Two mappings μ1 and μ2 are compatible when for all x in dom(μ1) intersect dom(μ2), it is the case that μ1(x) = μ2(x), i.e. when union of μ1 and μ2 is also a mapping.

  20. Semantics (cont.) • Let and be sets of mappings. We define the join of, the union of and the difference between and as:

  21. Semantics (cont.)

  22. Example • Consider the RDF dataset D:

  23. Example (cont.)

  24. SPARQL vs SQL • SPARQLSELECT ?salWHERE { emps:e13954 HR:salary ?sal . } • SQL SELECT salary FROM employees WHERE emp_id = 'e13954'

  25. SPARQL vs SQL • SPARQLSELECT ?id, ?salWHERE { ?id HR:salary ?sal } • SQL SELECT emp_id, salary FROM employees

  26. SPARQL vs SQL • SPARQLSELECT ?hdateWHERE { ?id HR:salary ?sal . ?id HR:hire_date ?hdate . FILTER ?sal >= 21750 } • SQL SELECT hire_date FROM employees WHERE salary >= 21750

  27. SPARQL vs SQL • SPARQL SELECT ?hdate WHERE { ?id HR:salary ?sal . ?id HR:hire_date ?hdate . FILTER ?sal >= 21750 } • SQL SELECT v.hire_date FROM emp_vars AS v, emp_consts AS c WHERE v.salary >= 21750 AND v.emp_id = c.emp_id

  28. References • http://www.w3.org/TR/rdf-sparql-query/ • http://www-128.ibm.com/developerworks/java/library/j-sparql/ • JorgeP´erez , MarceloArenas , and ClaudioGutierrez, “Semantics and Complexity of SPARQL” , 5th International Semantic Web Conference, Athens, GA, USA, November 5-9, 2006, LNCS 4273

More Related