SPIN Syntax Simplified
SPIN (W3C member submission) is an RDF vocabulary to embed SPARQL-based rules, constraints, functions and templates into semantic web models. It also includes a triple-based serialization of SPARQL which can be used to share the SPARQL queries of rules, constraints etc in a machine-friendly format. Among others, this syntax operates on true URI references and is therefore independent of prefix declarations, makes it easier to find and refactor the resources used in the query and supports various meta-operations on the structure of a query.
However, over the years I have collected overwhelming feedback that the SPIN RDF notation is an obstacle to wider adoption of SPIN. I have therefore made the SPIN syntax more flexible, so that SPIN files can more easily be edited in text files, and to reduce the implementation costs of SPIN engines. The change that I have made to the spec (which is now online) is very small: SPIN already had a property called sp:text that can be used to store a query string in the conventional textual representation of SPARQL. All I needed to change was that:
If sp:text is present, then the SPIN RDF triples are optional.
With this change, a SPIN rule can be edited in Turtle as:
ex:Person a rdfs:Class ; rdfs:label "Person"^^xsd:string ; rdfs:subClassOf owl:Thing ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this ex:grandParent ?grandParent . } WHERE { ?parent ex:child ?this . ?grandParent ex:child ?parent . }""" ] .
and a SPIN constraint based on an ASK becomes:
ex:Parent a rdfs:Class ; rdfs:label "Parent"^^xsd:string ; rdfs:subClassOf ex:Person ; spin:constraint [ a sp:Ask ; sp:text """ # must be at least 18 years old ASK WHERE { ?this ex:age ?age . FILTER (?age < 18) . }""" ] .
I believe this change supports the best of both worlds: editing tools such as TopBraid Composer can use the RDF syntax to keep track of references and support automated refactorings, while published models may only include the sp:text triples (or both) to make it easier for 3rd party tools to use the SPIN definitions. The implementation burden of this change is very light - all I needed to change in the SPIN API was a single method that turns the sp:Constructs etc into Jena Query objects. The only downside of this change is that there may be two dialects appearing and that some implementations may not support the full RDF syntax. If the market adopts these changes, then 3rd party vendors will probably only support the text syntax, so that most published models may end up containing the sp:text triples.
The next version of TopBraid (4.2) will have one-click features to move between the two syntaxes, for example to switch to the text syntax before publishing a SPIN file. A new version of the SPIN API will be available shortly.