You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Dick Murray <da...@gmail.com> on 2012/11/28 21:32:39 UTC

Issue adding Triples to Graph which has been added to a DatasetGraph.

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() ;
    }

}

Re: Issue adding Triples to Graph which has been added to a DatasetGraph.

Posted by Dick Murray <da...@gmail.com>.
Thank you!

On 30 November 2012 12:48, Andy Seaborne <an...@apache.org> wrote:

> On 30/11/12 11:34, Dick Murray wrote:
>
>> Hi Andy.
>>
>> Thanks for the reply and just so I am sure I understand this... :-)
>>
>
> ...
>
>  So I need to add the graph (as a empty mem based graph) to the TDB backed
>> dataset then add quads to the dataset..?
>>
>> Dick.
>>
>
>
> In TDB graph just "are" - you don't need to create them explicitly, just
> start adding quads.
>
> A TDB-backed graph, if you get it from the dataset, is just a view of the
> database and has no separate state.
>
> You can get it (no need to create) add triples (or as a model, statements)
> and they become quads view the view.
>
> (You don't need CREATE GRAPH in SPARQL Update either - in fact, you don't
> need it anywhere any more IIRC)
>
>         Andy
>
>

Re: Issue adding Triples to Graph which has been added to a DatasetGraph.

Posted by Andy Seaborne <an...@apache.org>.
On 30/11/12 11:34, Dick Murray wrote:
> Hi Andy.
>
> Thanks for the reply and just so I am sure I understand this... :-)

...
> So I need to add the graph (as a empty mem based graph) to the TDB backed
> dataset then add quads to the dataset..?
>
> Dick.


In TDB graph just "are" - you don't need to create them explicitly, just 
start adding quads.

A TDB-backed graph, if you get it from the dataset, is just a view of 
the database and has no separate state.

You can get it (no need to create) add triples (or as a model, 
statements) and they become quads view the view.

(You don't need CREATE GRAPH in SPARQL Update either - in fact, you 
don't need it anywhere any more IIRC)

	Andy


Re: Issue adding Triples to Graph which has been added to a DatasetGraph.

Posted by Dick Murray <da...@gmail.com>.
Hi Andy.

Thanks for the reply and just so I am sure I understand this... :-)

Looking at the Jena code for a SPARUL create graph <urn:test> against a
folder backed TDB store it gives the following stack;

Daemon Thread [Thread-24] (Suspended)
    GraphMem(GraphMemBase).<init>(ReificationStyle) line: 52
    GraphMem.<init>(ReificationStyle) line: 35
    Factory.createGraphMem(ReificationStyle) line: 50
    Factory.createDefaultGraph(ReificationStyle) line: 44
    Factory.createDefaultGraph() line: 38
    GraphFactory.createJenaDefaultGraph() line: 54
    GraphFactory.createDefaultGraph() line: 48

U4DefaultGraph$U4UpdateEngineWorker(UpdateEngineWorker).visit(UpdateCreate)
line: 140
    U4DefaultGraph$U4UpdateEngineWorker.visit(UpdateCreate) line: 369
    UpdateCreate.visit(UpdateVisitor) line: 58
    U4DefaultGraph$U4UpdateEngine.execute() line: 314
    UpdateProcessorBase.execute() line: 56
    U4DefaultGraph.graphSPARUL(U4HTTPDoRequestMessage) line: 1065
    U4DefaultGraph$5.go(Object) line: 857
    U4DefaultGraph$3.go(Object) line: 737
    U4DefaultGraph(U4DefaultNode).nodeMessageHandler(U4Message) line:
713
    U4DefaultNode$MessageHandler.run() line: 625
    ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1110
    ThreadPoolExecutor$Worker.run() line: 603
    Thread.run() line: 722

Specifically GraphFactory.createDefaultGraph() line: 48 is;

    /**
        Answer a memory-based Graph with the Standard reification style.
    */
    public static Graph createDefaultGraph()
        { return createDefaultGraph( ReificationStyle.Standard ); }

So Jena uses a memory based graph to fulfil the create graph request.

But uses add(Quad) to fulfil the insert data [into {iri}] {...} request as
detailed with the following stack.

DatasetGraphTxn(DatasetGraphTriplesQuads).add(Quad) line: 33
DatasetGraphTransaction(DatasetGraphTrackActive).add(Quad) line: 133
GraphStoreBasic(DatasetGraphWrapper).add(Quad) line: 72
UpdateEngineWorker.addToGraphStore(GraphStore, Quad) line: 484
U4DefaultGraph$U4UpdateEngineWorker(UpdateEngineWorker).visit(UpdateDataInsert)
line: 281

So I need to add the graph (as a empty mem based graph) to the TDB backed
dataset then add quads to the dataset..?

Dick.


On 29 November 2012 21:31, Andy Seaborne <an...@apache.org> wrote:

> On 29/11/12 21:24, Andy Seaborne wrote:
>
>>  > 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.
>>
>
> It seems that the code adds in the contents of the graph into the dataset
> by copying over the triples - i.e. update before adding.
>
>         Andy
>
>
>
>> 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?
>>>
>>
>

Re: Issue adding Triples to Graph which has been added to a DatasetGraph.

Posted by Andy Seaborne <an...@apache.org>.
On 29/11/12 21:24, Andy Seaborne wrote:
>  > 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.

It seems that the code adds in the contents of the graph into the 
dataset by copying over the triples - i.e. update before adding.

	Andy

>
> 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?


Re: Issue adding Triples to Graph which has been added to a DatasetGraph.

Posted by Andy Seaborne <an...@apache.org>.
 > 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() ;
>      }
>
> }
>