Re: Replacing URIs via SPARQL update

On 18 August 2012 01:16, Andy Seaborne <andy.seaborne@epimorphics.com> wrote:
>
>
> On 16/08/12 14:28, Carsten Keßler wrote:
>>
>> Dear all,
>>
>> is it possible to replace URIs in a store, similar to the approach in
>> example 5 given here: http://www.w3.org/TR/sparql11-update/#deleteInsert ?
>>
>> The catch is that I don't want to replace single URIs, but all URIs in a
>> certain namespace. Say I have
>>
>> http://some.domain.org/myClassA
>> http://some.domain.org/myClassB
>> http://some.domain.org/myPropertyA
>> http://some.domain.org/myPropertyB
>> etc.
>>
>> and I want to change them all to
>>
>> http://another.domain.org/myClassA
>> http://another.domain.org/myClassB
>> http://another.domain.org/myPropertyA
>> http://another.domain.org/myPropertyB
>> etc.
>>
>> Finding the URIs to replace via FILTER and regex is no problem, but I'm
>> wondering whether there is a way to make sure that the
>> class/property-specific parts of the URIs are maintained and copied over
>> to the new URIs?
>>
>> Any ideas appreciated!
>
>
> This (virtually untested) update will convert namespaces for subject URIs:
>
> DELETE { ?s ?p ?o  }
> INSERT { ?s1 ?p ?o  }
> WHERE
> {
>    { SELECT (uri(concat("http://another.domain.org/",
>                          SUBSTR(str(?s),24)) )
>              AS ?s1)
>     {
>       ?s ?p ?o .
>       FILTER regex(str(?s), "^http://some.domain.org/")
>     }}
> }

You could also strstarts as a replacement for regex here, although it
will not necessarily be any more efficient than a regex that starts
with "^".

> it finds the URIs starting with http://some.domain.org/, then calculates a
> replacement by string bashing.
>
> Repeat for objects.

And predicates possibly...

If you are using Sesame you may be able to reuse my URITranslator
implementation in SesameTools [1]

Cheers,

Peter

[1] https://github.com/ansell/sesametools/blob/develop/uritranslator/src/main/java/net/fortytwo/sesametools/URITranslator.java

Received on Friday, 17 August 2012 21:05:03 UTC