I am currently working on integrating with ontotext's GraphDB using their RDF4J API.
I am trying to insert and replace large sets of statements, ideally in one go. I am currently doing this on my Fuseki instance (which I'm migrating away from) by creating this block for every triple I want to insert into my Graph (currently only using default graph) and submitting that as one update
call using semi-colons to separate the statements (where that is going into the post
body);
delete { <x:test> <y:name> ?o }
insert { <x:test> <y:name> "Test" }
where { optional{ <x:test> <y:name> ?o }};
delete { <x:test> <y:description> ?o }
insert { <x:test> <y:description> "Test" }
where { optional{ <x:test> <y:description> ?o }};
delete { <x:test2> <y:name> ?o }
insert { <x:test2> <y:name> "Test" }
where { optional{ <x:test2> <y:name> ?o }};
I have been looking at the API and as far as I can work out Statement Post Method (POST /repositories/{repositoryID}/statement
) only allows a SPARQL 1.1 Update string like that in the query parameter called update
.
This means I would end up appending thousands of these blocks of SPARQL onto the query parameter which really doesn't feel right.
Am I missing something with how you update statements in GraphDB? Is there a better strategy I should be following?
After a play around I've created the following which seems to work however I can't say whether or not it would be considered a good way of doing it;
DELETE {
<x:test> ?p ?o
}
WHERE {
<x:test> ?p ?o .
VALUES (?p) {
(<y:name>)
(<y:description>)
}
};
INSERT DATA {
<x:test> <y:name> "New Name" .
<x:test> <y:description> "New Description" .
}
Any help would be greatly appreciated.
Many Thanks, John
You can sequence multiple SPARQL updates together using a semicolon, ";
". For example:
delete { <x:test1> <y:name> ?o }
insert { <x:test1> <y:name> "Test 1" }
where { <x:test1> <y:name> ?o }};
delete { <x:test2> <y:name> ?o }
insert { <x:test2> <y:name> "Test 2" }
where { <x:test2> <y:name> ?o }
Just send such a sequence string to the update endpoint and it will be executed in one go.
As for whether this is the most efficient way to do it, that's a different matter. Do the statements that you are trying to replace share any characteristics? If so, it might be possible to express the update in a single query, rather than a sequence for each triple / subject.