W3C home > Mailing lists > Public > semantic-web@w3.org > January 2013

Re: SPIN Syntax simplified

From: David Booth <david@dbooth.org>
Date: Thu, 31 Jan 2013 18:33:51 -0500
To: Holger Knublauch <holger@knublauch.com>
Cc: semantic-web@w3.org
Message-ID: <1359675231.25867.24277.camel@dbooth-laptop>
Hi Holger,

On Fri, 2013-02-01 at 08:22 +1000, Holger Knublauch wrote:
> Hi David,
> 
> the prefixes from the surrounding graph should be used for parsing. In a 
> typical application, SPIN rules would be loaded from a file at start-up 
> time and then those prefixes are readily available.

That is convenient, but the downside is that it requires the RDF parser
to have special knowledge of SPIN.

> 
> This does have limitations of course, if no prefixes are available. But 
> forcing full URIs we would sacrifice readability again - I don't think 
> people would always want to repeat the PREFIX statements nor spell out 
> the full URIs each time.

That may be tedious, but it is a safe approach.  

Another possible approach that would avoid the need for the parser to
have special knowledge of SPIN would be to allow the prefixes to be
explicitly asserted at the triple level, such as:

  @prefix ex:  <http://example/def#> .
  ex: spin:globalPrefix "ex:" .

or equivalently:

  <http://example/def#> spin:globalPrefix "ex:" .

These could be global (as shown), or they could be attached to specific
SPIN rules, like this:

> > ex:Person a rdfs:Class ;
> >          ...
> >        spin:rule
> >                [ ...
> >                  sp:prefix ( "ex:" ex: ) ;   # <-- ADDED
> >                  sp:text """
> >                      CONSTRUCT {
> >                          ?this ex:grandParent ?grandParent .
> >                      }
> >                      WHERE {
> >                          ?parent ex:child ?this .
> >                          ?grandParent ex:child ?parent .
> >                      }"""
> >          ...

The SPIN rules processor could know to look for them before parsing a
SPARQL rule that is given as a string that uses namespace prefixes.  It
would then automatically prepend appropriate lines like:

  PREFIX ex: <http://example/def#>

to the beginning of the quoted CONSTRUCT query.

As a refinement, if the global approach is taken, a Turtle parser could
automatically add these spin:globalPrefix assertions wherever a prefix
is declared using @prefix.  (This could serve functions beyond SPIN, so
it would not have to be SPIN specific.)

However, one rub is that Turtle allows prefixes to be re-defined:
http://www.w3.org/TR/turtle/#prefixed-name

  @prefix ex:  <http://example/OLDdef#> .
  ex:apple a ex:Fruit .
  @prefix ex:  <http://example/NEWdef#> .
  ex:pear a ex:Fruit .

which would yield ambiguous spin:prefix assertions, as the above would
effectively become:

  <http://example/OLDdef#> spin:globalPrefix "ex:" .
  <http://example/OLDdef#apple> a ex:Fruit .
  <http://example/NEWdef#> spin:globalPrefix "ex:" .
  <http://example/NEWdef#pear> a ex:Fruit .

But if one avoids re-defining prefixes, then the global approach could
work also.   Or the two approaches could be used together.

David

> 
> I guess the best practices will evolve through usage, and on the web we 
> can never predict what will turn out to be the winning notation...
> 
> Holger
> 
> 
> On 2/1/2013 2:45, David Booth wrote:
> > Hi Holger,
> >
> > On Thu, 2013-01-31 at 11:06 +1000, Holger Knublauch wrote:
> >> For those interested in SPIN, I have just published a blog post [1] that
> >> introduces a fundamental change to the SPIN syntax. In a nutshell, too
> >> many people have complained about the triple-based format to store
> >> SPARQL queries. In the updated spec, the property sp:text can be used to
> >> store the SPARQL query in textual form. This can happen either in
> >> addition to the RDF syntax or alone. Existing SPIN files will of course
> >> continue to work - the technical change to the spec was minimal.
> >>
> >> I hope this change is in the best interest of the semantic web community
> >> and leads to more SPIN implementations from other vendors than TopQuadrant.
> >>
> >> Regards,
> >> Holger
> >>
> >> [1]
> >> http://composing-the-semantic-web.blogspot.com/2013/01/spin-syntax-simplified.html
> > That sounds like a good improvement.  And I think it would be great if
> > SPIN were standardized by W3C at some point.  But I have a question,
> > which I was not able to post on your blog because it does not allow
> > public comments.
> >
> > The example in the blog includes a CONSTRUCT as the quoted string value
> > of the spin:text property:
> >
> > ex:Person a rdfs:Class ;
> >          ...
> >        spin:rule
> >                [ ...
> >                  sp:text """
> >                      CONSTRUCT {
> >                          ?this ex:grandParent ?grandParent .
> >                      }
> >                      WHERE {
> >                          ?parent ex:child ?this .
> >                          ?grandParent ex:child ?parent .
> >                      }"""
> >          ...
> >
> > I notice that the CONSTRUCT query above does not define the "ex:"
> > namespace prefix.  How are namespace prefixes handled inside the quoted
> > strings?  I.e., where/how are they defined?  Are there some other RDF
> > statements somewhere that explicitly define them?  Or are they magically
> > imported from the enclosing Turtle environment?  Or something else?
> >
> >
> 
> 
> 

-- 
David Booth, Ph.D.
http://dbooth.org/

Aaron's Law, in memory of Web prodigy and open information 
advocate Aaron Swartz: http://bit.ly/USR4rx 

Opinions expressed herein are my own and do not necessarily 
reflect those of my employer.
Received on Thursday, 31 January 2013 23:34:21 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 21:45:53 GMT