Sparql query delete all statements

2019-07-16 14:15发布

问题:

I would like to delete all statements related to an object that contains certain characters in the label. I am using the query:

DELETE
{?term ?p ?o}
WHERE
{
?term rdfs:label ?label.
FILTER(regex(?label, "xx", "i"))
?term ?p ?o.
}

However, this query seems to fail to delete all the statements that contain the subject of this statement as object. Then I seem to need another query.

DELETE
{?s ?p ?term}
WHERE
{
?term rdfs:label ?label.
FILTER(regex(?label, "xx", "i"))
?s ?p ?term.
}

The SELECT * does not seem to work for DELETE, and I have also tried to model a UNION within DELETE with no success. Could you please point me to the solution? Many thanks.

回答1:

try this. it worked for me both for insert and delete

DELETE
{?term ?p ?o}
WHERE
{
 SELECT ?term ?p ?o
 WHERE{
   ?term rdfs:label ?label.
   FILTER(regex(?label, "xx", "i"))
 }
}


标签: sparql