You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Gary King <gw...@metabang.com> on 2012/07/25 21:14:36 UTC

a question about graphs, datasets and SPARQL Update

Hi all,

Not sure if this is the correct/best list but I'm trying to understand the graph handling of SPARQL Update. 

Consider this statement evaluated under ARQ 2.9

PREFIX : <http://ex#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

insert data { graph <http://graph1> { <http://ex#a> <http://ex#name> "Meaghan" . }} ;

insert data { graph <http://graph2> { <http://ex#b> <http://ex#name> "Gary" . }} ;

DELETE { ?x :name ?y }
INSERT {?x rdfs:label ?y }
USING <http://graph1>
USING <http://graph2>
WHERE { ?x :name ?y }

from this command line

bin/update --verbose --update=query.rq --dump

 gets this output

<http://ex#b> <http://www.w3.org/2001/RDFSchema#label> "Gary" .
<http://ex#a> <http://www.w3.org/2001/RDFSchema#label> "Meaghan" .
<http://ex#a> <http://ex#name> "Meaghan" <http://graph1> .
<http://ex#b> <http://ex#name> "Gary" <http://graph2> .

I.e., we found the triples in the WHERE part but they "lost" their graphs and so the DELETE didn't delete them and the insert put them in the default graph. This makes sense to me and is what I would expect.

but consider this similar query which removes the USING clauses:

PREFIX : <http://ex#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

insert data { graph <http://graph1> { <http://ex#a> <http://ex#name> "Meaghan" . }} ;

insert data { graph <http://graph2> { <http://ex#b> <http://ex#name> "Gary" . }} ;

DELETE { ?x :name ?y }
INSERT {?x rdfs:label ?y }
WHERE { ?x :name ?y }

Now we get

<http://ex#a> <http://ex#name> "Meaghan" <http://graph1> .
<http://ex#b> <http://ex#name> "Gary" <http://graph2> .

So the WHERE clause found the triples, they retained their individual graphs and so the DELETE and INSERT found them as well. What is the rational for that?

thanks,
--
Gary Warren King, metabang.com 
Cell: (413) 559 8738
Fax: (206) 338-4052
gwkkwg on Skype * garethsan on AIM * gwking on twitter


Re: a question about graphs, datasets and SPARQL Update

Posted by Gary King <gw...@metabang.com>.
Hi Rob,

Thanks. Your explanation is very clear.

> Without the USING clauses you are querying the unnamed graph (aka the
> default graph) with your WHERE clause which in your example is empty.
> This means there are no results from the WHERE clause so the DELETE and
> INSERT has nothing to do so the result you get is just the data you
> created with your INSERT DATA statements.


Whoopts; I should my own e-mails more carefully. I actually mis-read (or failed to read) the output of the second query and thought that it had (in effect) changed name to label. Given that it hadn't, my question goes away.

off to clean my glasses. :-)
--
Gary Warren King, metabang.com 
Cell: (413) 559 8738
Fax: (206) 338-4052
gwkkwg on Skype * garethsan on AIM * gwking on twitter


Re: a question about graphs, datasets and SPARQL Update

Posted by Rob Vesse <rv...@yarcdata.com>.
Hi Gary


Comments inline

On 7/25/12 12:14 PM, "Gary King" <gw...@metabang.com> wrote:

>Hi all,
>
>Not sure if this is the correct/best list but I'm trying to understand
>the graph handling of SPARQL Update.
>
>Consider this statement evaluated under ARQ 2.9
>
>PREFIX : <http://ex#>
>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
>
>insert data { graph <http://graph1> { <http://ex#a> <http://ex#name>
>"Meaghan" . }} ;
>
>insert data { graph <http://graph2> { <http://ex#b> <http://ex#name>
>"Gary" . }} ;
>
>DELETE { ?x :name ?y }
>INSERT {?x rdfs:label ?y }
>USING <http://graph1>
>USING <http://graph2>
>WHERE { ?x :name ?y }
>
>from this command line
>
>bin/update --verbose --update=query.rq --dump
>
> gets this output
>
><http://ex#b> <http://www.w3.org/2001/RDFSchema#label> "Gary" .
><http://ex#a> <http://www.w3.org/2001/RDFSchema#label> "Meaghan" .
><http://ex#a> <http://ex#name> "Meaghan" <http://graph1> .
><http://ex#b> <http://ex#name> "Gary" <http://graph2> .
>
>I.e., we found the triples in the WHERE part but they "lost" their graphs
>and so the DELETE didn't delete them and the insert put them in the
>default graph. This makes sense to me and is what I would expect.

The USING clauses control what graphs the WHERE clause treats as the
default graph and will use for parts of the WHERE clause that don't
explicitly specify a graph.  In this example the presence of the USING
clause allows the WHERE to match both the triples created by the INSERT
DATA commands.

Therefore your WHERE returns some results which are then fed into the
DELETE and INSERT and end up in the unnamed graph.

>
>but consider this similar query which removes the USING clauses:
>
>PREFIX : <http://ex#>
>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
>
>insert data { graph <http://graph1> { <http://ex#a> <http://ex#name>
>"Meaghan" . }} ;
>
>insert data { graph <http://graph2> { <http://ex#b> <http://ex#name>
>"Gary" . }} ;
>
>DELETE { ?x :name ?y }
>INSERT {?x rdfs:label ?y }
>WHERE { ?x :name ?y }
>
>Now we get
>
><http://ex#a> <http://ex#name> "Meaghan" <http://graph1> .
><http://ex#b> <http://ex#name> "Gary" <http://graph2> .
>
>So the WHERE clause found the triples, they retained their individual
>graphs and so the DELETE and INSERT found them as well. What is the
>rational for that?

Without the USING clauses you are querying the unnamed graph (aka the
default graph) with your WHERE clause which in your example is empty.
This means there are no results from the WHERE clause so the DELETE and
INSERT has nothing to do so the result you get is just the data you
created with your INSERT DATA statements.

Hope this helps

Rob

>
>thanks,
>--
>Gary Warren King, metabang.com
>Cell: (413) 559 8738
>Fax: (206) 338-4052
>gwkkwg on Skype * garethsan on AIM * gwking on twitter
>