user1259487
user1259487

Reputation: 101

sparql query to delete

I am writing a sparql query in java to delete rdf data with a specific id. I am trying with

Delete ?ID ?name Where { 
     ?ID rdf:type ex:example ex:name ?name 
     FILTER(?ID ="something") 
}

but it doesn't do anything. Does anyone knows what is my mistake?

Upvotes: 7

Views: 21349

Answers (2)

Robin Keskisarkka
Robin Keskisarkka

Reputation: 896

The RDF representation means that we can only do deletes by removing (sub-) graphs. Any attempt at removing the equivalent of fields in a SELECT query will result in errors. Additionally, there are multiple forms of the DELETE query as can be seen in the SPARQL 1.1 Update specification. Another problem with the query in the question is that the DELETE format used is a shortcut for when the WHERE clause is used to define the triples that will be deleted, but the filter messes up the shortcut. Using the full DELETE syntax should work just fine:

PREFIX ex: <http://example.org#>
DELETE {
   ?id a ex:Example ;
       ex:name ?name .
}
WHERE { 
  ?id a ex:Example ;
      ex:name ?name .
  FILTER(str(?id) != "something") 
}

Upvotes: 5

Manuel Salvadores
Manuel Salvadores

Reputation: 16525

That query is probably failing, the closer SPARQL query that might work is ...

DELETE WHERE { 
     ?id rdf:type ex:example;
         ex:name ?name .
     FILTER(?id = <http://foo.com/some/example/uri>) 
}

The var ?id cannot be a string since it is positioned as a subject and in RDF all subjects are IRIs, not literals.

If you post some sample data we might be able to help better.

Upvotes: 7

Related Questions