You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Enes Bulut <en...@gmail.com> on 2012/08/08 08:51:51 UTC

SPARQL Update on default RDF model

Hi all,

I tried to update my RDF model using SPARQL, my model in memory,
then i had an exception that you can see below.

First I create a default model.

Model model= new ModelFactory.createDefaultModel();
...


Query string is something like that:

String queryStr = "PREFIX foaf:  <http://xmlns.com/foaf/0.1/> "
                                + "WITH <" + "http://example/addresses" +
"> "
                                + "DELETE { ?person foaf:givenName
\"Bill\" } "
                                + "INSERT { ?person foaf:givenName
\"William\" } "
                                + "WHERE {  ?person foaf:givenName
\"Bill\" } ";


UpdateRequest upReq = UpdateFactory.create();
upReq.add(queryStr);
UpdateAction.execute(upReq, model.getGraph);


When I run the project NullPointerException has occurred:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at
com.hp.hpl.jena.sparql.engine.iterator.QueryIterTriplePattern$TripleMapper.<init>(
 QueryIterTriplePattern.java:80)
        at
com.hp.hpl.jena.sparql.engine.iterator.QueryIterTriplePattern.nextStage(QueryIterTriplePattern.java:53)
        at
com.hp.hpl.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:113)
        at
com.hp.hpl.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:65)
...

Is there any way to update the model-in-memory using SPARQL?

Regards

Enes

Re: SPARQL Update on default RDF model

Posted by Andy Seaborne <an...@apache.org>.
On 08/08/12 12:24, Enes Bulut wrote:
> 2012/8/8 Damian Steer <d....@bristol.ac.uk>
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> On 08/08/12 07:51, Enes Bulut wrote:
>>> Hi all,
>>
>>> First I create a default model.
>>>
>>> Model model= new ModelFactory.createDefaultModel(); ...
>>>
>>>
>>> Query string is something like that:
>>>
>>> String queryStr = "PREFIX foaf:  <http://xmlns.com/foaf/0.1/> " +
>>> "WITH <" + "http://example/addresses" +
>>
>> You're trying to update a named graph (WITH), but you only have a
>> default graph. Drop the WITH.
>>
>>> UpdateRequest upReq = UpdateFactory.create(); upReq.add(queryStr);
>>> UpdateAction.execute(upReq, model.getGraph);
>>
>> Damian
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.11 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iEYEARECAAYFAlAiOOIACgkQAyLCB+mTtylvqwCglzrXiCkBgCLVbQarLp7rKkoo
>> 83sAoJ9WOYrzCfF0Mg6PQeSjEGDeZyrL
>> =i4Np
>> -----END PGP SIGNATURE-----
>>
>
> Oh, I got it. Thank you.
>

I've fixed the NPE as well (it won't make your update do anything 
sensible and it will not make a visible update to model, it just won't 
NPE) and put a note in the javadoc that working with named graphs needs 
a dataset, not a model.

	Andy

Re: SPARQL Update on default RDF model

Posted by Enes Bulut <en...@gmail.com>.
2012/8/8 Damian Steer <d....@bristol.ac.uk>

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 08/08/12 07:51, Enes Bulut wrote:
> > Hi all,
>
> > First I create a default model.
> >
> > Model model= new ModelFactory.createDefaultModel(); ...
> >
> >
> > Query string is something like that:
> >
> > String queryStr = "PREFIX foaf:  <http://xmlns.com/foaf/0.1/> " +
> > "WITH <" + "http://example/addresses" +
>
> You're trying to update a named graph (WITH), but you only have a
> default graph. Drop the WITH.
>
> > UpdateRequest upReq = UpdateFactory.create(); upReq.add(queryStr);
> > UpdateAction.execute(upReq, model.getGraph);
>
> Damian
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAlAiOOIACgkQAyLCB+mTtylvqwCglzrXiCkBgCLVbQarLp7rKkoo
> 83sAoJ9WOYrzCfF0Mg6PQeSjEGDeZyrL
> =i4Np
> -----END PGP SIGNATURE-----
>

Oh, I got it. Thank you.

Re: SPARQL Update on default RDF model

Posted by Damian Steer <d....@bristol.ac.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/08/12 07:51, Enes Bulut wrote:
> Hi all,

> First I create a default model.
> 
> Model model= new ModelFactory.createDefaultModel(); ...
> 
> 
> Query string is something like that:
> 
> String queryStr = "PREFIX foaf:  <http://xmlns.com/foaf/0.1/> " +
> "WITH <" + "http://example/addresses" +

You're trying to update a named graph (WITH), but you only have a
default graph. Drop the WITH.

> UpdateRequest upReq = UpdateFactory.create(); upReq.add(queryStr); 
> UpdateAction.execute(upReq, model.getGraph);

Damian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAiOOIACgkQAyLCB+mTtylvqwCglzrXiCkBgCLVbQarLp7rKkoo
83sAoJ9WOYrzCfF0Mg6PQeSjEGDeZyrL
=i4Np
-----END PGP SIGNATURE-----