Re: Replacing URIs via SPARQL update

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/")
     }}
}

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

Repeat for objects.

	Andy

>
> Thanks,
> Carsten
>
> ---
> Carsten Keßler  | http://carsten.io
>
> Semantic Interoperability Lab | http://musil.uni-muenster.de
> Institute for Geoinformatics | http://ifgi.uni-muenster.de
> University of Münster | http://www.uni-muenster.de
>
>

Received on Friday, 17 August 2012 15:16:54 UTC