- From: Stephen Williams <sdw@lig.net>
- Date: Sun, 11 Nov 2012 10:11:26 -0800
- To: Andy Seaborne <andy.seaborne@epimorphics.com>
- CC: semantic-web@w3.org
- Message-ID: <509FEA4E.10603@lig.net>
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.0407
AIM: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 18:11:51 UTC