Virtuoso SPARQL 1.1. ADD Usage Examples

What?

This guide contains Virtuoso SPARQL 1.1. ADD 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 operations.

Why?

Use as shortcut for inserting all data from an input graph into a destination graph. Note that the original content in the destination graph if any, is kept intact.

How?

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

ADD Example

This example adds all triples from a named graph identified by the IRI <urn:sparql:tests:add:data> to a named graph identified by the IRI <urn:sparql:tests:add2:data>

  1. Assume the following Raw Data Representation in Turtle:

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

  2. Load the sample data into <urn:sparql:tests:add:data>:

    INSERT DATA { GRAPH <urn:sparql:tests:add:data> { <http://example/william> a <http://xmlns.com/foaf/0.1/Person> ; <http://xmlns.com/foaf/0.1/givenName> "William" ; <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . } }

  3. Query graph <urn:sparql:tests:add:data> data:

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

  4. Assume the following Raw Data Representation in Turtle:

    <http://example/fred> a <http://xmlns.com/foaf/0.1/Person> .

  5. Load the sample data into <urn:sparql:tests:add2:data>:

    INSERT DATA { GRAPH <urn:sparql:tests:add2:data> { <http://example/fred> a <http://xmlns.com/foaf/0.1/Person> . } }

  6. Query graph <urn:sparql:tests:add2:data> data:

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

  7. Add all triples from <urn:sparql:tests:add:data> to <urn:sparql:tests:add2:data>

    ADD GRAPH <urn:sparql:tests:add:data> TO <urn:sparql:tests:add2:data>;

  8. Equivalent variant is:

    INSERT { GRAPH <urn:sparql:tests:add2:data> { ?s ?p ?o } } WHERE { GRAPH <urn:sparql:tests:add:data> { ?s ?p ?o } }

  9. Query graph <urn:sparql:tests:add2:data> data: Note that the original content in <urn:sparql:tests:add2:data> is kept intact by the ADD operation:

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

Related