Your logic looks a little strange, comments inline:

On 04/02/2015 09:02, "Trevor Donaldson" <[email protected]> wrote:

>Not sure if this is right but I am pretty much implementing this logic.
>boolean modelExist = true;
>if(datasetaccessor.containsModel(GRAPH_NAME)){
>  model = datasetAccessor.getModel(GRAPH_NAME);
>} else{
>  model = ModelFactory.createDefaultModel();
>  modelExist = false;
>}
>
>build triples do model manipulation.....
>
>if(!modelExist){
>   datasetAccessor.put(GRAPH_NAME,model);

If the model doesn't exist you add it as a named graph

>} else{
>   datasetAccessor.add(model);

However if the model does exist you add it to the default graph, the Model
object does not carry around a graph name which seems to have been your
assumption here

So you are changing different graphs depending on whether the graph
already exists, in the case where it does the changes you make aren't
being saved where you expect them to and so won't be seen the next time
the code runs and loads the existing graph (it'll still be the same graph
as before because you put your actual changes in the default graph not the
named graph.

Additionally using add() means that any local deletions will not be
reflected because add will only add the current state of the model and
won't overwrite any data that was already in that graph so any triples you
deleted locally will still be present in the remote graph and seen next
time you load it.

Therefore you likely want to change this line like so:

datasetAccessor.put(GRAPH_NAME, model);

Which means you can actually eliminate that second if statement and just
call this method since you want to do the same thing whether the graph
already exists or not.

Rob

>}
>
>
>On Wed, Feb 4, 2015 at 11:48 AM, Trevor Donaldson <[email protected]>
>wrote:
>
>> How do I create a model with a graph name if it doesn't exist? I have
>> tried
>> Model model = ModelFactory.createDefaultModel();
>> datasetaccessor.put("http:example.org#exampleGraph",model);
>>
>> That doesn't seem to work.
>>




Reply via email to