You are here:
/ Dashboard / Main / VirtRDFInsert

RDF Insert Methods in Virtuoso

RDF Sink Folders (Virtuoso or ODS-Briefcase)

HTTP Post using Content-Type: application/sparql-query

Theory

  1. With POST can be accomplished SPARQL Insert/Update etc.
  2. The result is in the rdf_quiad
  3. With GET Methods you can get the triples which are saved.

Simple Example 1

  1. Create a DAV collection and not to request for authentication set RW permissions for public. For ex. the collection path could be /DAV/xx
  2. Execute the following command:

    curl -i -d "INSERT {<s> <p> <o>}" -H "Content-Type: application/sparql-query" http://host:port/DAV/xx/yy

  3. The response should be:

    HTTP/1.1 201 Created Server: Virtuoso/05.00.3023 (Win32) i686-generic-win-32 VDB Connection: Keep-Alive Content-Type: text/html; charset=ISO-8859-1 Date: Fri, 28 Dec 2007 12:50:12 GMT Accept-Ranges: bytes MS-Author-Via: SPARQL Content-Length: 0

  4. As result in the DAV/xx location will be created a file with name "yy" and with the following content:
    1. if opened with Conductor:

      CONSTRUCT { ?s ?p ?o } FROM <http://host:port/DAV/xx/yy> WHERE { ?s ?p ?o }

    2. if opened with GET, then the content will be RDF representation of what was inserted into the graph, i.e.

      <?xml version="1.0" encoding="utf-8" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> <rdf:Description rdf:about="s"><p rdf:resource="o"/></rdf:Description> </rdf:RDF>

Simple Example 2

  1. Create a DAV collection, for ex. with name "test" for user ( for ex. demo).
  2. Execute the following command:

    curl -i -d "INSERT IN GRAPH <http://example/testrq> { <s1> <p1> <o1> . <s2> <p2> <o2> . <s3> <p3> <o3> } " -u "demo:demo" -H "Content-Type: application/sparql-query" http://host:port/DAV/home/demo/test/myrq

  3. As result the response will be:

    HTTP/1.1 201 Created Server: Virtuoso/05.00.3023 (Win32) i686-generic-win-32 VDB Connection: Keep-Alive Content-Type: text/html; charset=ISO-8859-1 Date: Thu, 20 Dec 2007 16:25:25 GMT Accept-Ranges: bytes MS-Author-Via: SPARQL Content-Length: 0

  4. Now let's check the inserted triples. Go to the sparql endpoint, i.e. http://host:port/sparql and:
    1. Enter for Default Graph URI:

      http://example/testrq

    2. Enter in the Query area:

      SELECT * WHERE {?s ?p ?o}

    3. Click the button "Run Query"
    4. As result will be shown the inserted triples:

      s p o s1 p1 o1 s2 p2 o2 s3 p3 o3

HTTP PUT

Theory

"the URI in a PUT request identifies the entity enclosed with the request" (1). Therefore using HTTP PUT is a more useful and meaningful command than using POST (which is more about submitting data to a script).

Simple Usage Example


File: myfoaf.rdf
Destination Server: demo.openlinksw.com

curl -T myfoaf.rdf http://demo.openlinksw.com/DAV/home/demo/rdf_sink/myfoaf.rdf

References

  1. HTTP/1.1 PUT
  2. Some Virtuoso PUT Documentation regarding Multipart Forms

SPARQL Insert using LOAD

SPARQL INSERT operation can be done using the LOAD feature.

Theory

Simple Example

  1. Execute from ISQL:

    sparql insert in graph <http://example/load> { <l1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#User> . <l1> <http://rdfs.org/sioc/ns#name> <test1> . <l2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#User> . <l2> <http://rdfs.org/sioc/ns#name> <test2> . <l3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#User> . <l3> <http://rdfs.org/sioc/ns#name> <test3> . <l4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#User> . <l4> <http://rdfs.org/sioc/ns#name> <demo> . };

  2. Create DAV collection which is visible to public, for ex: http://host:port/DAV/tmp
  3. Upload to the DAV collection the following file for ex. with name listall.rq:

    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX sioc: <http://rdfs.org/sioc/ns#> SELECT ?x ?p ?o FROM <http://example/load> WHERE { ?x rdf:type sioc:User . ?x ?p ?o. ?x sioc:name ?name . FILTER REGEX(str(?name), "^test") } ORDER BY ?x

  4. Now from ISQL execute the following command:

    sparql load bif:concat ("http://", bif:registry_get("URIQADefaultHost"), "/DAV/tmp/listall.rq") into graph <http://example/load2>;

  5. As result should be shown the message:

    callret-0 VARCHAR _______________________________________________________________________________ Load <http://rumi.ath.cx:8895/DAV/tmp/listall.rq> into graph <http://example/load2> -- done 1 Rows. -- 321 msec.

SPARQL Insert via /sparql endpoint

SPARQL INSERT operation can be sent to a web service endpoint as a single statement and executed in sequence.

Theory

Simple Example

Using the Virtuoso ISQL tool or using the /sparql UI at http://host:port/sparql, execute the following:

  1. Insert into graph http://example/bookStore 3 triples:

    sparql insert in graph <http://example/bookStore> { <s1> <http://purl.org/dc/elements/1.1/date> <1999-04-01T00:00:00> . <s2> <http://purl.org/dc/elements/1.1/date> <1998-05-03T00:00:00> . <s3> <http://purl.org/dc/elements/1.1/date> <2001-02-08T00:00:00> };

  2. As result will be shown the message:

    Insert into <http://example/bookStore>, 3 triples -- done

  3. Next we will select all triples from the graph http://example/bookStore:

    sparql select * from <http://example/bookStore> where {?s ?p ?o};

  4. As result will be shown:

    s p o VARCHAR VARCHAR VARCHAR _______________________________________________________________________ s1 http://purl.org/dc/elements/1.1/date 1999-04-01T00:00:00 s3 http://purl.org/dc/elements/1.1/date 2001-02-08T00:00:00 s2 http://purl.org/dc/elements/1.1/date 1998-05-03T00:00:00 3 Rows. -- 0 msec.

  5. Now let's insert into graph another graph http://example/bookStore2 values:

    sparql PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> INSERT INTO GRAPH <http://example/bookStore2> { ?book ?p ?v } WHERE { GRAPH <http://example/bookStore> { ?book dc:date ?date FILTER ( xsd:dateTime(?date) < xsd:dateTime("2000-01-01T00:00:00")). ?book ?p ?v. } };

  6. As result will be shown:

    callret-0 VARCHAR _______________________________________________________________________________ Insert into <http://example/bookStore2>, 2 triples -- done

  7. Finally we will check the triples from the graph http://example/bookStore2:

    SQL> sparql select * from <http://example/bookStore2> where {?s ?p ?o};

  8. As result will be shown:

    s p o VARCHAR VARCHAR VARCHAR _______________________________________________________________________ s1 http://purl.org/dc/elements/1.1/date 1999-04-01T00:00:00 s2 http://purl.org/dc/elements/1.1/date 1998-05-03T00:00:00 2 Rows. -- 20 msec.

References

SPARQL Insert via HTTP Post using Content-Type: application/sparql-query and ODS wiki

Theory

  • With HTTP Post and ODS wiki can be written an rdf document and respectively to be performed over it INSERT/UPDATE action.
  • You can write to a file using SIOC terms for ODS-Wiki
  • You can check with sparql the inserted / updated triples in the Quad Store.

Simple Example

  1. Suppose there is ODS user test3 with ODS password 1, which has testWiki wiki instance.
  2. Execute the following:

    curl -i -d "INSERT {<http://host:port/dataspace/test3/wiki/testWiki> <http://atomowl.org/ontologies/atomrdf#contains> <http://host:port/dataspace/test3/wiki/testWiki/MyTest> . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://rdfs.org/sioc/ns#has_container> <http://host:port/dataspace/test3/wiki/testWiki> . <http://host:port/dataspace/test3/wiki/testWiki> <http://atomowl.org/ontologies/atomrdf#entry> <http://host:port/dataspace/test3/wiki/testWiki/MyTest> . <http://host:port/dataspace/test3/wiki/testWiki> <http://rdfs.org/sioc/ns#container_of> <http://host:port/dataspace/test3/wiki/testWiki/MyTest> . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://rdfs.org/sioc/ns#topic> <http://host:port/dataspace/test3/wiki/testWiki> . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://atomowl.org/ontologies/atomrdf#source> <http://host:port/dataspace/test3/wiki/testWiki> . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/types#Comment> . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://atomowl.org/ontologies/atomrdf#Entry> . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://www.w3.org/2000/01/rdf-schema#label> 'MyTest' . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://atomowl.org/ontologies/atomrdf#Link> . <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://rdfs.org/sioc/ns#content> <test>}" -u "test3:1" -H "Content-Type: application/sparql-query" http://host:port/DAV/home/test3/wiki/testWiki/MyTest

  3. As result we should have 2 files created:
    1. In the user DAV folder "DAV/home/test3/wiki/testWiki/" will be created a file "MyTest?" with type "application/sparql-query".
      1. You can view the content of this file from from the Conductor UI or from the user's Briefcase UI, path "DAV/home/test3/wiki/testWiki":
      2. It content will be:

        <?xml version="1.0" encoding="utf-8" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki"><ns0pred:entry xmlns:ns0pred="http://atomowl.org/ontologies/atomrdf#" rdf:resource="http://host:port/dataspace/test3/wiki/testWiki/MyTest"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:label xmlns:ns0pred="http://www.w3.org/2000/01/rdf-schema#">MyTest</ns0pred:label></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:type xmlns:ns0pred="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://atomowl.org/ontologies/atomrdf#Link"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:type xmlns:ns0pred="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://rdfs.org/sioc/types#Comment"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:type xmlns:ns0pred="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://atomowl.org/ontologies/atomrdf#Entry"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:has_container xmlns:ns0pred="http://rdfs.org/sioc/ns#" rdf:resource="http://host:port/dataspace/test3/wiki/testWiki"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki"><ns0pred:container_of xmlns:ns0pred="http://rdfs.org/sioc/ns#" rdf:resource="http://host:port/dataspace/test3/wiki/testWiki/MyTest"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki"><ns0pred:contains xmlns:ns0pred="http://atomowl.org/ontologies/atomrdf#" rdf:resource="http://host:port/dataspace/test3/wiki/testWiki/MyTest"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:content xmlns:ns0pred="http://rdfs.org/sioc/ns#">test</ns0pred:content></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:topic xmlns:ns0pred="http://rdfs.org/sioc/ns#" rdf:resource="http://host:port/dataspace/test3/wiki/testWiki"/></rdf:Description> <rdf:Description rdf:about="http://host:port/dataspace/test3/wiki/testWiki/MyTest"><ns0pred:source xmlns:ns0pred="http://atomowl.org/ontologies/atomrdf#" rdf:resource="http://host:port/dataspace/test3/wiki/testWiki"/></rdf:Description> </rdf:RDF>

    2. To the user's wiki instance will be added a new WikiWord? "MyTest?" with content the value of the SIOC term attribue "content":

      <http://host:port/dataspace/test3/wiki/testWiki/MyTest> <http://rdfs.org/sioc/ns#content> <test> i.e. the content will be "test".

      1. You can view this filein path "DAV/home/test3/wiki/testWiki/" and its name will be "MyTest.txt".
      2. Using the ODS wiki UI you can:
        1. Go to Index link
        2. As result the MyTest? article will be shown in the given list. Click on its link.
        3. As result the content of the article will be shown.
  4. Now lets check what data was inserted in the Quad Store:
    1. Go to the sparql endpoint, i.e. to http://host:port/sparql
    2. Enter for Default Graph URI:

      http://host:port/DAV/home/test3/wiki/testWiki/MyTest

    3. Enter for Query text:

      SELECT * WHERE {?s ?p ?o}

    4. Click the "Run Query" button.
    5. As result will be shown the inserted triples:

      s p o http://host:port/dataspace/test3/wiki/testWiki http://rdfs.org/sioc/ns#container_of http://host:port/dataspace/test3/wiki/testWiki/MyTest http://host:port/dataspace/test3/wiki/testWiki http://atomowl.org/ontologies/atomrdf#entry http://host:port/dataspace/test3/wiki/testWiki/MyTest http://host:port/dataspace/test3/wiki/testWiki http://atomowl.org/ontologies/atomrdf#contains http://host:port/dataspace/test3/wiki/testWiki/MyTest http://host:port/dataspace/test3/wiki/testWiki/MyTest http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://rdfs.org/sioc/types#Comment http://host:port/dataspace/test3/wiki/testWiki/MyTest http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://atomowl.org/ontologies/atomrdf#Entry http://host:port/dataspace/test3/wiki/testWiki/MyTest http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://atomowl.org/ontologies/atomrdf#Link http://host:port/dataspace/test3/wiki/testWiki/MyTest http://www.w3.org/2000/01/rdf-schema#label MyTest http://host:port/dataspace/test3/wiki/testWiki/MyTest http://rdfs.org/sioc/ns#has_container http://host:port/dataspace/test3/wiki/testWiki http://host:port/dataspace/test3/wiki/testWiki/MyTest http://rdfs.org/sioc/ns#content test http://host:port/dataspace/test3/wiki/testWiki/MyTest http://rdfs.org/sioc/ns#topic http://host:port/dataspace/test3/wiki/testWiki http://host:port/dataspace/test3/wiki/testWiki/MyTest http://atomowl.org/ontologies/atomrdf#source http://host:port/dataspace/test3/wiki/testWiki

References

WebDAV (mount folder to DAV and dump; if this is the rdf_sink the Quad Store is updated automatically, or you can load from DAV manually to quad store)

Theory

Simple Example

References

Virtuoso Crawler (which includes the Sponger options so you crawl non-RDF but get RDF and this can go to the Quad Store)

Theory

Simple Example

References

SPARQL Query (i.e. we Sponge the Resources in the FROM Clause or values for the graph-uri paramater in SPARQL protocol URLs)

Theory

Simple Example

References

Virtuoso PL APIs

Theory

Simple Example

References

SIMILE RDF Bank API

Theory

Simple Example

References

RDF NET

Theory

Simple Example

References

Virtuoso and the Virtuoso Website are Copyright (C) OpenLink Software 2006-
SourceForge.net Logo