3

I use the jena fuseki 2 docker image to create a fuseki server.

And I want to know if there is a way to upload my dataset to fuseki not from the web interface but programmatically, from SPARQL or Python or whatever else.

And also, is there a way to work with ontology from webprotégé directly from fuseki? Thanks for your answer

3 Answers 3

2

Fuseki comes with an HTTP API that can be used to upload data. You could use CURL or a Python HTTP library to communicate with this API. Fuseki also includes command-line helper scripts that can be used for calling the HTTP API. See https://jena.apache.org/documentation/fuseki2/soh.html#soh-sparql-http for more details.

8
  • Thank you for your answer. Please, can you show me an example of how to use python with HTTP API of fuseki to upload my dataset?
    – mee
    Feb 6, 2019 at 11:47
  • @mee just load the file as stream which makes the HTTP content body and use HTTP PUT as request type. And then indeed the appropriate request URI made of dataset and graph name. Feb 7, 2019 at 7:46
  • I tried this with no success: with open('pizza.owl', 'rb') as f: response=requests.put(http://localhost:3030/mydataset/update, data=f, stream=True)
    – mee
    Feb 7, 2019 at 14:00
  • If I understand the documentation correctly, you probably need to PUT to either http://localhost:3030/mydataset/data or http://localhost:3030/mydataset/data?default. That would use the SPARQL Graph Store Protocol (w3.org/2012/01/http-rdf-update), which (with a PUT-call) replaces the entire dataset. If you want to use the /update endpoint, which only adds/updates the given triples, you probably need to use POST as the HTTP method. Feb 7, 2019 at 14:58
  • 1
    I tried http://localhost:3030/mydataset/data as url in my put method and got response[400], and when I look at my container logs, I find this: PUT http://localhost:3030/mydataset/data , PUT /mydataset :: 'data' :: [multipart/form-data] ?, 400 Only files accepted in multipart file upload (got fileName=pizza.owl).
    – mee
    Feb 8, 2019 at 8:36
2

If your RDF data is in turtle format, you can use the following code:

data = open('test.ttl').read()
headers = {'Content-Type': 'text/turtle;charset=utf-8'}
r = requests.post('http://localhost:3030/mydataset/data?default', data=data, headers=headers)

If your RDF data are in other format, you should change your headers, here is a list:

n3: text/n3; charset=utf-8
nt: text/plain
rdf: application/rdf+xml
owl: application/rdf+xml
nq: application/n-quads
trig: application/trig
jsonld: application/ld+json
2

I tried to upload file to fuseki using CURL, WGET, ./s-post, ./s-put with no effect. I generated request with postman's help. If someone, like me, is looking for correct CURL request, this is it:

curl --location --request POST 'http://{FUSEKIADDRESS}/{YOURDATASET}/data' --header 'Content-Type: multipart/form-data' --form 'file.ttl=@{}PATHtoFILE/file.ttl'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.