A better approach may be to use RDFConnection.
It has all the SPARQL operation including "send model"
Andy
On 25/09/2019 14:09, Andy Seaborne wrote:
INSERT DATA does not take quads directly.
The form is
INSERT DATA { GRAPH <graph> { triples } }
What *may* work is using Trig to insert.
Andy
On 25/09/2019 12:06, Mark Hissink Muller wrote:
Hi all,
I encounter a strange QueryParseException when building my
UpdateRequest to add a named model remotely from my Java client
application.
I've progressed since my last question regarding inserts to a remote
repository [1]. Thanks again Andy and Claude for your kind
suggestions. Among other, I've understood that data insert calls
should be directed at
"http://[servername]/rdf4j-server/repositories/[repo_name]/statements". I've
learned that a model should be serialized in NQUADS format into the
request and that TURTLE does not work. Based on this, calling the
server works well for dropping graphs and for inserting _unnamed_ models.
However, I am unable to insert data for a _named_ model/graph
remotely. My approach - which fails when adding the serialized model
to the UpdateRequest - is as follows.
...
// prepare the model we would like to load
Model model = prepareModel(..);
// create a dataset and add the model to it with a proper context
Dataset dataset = dataset = DatasetFactory.create();
dataset.addNamedModel(modelNameUri, model);
// serialise the dataset to an outputStream in NQUADS format
RDFDataMgr.write(outputStream, dataset, RDFFormat.NQUADS);
// build the full request by adding the prefix, the outputStream
and the suffix
String insertDataRequest = "INSERT DATA { " +
outputStream.toString() + "}";
UpdateRequest updateRequest =
UpdateFactory.create(insertDataRequest);
// create the processor and fire off the request
UpdateProcessor updateProcessor =
UpdateExecutionFactory.createRemoteForm(updateRequest, postUrl);
updateProcessor.execute();
...
This code fails down in the UpdateFactory where a QueryParseException
is thrown that tells that the fourth element (which is the model name
/ modelNameUri) is not expected. Strange thing is that the serialized
NQUADS look ok.
When using an alternative approach and trying to build an request with
an UpdateBuilder (as Claude suggested), I don't see how I can set the
model name/uri for the model. It should be possible to add this either
at creation or afterwards (rather than with every added triple), I
presume…?
What is the recommended approach to add a named model...? Are there
perhaps any examples...?
Much appreciated.
Best, Mark
[1] - https://jena.markmail.org/message/oxf5ff4bus67iim4