W3C home > Mailing lists > Public > semantic-web@w3.org > November 2012

Re: Incrementing a literal

From: Paul Gearon <gearon@ieee.org>
Date: Sun, 11 Nov 2012 18:11:38 -0500
Message-ID: <CAGZNPFm5x4+yvQwe+LUQy0F=uQJHsEpyntgn1Xm9f63oTWbMhQ@mail.gmail.com>
To: Stephen Williams <sdw@lig.net>
Cc: Andy Seaborne <andy.seaborne@epimorphics.com>, Semantic Web <semantic-web@w3.org>
While some may agree with this, a lot of people will disagree with such an
operation. An "increment" operation implies that you're changing a value.
While some people certainly see an RDF property in this way, it doesn't
match the other concept of "triples", wherein a triple with one
subject/property/value is removed, and another is inserted (where the
subject and property are the same, and the value is one more than the value
from the removed triple). The latter view matches SPARQL, so I doubt there
will be much traction for an operation that supports the "change a value"
perspective.

Regards,
Paul


On Sun, Nov 11, 2012 at 1:11 PM, Stephen Williams <sdw@lig.net> wrote:

>  On 11/11/12 9:06 AM, Andy Seaborne wrote:
>
>
>
> On 10/11/12 11:54, Melvin Carvalho wrote:
>
> Is there a pattern for incrementing a literal counter?
>
> Alice stores turtle in http://example.org/counter
>
> The initial operation should generate something like
>
> <#> <#counter> 1.
>
> Then the subsequent operation
>
> <#> <#counter> 2.
>
> And after that.
>
> <#> <#counter> 3.
>
> And so on ...
>
> Is there a neat way to do this in  distributed way?  SPARQL update?
> Maybe using Etags?
>
>
> SPARQL Update:
>
> DELETE { <#> <#counter> ?c1 }
> INSERT { <#> <#counter> ?c2 }
> WHERE  { <#> <#counter> ?c1 .
>          BIND(?c1+1 AS ?c2) }
>
> There are various ways to deal with the initial condition at the same
> time:
>
> All in one operation:
>
> DELETE { <#> <#counter> ?c1 }
> INSERT { <#> <#counter> ?c2 }
> WHERE  {
>    OPTIONAL { <#> <#counter> ?c1 . }
>    BIND(COALESCE(?c1+1, 1) AS ?c2) }
>
> where the assignment can also be written:
>
>    BIND(IF (BOUND(?c1) , ?c1+1 , 1) AS ?c2)
>
> You can also use two operations in one request: (requests should be atomic
> i.e the two operations together):
>
> # Does a triple for the counter exist?
> INSERT { <#> <#counter> 0 }
> WHERE   { FILTER NOT EXISTS { <#> <#counter> ?c } }
> ;
>
> # Increment always - hence initialize to zero above
> DELETE { <#> <#counter> ?c1 }
> INSERT { <#> <#counter> ?c2 }
> WHERE  { <#> <#counter> ?c1 .
>          BIND(?c1+1 AS ?c2) }
>
>     Andy
>
>
> At some point, a better solution should exist, such as an increment
> operation.  Integrated semantics on another axis.
> For now, perhaps linking a semantic store with some values delegated to a
> Redis database might solve performance, scalability, and similar problems.
>
> sdw
>
> --
> Stephen D. Williams sdw@lig.net stephendwilliams@gmail.com LinkedIn: http://sdw.st/in
> V:650-450-UNIX (8649) V:866.SDW.UNIX V:703.371.9362 F:703.995.0407AIM:sdw Skype:StephenDWilliams Yahoo:sdwlignet Resume: http://sdw.st/gres
> Personal: http://sdw.st facebook.com/sdwlig twitter.com/scienteer
>
>
Received on Sunday, 11 November 2012 23:12:06 GMT

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