sparql query to delete
Asked Answered
E

2

7

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?

Epos answered 14/3, 2012 at 16:1 Comment(0)
P
7

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.

Papaverine answered 14/3, 2012 at 19:9 Comment(4)
i think that the problem is with sparql update because i get the error Encountered " "delete" "DELETE "" at line 6, column 1. Was expecting one of: "prefix" ... "select" ... "construct" ... "describe" ... "ask" ... Do you know if i can do anything to run a delete query?Epos
which triple store are you using ?Papaverine
The error message is related to the differences between SPARQL query and SPARQL update. They are represented using different classes in Jena (which I would guess is what you are using) and they are usually exposed as different endpoint URL:s. These are not compatible by design, hence the error.Cube
The query is, as far as I know, not valid. The filter prevents the DELETE shortcut from working. Perhaps this is implementation specific though, but that's what I gather from the specs (w3.org/TR/sparql11-update) at least.Cube
C
5

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") 
}
Cube answered 15/5, 2017 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.