> final Dataset d = TDBFactory.createDataset();
> Node n = Node.createURI("urn:graph");
> d.addGraph(n, GraphFactory.createDefaultGraph());

(sorry for the delay replying)

I'm afraid that isn't going to work.  I suspect it should be an error.

A TDB dataset is a triples+quad store. You can't add an in-memory storage-backed graph to a dataset backed by TDB.

If you want a mixe dataset, you can create an in-memory dataset and add in TDB backed graphs.

        Andy

On 28/11/12 20:32, Dick Murray wrote:
Hi all.

I have an issue where triples which are added to a graph which has been
added to a dataset are not visible in the dataset.

However if I add the graph then add quads to the dataset with the quad
graph node as the node used to add the graph the quads are visible.

Is this expected?

e.g.

Node n = Node.createURI("urn:graph");
d.addGraph(n, GraphFactory.createDefaultGraph());
d.add(new Quad(n, s, p, o);

Via the debug the graph has the triple but the dataset doesn't. (The
dataset doesn't see the graph because the triple is not visible..?)

The following code results in this output;

20:16:31 INFO  U4Dataset            :: t = urn:gs @urn:gp urn:go
20:16:31 INFO  U4Dataset            :: via graph 0
20:16:32 INFO  U4Dataset            :: q = [urn:dataset urn:ds urn:dp
urn:do]
20:16:32 INFO  U4Dataset            :: via dataset 1
<urn:ds>
       <urn:dp> <urn:do> .

I would expect to also see the triple;

<urn:gs>
       <urn:gp> <urn:so> .


public class U4Dataset {


     static private final Logger logger = Logger.getLogger(U4Dataset.class);

     static public void main(String[] args) {
         new U4Dataset().go();
     }

     final Dataset d = TDBFactory.createDataset();

     final DatasetGraph dg = d.asDatasetGraph();

     protected void go() {
         viaGraph("urn:graph");
         viaDataset("urn:dataset");
     }

     protected void viaGraph(String uri) {
         final Node n = Node.createURI(uri);

         d.begin(ReadWrite.WRITE);

         Graph g = GraphFactory.createDefaultGraph();
         dg.addGraph(n, g);

         final Node s = Node.createURI("urn:gs");
         final Node p = Node.createURI("urn:gp");
         final Node o = Node.createURI("urn:go");

         final Triple t = new Triple(s, p, o);
         logger.info(String.format("t = %s", t.toString()));
         g.add(t);

         d.commit();

         d.begin(ReadWrite.READ);

         logger.info(String.format("via graph %s", dg.size()));
         query("urn:x-arq:UnionGraph");

         d.end();
     }

     protected void viaDataset(String uri) {
         final Node n = Node.createURI(uri);

         d.begin(ReadWrite.WRITE);

         Graph g = GraphFactory.createDefaultGraph();
         dg.addGraph(n, g);

         final Node s = Node.createURI("urn:ds");
         final Node p = Node.createURI("urn:dp");
         final Node o = Node.createURI("urn:do");

         final Quad q = new Quad(n, s, p, o);
         logger.info(String.format("q = %s", q.toString()));
         dg.add(q);

         d.commit();

         d.begin(ReadWrite.READ);

         logger.info(String.format("via dataset %s", dg.size()));
         query("urn:x-arq:UnionGraph");

         d.end();
     }

     protected void query(String graphIRI) {
         Query query = QueryFactory.create(String.format("construct {?s ?p
?o} from <%s> where {?s ?p ?o}", graphIRI)) ;
         QueryExecution qExec = QueryExecutionFactory.create(query, d) ;
         Model model = ModelFactory.createDefaultModel();
         qExec.execConstruct(model);
         model.write(System.out, "Turtle") ;
         qExec.close() ;
     }

}


Reply via email to