0

I've been following the ARQ guide on Property Functions. The section on Graph Operations concludes with "New Triples or Graphs can therefore be created as part of the Property Function" and I've been hoping to use this as a means to add triples to the current query execution context (and not to persist), accessible for the remaining query.

I've been trying the code snippets in that section of the guide:

DatasetGraph datasetGraph = execCxt.getDataset();

Node otherGraphNode = NodeFactory.createURI("http://example.org/otherGraph");

Graph newGraph = new SimpleGraphMaker().createGraph();

Triple triple = ...
newGraph.add(triple);

datasetGraph.addGraph(otherGraphNode, newGraph);

but I'm running into issues, seemingly with the read-lock.

org.apache.jena.dboe.transaction.txn.TransactionException: Can't become a write transaction
at org.apache.jena.dboe.transaction.txn.Transaction.ensureWriteTxn(Transaction.java:251) ~[fuseki-server.jar:4.2.0]
at org.apache.jena.tdb2.store.StorageTDB.ensureWriteTxn(StorageTDB.java:200) ~[fuseki-server.jar:4.2.0]
at org.apache.jena.tdb2.store.StorageTDB.add(StorageTDB.java:81) ~[fuseki-server.jar:4.2.0]
at org.apache.jena.dboe.storage.system.DatasetGraphStorage.add(DatasetGraphStorage.java:181) ~[fuseki-server.jar:4.2.0]
at org.apache.jena.dboe.storage.system.DatasetGraphStorage.lambda$addGraph$1(DatasetGraphStorage.java:194) ~[fuseki-server.jar:4.2.0]

Is there any way to add triples to the execution context during a SPARQL query?

InSilico
  • 213
  • 2
  • 7
  • Put the whole execution inside a write transaction or a "promote" transaction. BTW Changing the dataset while running a query is not really a good idea for TDB2 while it is possible for a general purpose dataset. That documentation needs revising. – AndyS Sep 26 '21 at 08:36

1 Answers1

0

Yes, and SPARQL Anything uses that capability to triplify non-RDF data at query time and makes it available in the execution context's DatasetGraph.

Here is an example of that being done:

                if (this.execCxt.getDataset().isEmpty()) {
                // we only need to call getDatasetGraph() if we have an empty one
                // otherwise we could triplify the same data multiple times
                dg = getDatasetGraph(p, opBGP);
            } else {
                dg = this.execCxt.getDataset();
            }

These lines

This answer might not address your particular need (adding individual triples) but hopefully some of code in the project could serve as an example of what you are looking for.

justin2004
  • 75
  • 5