SparqlPatch

From Semantic Web Standards

Status

Proposed by Eric Prud'hommeaux. Discussed as one option by the Linked Data Platform Working Group, but the group decided not to standardize in this space yet.

Summary: SparqlPatch is a subset of SPARQL 1.1 Update with only a DELETE, INSERT and WHERE clause. The WHERE clause is restricted to one Basic Graph Pattern with no property paths or variable predicates.

Motivation

SparqlPatch can be executed by any SPARQL 1.1 engine. The simpler grammar and the reduced complexity (and power) are intended to make it easier to implement over a triple store or other back-end, for example, SQL database. The inclusion of a WHERE clause allows one to code defensibly against lost updates or expired data.

Example

This renames all US Presidents with the given name "Bill" to "William".

PATCH http://us.example/presidents HTTP/1.0
Content-Type: text/sparqlpatch

PREFIX foaf:  <http://xmlns.com/foaf/0.1/>
PREFIX : <http://politics.example/ns#>

DELETE { ?person foaf:givenName 'Bill' }
INSERT { ?person foaf:givenName 'William' }
WHERE
  { ?person a :USPresident ; foaf:givenName 'Bill'
  } 

Data before:

@prefix foaf:  <http://xmlns.com/foaf/0.1/> .

<p25> a :USPresident ;
  foaf:givenName "Bill" ; foaf:familyName "McKinley" .
<p27> a :USPresident ;
  foaf:givenName "Bill" ; foaf:familyName "Taft" .
<p42> a :USPresident ;
  foaf:givenName "Bill" ; foaf:familyName "Clinton" .

Data after:

@prefix foaf:  <http://xmlns.com/foaf/0.1/> .

<p25> a :USPresident ;
  foaf:givenName "William" ; foaf:familyName "McKinley" .
<p27> a :USPresident ;
  foaf:givenName "William" ; foaf:familyName "Taft" .
<p42> a :USPresident ;
  foaf:givenName "William" ; foaf:familyName "Clinton" .

Protocol

SparqlPatch is a format for conveying modifications to an HTTP resource. An HTTP PATCH with a Content-Type of text/sparqlpatch is intended to modify the RDF graph or apparent RDF graph at the effective request URI [HTTPMes].

Grammar

The SparqlPatch sublanguage of SPARQL Update can be summarized as:

(DELETE TriplesTemplate (INSERT TriplesTemplate)? | INSERT TriplesTemplate)
WHERE '{' TriplesTemplate '}'

See the SparqlPatch grammar and play with the simple validator.

Semantics

The behavior of the SparqlPatch sublangauge is defined by the following sections of the SPARQL Update Formal Model:

The graph being modified is the upon which the PATCH opperation is applied. The Dataset( QuadPattern, μ, DS, GS ) constructor in Section 4.2.3 Dataset( QuadPattern, μ, DS, GS ) is of the form 'GRAPH' VarOrIri '{' TriplesTemplate? '}' where the graph is the effective request URI [HTTPMes] of the PATCH request.

References

[HTTPMes] Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing, R. Fielding, J. Reschke; June 2014 http://tools.ietf.org/html/rfc7230

[SPUP] SPARQL 1.1 Update], Paul Gearon, Alexandre Passant, Axel Polleres; W3C Recommendation 21 March 2013 http://www.w3.org/TR/2013/REC-sparql11-update-20130321/