Overview

Notes on how to register and delete RDF files in Virtuoso RDF store using curl and Python.

The following was used as a reference.

https://vos.openlinksw.com/owiki/wiki/VOS/VirtRDFInsert#HTTP PUT

curl

As described on the above page. First, create myfoaf.rdf as sample data for registration.

<rdf:RDF xmlns:foaf="http://xmlns.com/foaf/0.1/">
    <foaf:Person rdf:about="http://www.example.com/people/中村覚">
        <foaf:name>中村覚</foaf:name>
    </foaf:Person>
</rdf:RDF>

Next, execute the following command.

curl -T ${filename1} ${endpoint}/DAV/home/${user}/rdf_sink/${filename2} -u ${user}:${passwd}

A specific example is as follows.

curl -T myfoaf.rdf http://localhost:8890/DAV/home/dba/rdf_sink/myfoaf.rdf -u dba:dba

Python

Here is an execution example. The following uses rdflib to create the RDF file from scratch. Also, by setting the action to delete, you can perform deletion.

import requests
from rdflib import Graph, URIRef, Literal
from rdflib.namespace import FOAF

filename = "myfoaf.rdf"
endpoint = "http://locahost:8890"
user = "dba"
passwd = "dba"
action = "create"
# action = "delete"

#####

# Create RDF data

g = Graph()

s = URIRef("http://example.org/people/中村覚")

name = Literal("中村覚")
g.add((s, FOAF.name, name))

# Save to file

g.serialize(destination=filename, format="xml")

data = open(filename,'r', encoding='utf-8')
data = data.read().encode()

# Registration

url = f"{endpoint}/DAV/home/{user}/rdf_sink/{filename}"

if action == "create":
    response = requests.put(url, data=data, auth=(user, passwd))
elif action == "delete":
    response = requests.delete(url, auth=(user, passwd))

print(response.status_code)

Summary

There may be other methods, but I hope this serves as a useful reference.