Juan
I haven't tested this but in principal the following should work:
DELETE
{
?s ?p ?o
}
WHERE
{
{
# Find things directly connected to the root
<root> ?p ?o .
BIND(<root> AS ?s)
}
UNION
{
# Find everything indirectly connected to the root
<root> (<>|!<>)+ ?s .
?s ?p ?o .
}
}
In the first branch simply select any triples directly off of the root.
In the second branch find any triples one/more steps away from the root
and the associated triples. Then in the DELETE template simply delete all
the matched triples.
The second branch uses Joshua Taylor's trick from
http://stackoverflow.com/a/26707541/107591 of using a property path via a
URI and its negation to find any subject that is reachable by 1 or more
steps via any property from your root. You can then simply grab things
that are directly connected to that subject.
This will probably perform badly and can be sped up if you have a specific
property used to denote the tree hierarchy. For example if the root is
linked to child nodes via the property :child then we could rewrite the
second branch as follows:
<root> :child+ ?s .
?s ?p ?o .
Which still requires a property path but will perform better because the
path is simpler.
Rob
On 09/11/2015 15:32, "Charles Greer" <[email protected]> wrote:
>Hi Juan,
>
>Seems that if you can do this efficiently
>
>"Another thought is to put the RDF graph in a NG and then just clear the
>NG."
>
>then that will be more efficient than following property paths.
>
>Interesting question to be sure.
>
>Charles
>
>
>________________________________________
>From: Juan Sequeda [[email protected]]
>Sent: Monday, November 09, 2015 3:28 PM
>To: [email protected]
>Subject: Deleting an entire RDF graph
>
>All,
>
>Assume I have an RDF graph which is a tree, hence there is a root node.
>What is the best way of deleting that entire RDF graph given the root
>node?
>
>Is there a way to do it with Property paths? And if so, I guess I would
>have to have knowledge of the structure of the graph/tree?
>
>Another thought is to put the RDF graph in a NG and then just clear the
>NG.
>
>Thoughts?
>
>Thanks,
>
>Juan