Learn about SPARQL 1.1

David Beckett

This presentation is personal opinion.
I am not speaking on behalf of my employer, Digg Inc..
The slides are presented via S5

David Beckett

SPARQL

Overview

Note: This is not an introduction to SPARQL

  1. SPARQL 1.0
  2. SPARQL 1.1 concepts
  3. Major changes
  4. Functions and operators
  5. RDF Dataset / Graph store management
  6. Other changes
  7. Implementations and pointers

SPARQL 1.0 Concepts

SPARQL 1.0 Query Execution

SPARQL 1.0 query execution components

Based on http://www.dajobe.org/2009/11/sparql11/

SPARQL 1.1 Concepts

SPARQL 1.1 Query Execution

SPARQL 1.1 query execution components

Excluding property paths. Based on http://www.dajobe.org/2009/11/sparql11/

Extended query language power

Aggregates

The new built-in aggregate expressions are:

All are allowed with and without DISTINCT across the arguments.

Grouping of results is optionally done with GROUP BY otherwise the entire result set is 1 group (like SQL). This may bind a variable too.

HAVING executes a filter expression over the results of an aggregation.

Sub-queries

SPARQL 1.1 allows sub-SELECTs

PREFIX : <http://people.example/>
PREFIX : <http://people.example/>
SELECT ?y ?minName
WHERE {
  :alice :knows ?y .
  {
    SELECT ?y (MIN(?name) AS ?minName)
    WHERE {
      ?y :name ?name .
    } GROUP BY ?y
  }
}

Negation and filtering

3 new ways to negate / exclusion:

  1. OPTIONAL { graph-pattern } (1.0)
  2. FILTER ... !expr (1.0)
  3. FILTER ... NOT EXISTS { graph-pattern } (1.1)
  4. Aggregation using HAVING with either of the above (1.1)
  5. graph-pattern MINUS graph-pattern (1.1)

(Some of these can be done with complex UNION and OPTIONAL patterns)

Property Paths

This changes the fundamental SPARQL matching

From:
Triple pattern matches a triple to bind variables.
To:
Triples with property paths regex-like match multiple triples to bind variables.

The essential difference is that depending on the data, the query engine could do a simple match or do a lot of searching for matches.

There is lots of new syntax to select different properties from a subject node:
a/b ^a a|b a* a+ a? a{m,n} a{n} a{m,} a{,n}
where a and b are property URIs.

Introducing new variables

All new ways to introduce variables:

  1. Project expressions: SELECT (expr AS ?var)
  2. Assign variables: BIND (expr AS ?var) in a graph pattern
  3. Grouping: GROUP BY (expr AS ?var)
  4. BINDINGS clause creating a result set
  5. Sub-queries can bind scoped variables

Basic Federated Query

A graph pattern that invokes a SPARQL protocol call and remote query returning the usual result formats

SERVICE <endpoint-uri> {
  graph pattern
}

This can optionally use BINDINGS to pre-bind some variables in a SELECT:

SELECT ?a
{
  ?a ?b ?c .
} BINDINGS ?a {
  ( :value1 )
}

Returns 1 row with ?a bound to :value

This also makes SPARQL into a new syntax to build result sets with no data source or query:

SELECT * { } BINDINGS ?var1 ?var2  {
   ( "var1-value1"  "var2-value1" )
   ( "var1-value2"  "var2-value2" )
}

70+ New keywords, built-ins and operators

ABS ADD AS AVG BIND BINDINGS BNODE CEIL CLEAR COALESCE CONCAT CONTAINS COPY COUNT CREATE DAY DELETE DROP ENCODE_FOR_URI EXISTS FLOOR GROUP_CONCAT HOURS IF IN INSERT INTO IRI isNUMERIC LCASE LOAD MAX MD5 MIN MINUS MINUTES MONTH MOVE NOT EXISTS NOT IN NOW RAND ROUND SAMPLE SECONDS SERVICE SHA1 SHA224 SHA256 SHA384 SHA512 SILENT STRDT STRENDS STRLANG STRLEN STRSTARTS SUBSTR SUM TIMEZONE TO TZ UCASE URI USING WITH YEAR ^a a* a/b a? a{m,n} a|b

New interesting functions and operators

IF(expr, if-true-expr, if-false-expr)
Works on scalar expressions and returns one.

COALESCE(expr, ...)
Takes a variable argument list and returns the first non-error value. Like SQL.

term IN (expression, ...) and term NOT IN ( ... )
Returns a boolean if the term is in/not in in the set of expressions. Like SQL.

EXISTS { graph-pattern } and NOT EXISTS { graph-pattern }
Performs a graph pattern match in the expression and returns a boolean if the pattern returned at least one match. Like a sub-ASK.

New built-in functions and operators

6 New RDF term constructors and functions: BNODE, IRI, URI, isNUMERIC, STRDT, STRLANG

9 New string functions: CONCAT, CONTAINS, ENCODE_FOR_URI, LCASE, STRENDS, STRLEN, STRSTARTS, SUBSTR, UCASE

6 New string digest functions: MD5, SHA1, SHA224, SHA256, SHA384, SHA512

4 New numeric functions: ABS, CEIL, FLOOR, ROUND

9 New date/time and accessor functions: NOW, DAY, HOURS, MINUTES, MONTH, SECONDS, TIMEZONE, TZ, YEAR

7 New aggregate expressions: AVG, COUNT, GROUP_CONCAT (and SEPARATOR), MAX, MIN, SAMPLE, SUM

5 Other new functions and operators: IF, COALESCE, EXISTS and NOT EXISTS, IN and NOT IN, RAND

(plus property path operators)

RDF Dataset / Graph Store management

RDF Dataset: a fixed set of RDF graphs. 1 graph (the default graph) has no name, 0 or more have IRI names.

Graph Store: a service that provides an RDF Dataset which may be managed and changed.

Graph store management keywords: ADD, CLEAR, COPY, CREATE, DELETE, DROP, INSERT, LOAD, MOVE and USING plus WITH and forms of INSERT and DELETE together which allows batch and group combinations.

There are two forms of INSERT / DELETE:

  1. Using referenced graphs URIs
  2. Inline DATA for streaming data

Graph Store Operations

SPARQL 1.1 Graph Store operations shown between graph store, triples and external graphs

Other SPARQL 1.1 documents

Conformance Tests
Tests for the specifications.
I am waiting to hear officially if SPARQL is one thing or many. i.e. if you "Implement SPARQL 1.1" does it mean you have to do it all?
Entailment Regimes
Rules for using SPARQL 1.1 in an inferencing environment such as RDF/S and OWLs.
Query Results JSON Format
A standard format for writing the query results in JSON. Covers same area as the XML results format.
Service Description
An HTTP GET to describe a SPARQL endpoint and what it provides: functions, aggregates, property functions, result formats etc.

Free Software / Open Source Implementations

Not a complete list. Also since SPARQL 1.1 is not complete so everything here cannot be said to be definitive.

Some of the protocol aspects (a service) are implemented by related projects not the core SPARQL systems.

Commercial Implementations

Cloud Implementations

Thanks

Slides: http://www.dajobe.org/talks/201105-sparql-11/

Appendix: SPARQL Tutorials and Learning materials

Appendix: SPARQL 1.1 References