Virtuoso SPARQL 1.1. DELETE Usage Examples

What?

This guide contains Virtuoso SPARQL 1.1. DELETE Usage examples queries which you can run against any SPARQL endpoint that supports SPARQL 1.1 and the ability to allow a verified user perform INSERT/DELETE operations.

Note: There should be either DELETE WHERE OR DELETE DATA but not both DATA and WHERE in same sequence.

Why?

Using DELETE to manage graphs data.

How?

Here are some examples showcasing Virtuoso's support for this functionality:

DELETE DATA Examples

Removing Triples from a Graph Example

This example request describes 2 triples to be removed from the named graph identified by the IRI <urn:sparql:tests:delete:data>

  1. Assume the following Raw Data Representation in Turtle:

    <#book2> <http://example.org/ns#price> 42 . <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" . <#book2> <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" .

  2. Load the sample data:

    INSERT DATA { GRAPH <urn:sparql:tests:delete:data> { <#book2> <http://example.org/ns#price> 42 . <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" . <#book2> <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" . } }

  3. Delete 2 triples from the graph:

    DELETE DATA FROM <urn:sparql:tests:delete:data> { <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" ; <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" . }

  4. Query the graph data:

    SELECT * FROM <urn:sparql:tests:delete:data> WHERE { ?s ?p ?o }

  5. View the SPARQL Query Definition via SPARQL Protocol URL;
  6. View the SPARQL Query Results via SPARQL Protocol URL

DELETE WHERE Examples

Removing Triples from a Graph Example

This example request removes all statements about anything with a given name of "Fred" from the named graph identified by the IRI <urn:sparql:tests:delete:where> :

  1. Assume the following Raw Data Representation in Turtle:

    <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/foaf/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> .

  2. Load the sample data:

    INSERT DATA { GRAPH <urn:sparql:tests:delete:where> { <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/foaf/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . } }

  3. Delete all statements about anything with a given name of "Fred" from the graph. A WITH clause is present, meaning that graph <urn:sparql:tests:delete:where> is both the one from which triples are being removed and the one which the WHERE clause is matched against:

    WITH <urn:sparql:tests:delete:where> DELETE { ?person ?property ?value } WHERE { ?person ?property ?value ; <http://xmlns.com/foaf/0.1/givenName> "Fred" }

  4. Query the graph data:

    SELECT * FROM <urn:sparql:tests:delete:where> WHERE { ?s ?p ?o }

  5. View the SPARQL Query Definition via SPARQL Protocol URL;
  6. View the SPARQL Query Results via SPARQL Protocol URL

Removing Triples in 2 graphs that have corresponding triples Example

This example request removes both statements naming some resource "Fred" in the graph <urn:sparql:tests:delete:where1> , and also statements about that resource from the graph <urn:sparql:tests:delete:where2> (assuming that some of the resources in the graph <urn:sparql:tests:delete:where1> have corresponding triples in the graph <urn:sparql:tests:delete:where2>).

  1. Assume the following Raw Data Representation in Turtle:

    <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" .

  2. Load the sample data:

    INSERT DATA { GRAPH <urn:sparql:tests:delete:where1> { <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . } }

  3. Assume another Raw Data Representation in Turtle:

    <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> .

  4. Load the sample data:

    INSERT DATA { GRAPH <urn:sparql:tests:delete:where2> { <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . } }

  5. Remove statements naming some resource "Fred" in the graph <urn:sparql:tests:delete:where1> , and also statements about that resource from the graph <urn:sparql:tests:delete:where2> :

    DELETE WHERE { GRAPH <urn:sparql:tests:delete:where1> { ?person <http://xmlns.com/foaf/0.1/givenName> 'Fred' ; ?property1 ?value1 . } GRAPH <urn:sparql:tests:delete:where2> { ?person ?property2 ?value2 . } }

  6. Query the graph <urn:sparql:tests:delete:where1> data:

    SELECT * FROM <urn:sparql:tests:delete:where1> WHERE { ?s ?p ?o }

  7. View the SPARQL Query Definition via SPARQL Protocol URL;
  8. View the SPARQL Query Results via SPARQL Protocol URL
  9. Query the graph <urn:sparql:tests:delete:where2> data:

    SELECT * FROM <urn:sparql:tests:delete:where2> WHERE { ?s ?p ?o }

  10. View the SPARQL Query Definition via SPARQL Protocol URL;
  11. View the SPARQL Query Results via SPARQL Protocol URL

DELETE (Informative) Examples

Remove Triples from graph about anything with given name "Fred"

This example request removes all statements about anything with a given name of "Fred" from the graph <urn:sparql:tests:delete:informative> . A WITH clause is present, meaning that graph <urn:sparql:tests:delete:informative> is both the one from which triples are being removed and the one which the WHERE clause is matched against:

  1. Assume the following Raw Data Representation in Turtle:

    <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> .

  2. Load the sample data:

    INSERT DATA { GRAPH <urn:sparql:tests:delete:informative> { <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . } }

  3. Remove all statements about anything with a given name of "Fred":

    WITH <urn:sparql:tests:delete:informative> DELETE { ?person ?property ?value } WHERE { ?person ?property ?value ; <http://xmlns.com/foaf/0.1/givenName> 'Fred' }

  4. Query the graph <urn:sparql:tests:delete:informative> data:

    SELECT * FROM <urn:sparql:tests:delete:informative> WHERE { ?s ?p ?o }

  5. View the SPARQL Query Definition via SPARQL Protocol URL;
  6. View the SPARQL Query Results via SPARQL Protocol URL

Related