You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Eric Scott <er...@att.net> on 2012/06/12 03:15:05 UTC
Problem inserting into named graphs
I'm encountering a problem inserting into named graphs when doing so
programmatically.
Pardon my clojure, but I think its intent is pretty clear, let me know
and I'll translate to java-ish pseudocode:
(let [model (TDBFactory/createModel (ensure-directories-exist
"/home/escott/test1TDB")),
update-request (UpdateFactory/create)
]
(.add update-request "Create Graph <http://myDB.com/ng>")
(.add update-request "INSERT DATA {graph <http://myDB.com/ng>
{<http://myDB.com/a><http://myDB.com/b><http://myDB.com/c>}}")
(UpdateAction/execute update-request model)
(.close model)))
This runs without error, and is similar to code I've called in the past
which works fine, but does not insert into a named graph.
However, when I make (say) this call:
(let [model (TDBFactory/createModel "/home/escott/test1TDB")
]
(sparql-query model "select ?g where {graph ?g {}}")))
I get no errors, but an empty response.
I have also entered exactly these update requests in fuseki and gotten
the expected behavior (a listing of named graphs, including the one I
just created).
Here are my maven spex:
[org.apache.jena/jena-core "2.7.0-incubating"]
[org.apache.jena/jena-arq "2.9.0-incubating"]
[org.apache.jena/jena-tdb "0.9.0-incubating"]
Is this a bug, or am I doing it wrong?
Thanks,
Re: Problem inserting into named graphs
Posted by Eric Scott <er...@att.net>.
Argh. That's right. The ol' model/dataset distinction.
Sorry about that.
Thanks,
On 06/12/2012 02:43 AM, Andy Seaborne wrote:
> On 12/06/12 02:15, Eric Scott wrote:
>> I'm encountering a problem inserting into named graphs when doing so
>> programmatically.
>>
>> Pardon my clojure, but I think its intent is pretty clear, let me know
>> and I'll translate to java-ish pseudocode:
>>
>>
>> (let [model (TDBFactory/createModel (ensure-directories-exist
>> "/home/escott/test1TDB")),
>> update-request (UpdateFactory/create)
>> ]
>> (.add update-request "Create Graph <http://myDB.com/ng>")
>> (.add update-request "INSERT DATA {graph <http://myDB.com/ng>
>> {<http://myDB.com/a><http://myDB.com/b><http://myDB.com/c>}}")
>> (UpdateAction/execute update-request model)
>> (.close model)))
>>
>> This runs without error, and is similar to code I've called in the past
>> which works fine, but does not insert into a named graph.
>>
>>
>> However, when I make (say) this call:
>>
>> (let [model (TDBFactory/createModel "/home/escott/test1TDB")
>> ]
>> (sparql-query model "select ?g where {graph ?g {}}")))
>>
>> I get no errors, but an empty response.
>>
>> I have also entered exactly these update requests in fuseki and gotten
>> the expected behavior (a listing of named graphs, including the one I
>> just created).
>>
>>
>> Here are my maven spex:
>>
>> [org.apache.jena/jena-core "2.7.0-incubating"]
>> [org.apache.jena/jena-arq "2.9.0-incubating"]
>> [org.apache.jena/jena-tdb "0.9.0-incubating"]
>>
>>
>> Is this a bug, or am I doing it wrong?
>
> It is because you are creating a model not a dataset.
>
> You then try to update the model by adding another model (the named
> graph).
>
> SPARQL Update acts on a dataset/graphstore. If you pass a model to
> the update engine, it wraps it in a general purpose, but in-memory,
> dataset with the passed-in model as the default graph.
>
> Your code adds a model "INSERT DATA {graph..." but that is not in the
> TDB dataset.
>
> Better is to create a TDB dataset and update that.
>
> TDBFactory/createDataset
>
> By the way - this route is now blocked - you'll get an exception
> saying "no such graph" because it now uses an datasetwrapper that only
> has one graph.
>
> Andy
>
>>
>> Thanks,
>>
>
>
Re: Problem inserting into named graphs
Posted by Andy Seaborne <an...@apache.org>.
On 12/06/12 02:15, Eric Scott wrote:
> I'm encountering a problem inserting into named graphs when doing so
> programmatically.
>
> Pardon my clojure, but I think its intent is pretty clear, let me know
> and I'll translate to java-ish pseudocode:
>
>
> (let [model (TDBFactory/createModel (ensure-directories-exist
> "/home/escott/test1TDB")),
> update-request (UpdateFactory/create)
> ]
> (.add update-request "Create Graph <http://myDB.com/ng>")
> (.add update-request "INSERT DATA {graph <http://myDB.com/ng>
> {<http://myDB.com/a><http://myDB.com/b><http://myDB.com/c>}}")
> (UpdateAction/execute update-request model)
> (.close model)))
>
> This runs without error, and is similar to code I've called in the past
> which works fine, but does not insert into a named graph.
>
>
> However, when I make (say) this call:
>
> (let [model (TDBFactory/createModel "/home/escott/test1TDB")
> ]
> (sparql-query model "select ?g where {graph ?g {}}")))
>
> I get no errors, but an empty response.
>
> I have also entered exactly these update requests in fuseki and gotten
> the expected behavior (a listing of named graphs, including the one I
> just created).
>
>
> Here are my maven spex:
>
> [org.apache.jena/jena-core "2.7.0-incubating"]
> [org.apache.jena/jena-arq "2.9.0-incubating"]
> [org.apache.jena/jena-tdb "0.9.0-incubating"]
>
>
> Is this a bug, or am I doing it wrong?
It is because you are creating a model not a dataset.
You then try to update the model by adding another model (the named graph).
SPARQL Update acts on a dataset/graphstore. If you pass a model to the
update engine, it wraps it in a general purpose, but in-memory, dataset
with the passed-in model as the default graph.
Your code adds a model "INSERT DATA {graph..." but that is not in the
TDB dataset.
Better is to create a TDB dataset and update that.
TDBFactory/createDataset
By the way - this route is now blocked - you'll get an exception saying
"no such graph" because it now uses an datasetwrapper that only has one
graph.
Andy
>
> Thanks,
>