You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "Cekov, Luchesar" <Lu...@nature.com> on 2013/06/11 14:42:38 UTC

Delete related triples across multiple graphs

Hi guys,

I have a problem with specific case of sparql delete statements. I have the feeling I am doing something wrong.

My case is having a tree like graph structure starting with a certain subject and having multiple levels. The triples for different levels could be in different named graphs. I want to create a query that deletes the whole my tree. A simplified case contains only two levels.

First level in graph1

INSERT DATA {
    GRAPH <http://graph1> {
        <http://s1> <http://p1> <http:/s2>
    }
};

Second level in graph2

INSERT DATA {
    GRAPH <http:graph2> {
        <http://s2> <http://p2> "literal1" .
        <http://s2> <http://p3> <http://url1> .
    }
};

I would like to delete the triples from the second graph and any graph actually as I don't know the name of the second graph. In my real application the second graph will contain many other triples but I want to delete only the triples from the second level of my tree.
I use this delete statement:
DELETE {
    GRAPH ?g {
        <http://s1> ?p1 ?o1.
        ?o1 ?p2 ?o2.
    }
} WHERE {
    GRAPH ?g {
        <http://s1> ?p1 ?o1.
        ?o1 ?p2 ?o2.
    }
};

Unfortunately this would not work. It behaves as if deletions are not seeing triples across different graphs.

If I put all the triples in the same graph the above delete query will work. I am enclosing a junit test case that demonstrates my issue. Can anybody give a hand please? Any explanations of why this could behave like that or workarounds are very welcome.

Many thanks,
Luchesar

********************************************************************************   
DISCLAIMER: This e-mail is confidential and should not be used by anyone who is
not the original intended recipient. If you have received this e-mail in error
please inform the sender and delete it from your mailbox or any other storage
mechanism. Neither Macmillan Publishers Limited nor any of its agents accept
liability for any statements made which are clearly the sender's own and not
expressly made on behalf of Macmillan Publishers Limited or one of its agents.
Please note that neither Macmillan Publishers Limited nor any of its agents
accept any responsibility for viruses that may be contained in this e-mail or
its attachments and it is your responsibility to scan the e-mail and 
attachments (if any). No contracts may be concluded on behalf of Macmillan 
Publishers Limited or its agents by means of e-mail communication. Macmillan 
Publishers Limited Registered in England and Wales with registered number 785998 
Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS   
********************************************************************************

Re: Delete related triples across multiple graphs

Posted by Andy Seaborne <an...@apache.org>.
Luchesar,

 > } WHERE {
 >      GRAPH ?g {
 >          <http://s1> ?p1 ?o1.
 >          ?o1 ?p2 ?o2.
 >      }

This forces matching in one graph:

Try something like:

      GRAPH ?g1 { <http://s1> ?p1 ?o1 }
      GRAPH ?g2 { ?o1 ?p2 ?o2. }

which allows the second triple to be in a different graph.

Tip: use DELETE WHERE for when the template and the WHERE pattern are 
the same quad matching:

DELETE WHERE {
      GRAPH ?g1 { <http://s1> ?p1 ?o1 }
      GRAPH ?g2 { ?o1 ?p2 ?o2. }
}


 > I am enclosing a junit test case that demonstrates my issue.

Attachements don't get through.  Trying using a pastebin somewhere and 
sending the link.

	Andy

On 11/06/13 13:42, Cekov, Luchesar wrote:
> Hi guys,
>
> I have a problem with specific case of sparql delete statements. I have
> the feeling I am doing something wrong.
>
> My case is having a tree like graph structure starting with a certain
> subject and having multiple levels. The triples for different levels
> could be in different named graphs. I want to create a query that
> deletes the whole my tree. A simplified case contains only two levels.
>
> First level in graph1
>
> INSERT DATA {
>      GRAPH <http://graph1> {
>          <http://s1> <http://p1> <http:/s2>
>      }
> };
>
> Second level in graph2
>
> INSERT DATA {
>      GRAPH <http:graph2> {
>          <http://s2> <http://p2> "literal1" .
>          <http://s2> <http://p3> <http://url1> .
>      }
> };
>
> I would like to delete the triples from the second graph and any graph
> actually as I don't know the name of the second graph. In my real
> application the second graph will contain many other triples but I want
> to delete only the triples from the second level of my tree.
> I use this delete statement:
> DELETE {
>      GRAPH ?g {
>          <http://s1> ?p1 ?o1.
>          ?o1 ?p2 ?o2.
>      }
> } WHERE {
>      GRAPH ?g {
>          <http://s1> ?p1 ?o1.
>          ?o1 ?p2 ?o2.
>      }
> };
>
> Unfortunately this would not work. It behaves as if deletions are not
> seeing triples across different graphs.
>
> If I put all the triples in the same graph the above delete query will
> work. I am enclosing a junit test case that demonstrates my issue. Can
> anybody give a hand please? Any explanations of why this could behave
> like that or workarounds are very welcome.
>
> Many thanks,
> Luchesar
>
>
> ********************************************************************************
>
> DISCLAIMER: This e-mail is confidential and should not be used by anyone
> who is
> not the original intended recipient. If you have received this e-mail in
> error
> please inform the sender and delete it from your mailbox or any other
> storage
> mechanism. Neither Macmillan Publishers Limited nor any of its agents accept
> liability for any statements made which are clearly the sender's own and not
> expressly made on behalf of Macmillan Publishers Limited or one of its
> agents.
> Please note that neither Macmillan Publishers Limited nor any of its agents
> accept any responsibility for viruses that may be contained in this
> e-mail or
> its attachments and it is your responsibility to scan the e-mail and
> attachments (if any). No contracts may be concluded on behalf of Macmillan
> Publishers Limited or its agents by means of e-mail communication.
> Macmillan
> Publishers Limited Registered in England and Wales with registered
> number 785998
> Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS
> ********************************************************************************
>