You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Ed Swing <Ed...@sas.com> on 2014/01/16 18:55:56 UTC

Another Problem: can't set default graph

Onto another problem...

        File dir = new File(baseDir + "/" + projName);
        if (!dir.exists()) {
            dir.mkdirs();
            Dataset dataset =
                TDBFactory.createDataset(baseDir + "/" + projName);
            dataset.begin(ReadWrite.WRITE);
            OntModel project =
                ModelFactory
                    .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
            model.setNsPrefix("", SemanticStoreService.BASE_URI + projName
                + "/");
            dataset.setDefaultModel(project);

throws the following exception:
Exception in thread "main" java.lang.UnsupportedOperationException: Can't set default graph via GraphStore on a TDB-backed dataset
       at com.hp.hpl.jena.tdb.store.DatasetGraphTDB.setDefaultGraph(DatasetGraphTDB.java:314)
       at com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.setDefaultGraph(DatasetGraphTrackActive.java:115)
       at com.hp.hpl.jena.sparql.core.DatasetImpl.setDefaultModel(DatasetImpl.java:215)
       at com.sas.store.service.SemanticStoreService.createProject(SemanticStoreService.java:203)

I'm not sure what's going on here. How would you set the default graph of a newly created dataset? Note that this code is for the case when the dataset does not exist yet.

On a side note, it might be nice to add a method for TDBFactory.createDataset(File dir)...


Edward Swing
Applied Research Technologist
Vision Systems + Technology, Inc., a SAS Company
6021 University Boulevard * Suite 360 * Ellicott City * Maryland * 21043
Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
Web: http://www.vsticorp.com<http://www.vsticorp.com/>


RE: Another Problem: can't set default graph

Posted by Ed Swing <Ed...@sas.com>.
OK - thanks. I wasn't sure whether the default model was automatically created when a new TDB dataset is created.

-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org] 
Sent: Thursday, January 16, 2014 1:16 PM
To: users@jena.apache.org
Subject: Re: Another Problem: can't set default graph

On 16/01/14 17:55, Ed Swing wrote:
> Onto another problem...
>
>          File dir = new File(baseDir + "/" + projName);
>          if (!dir.exists()) {
>              dir.mkdirs();
>              Dataset dataset =
>                  TDBFactory.createDataset(baseDir + "/" + projName);

The dataset now exists.

>              dataset.begin(ReadWrite.WRITE);
>              OntModel project =
>                  ModelFactory
>                      .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>              model.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>                  + "/");
>              dataset.setDefaultModel(project);

Same issue - a dataset in TDB is not something you flip graphs on - they have to be copied in and out because they are bytes on disk (+caching).

The default graph is already there.  You need to add to it.

dataset.getDefaultModel().add(project);

>
> throws the following exception:
> Exception in thread "main" java.lang.UnsupportedOperationException: Can't set default graph via GraphStore on a TDB-backed dataset
>         at com.hp.hpl.jena.tdb.store.DatasetGraphTDB.setDefaultGraph(DatasetGraphTDB.java:314)
>         at com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.setDefaultGraph(DatasetGraphTrackActive.java:115)
>         at com.hp.hpl.jena.sparql.core.DatasetImpl.setDefaultModel(DatasetImpl.java:215)
>         at 
> com.sas.store.service.SemanticStoreService.createProject(SemanticStore
> Service.java:203)
>
> I'm not sure what's going on here. How would you set the default graph of a newly created dataset? Note that this code is for the case when the dataset does not exist yet.
>
> On a side note, it might be nice to add a method for TDBFactory.createDataset(File dir)...

Fore now, you can use:
TDBFactory.createDataset(dir.getAbsolutePath()) ;

>
>
> Edward Swing
> Applied Research Technologist
> Vision Systems + Technology, Inc., a SAS Company
> 6021 University Boulevard * Suite 360 * Ellicott City * Maryland * 
> 21043
> Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
> Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
> Web: http://www.vsticorp.com<http://www.vsticorp.com/>
>
>




Re: Another Problem: can't set default graph

Posted by Andy Seaborne <an...@apache.org>.
On 16/01/14 19:01, Ed Swing wrote:
> Here's the write code block:
>
>              Dataset dataset =
>                  TDBFactory.createDataset(baseDir + "/" + projName);
>              dataset.begin(ReadWrite.WRITE);
>              Model defModel = dataset.getDefaultModel();
>              defModel.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>                  + "/");
>              OntModel project =
>                  ModelFactory
>                      .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>              defModel.add(project);
>              OntModel projMeta =
>                  ModelFactory
>                      .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>              projMeta.setNsPrefix("", SemanticStoreService.BASE_URI);

projMeta is an in-memory graph

>              dataset.addNamedModel("metadata", projMeta);

addNamedModel does not copy prefixes.

Model dbm1 = dataset.getNamedModel("metadata");
dbm1.add(projMeta) ;
dbm1.setNsPrefixes(projMeta) ;

Tested - works for me (are youusing an old version?)

>              OntModel projOnt =
>                  ModelFactory
>                      .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>              projOnt.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>                  + "/");
>              dataset.addNamedModel("ontology", projOnt);
>              dataset.commit();
>              dataset.end();
>
> It doesn't seem to set the NsPrefix even when I supposedly set it on the default model.

Where?

> Here's the fragment where I get the model and print the namespace:
>
>          Dataset dataset =
>              dir.exists() ? TDBFactory.createDataset(directory) : null;
>          Model model = null;
>          dataset.begin(ReadWrite.WRITE);
>          model =
>              (modelName == null) ? dataset.getDefaultModel() : dataset
>                  .getNamedModel(modelName);
>          System.out.println("Read model " + projName + " " + modelName
>              + " baseURI=" + model.getNsPrefixURI(""));
>
> The model.getNsPrefixURI returns null for all three graphs (default, ontology, and metadata).

TDBFactory.createDataset() creates an in-memory TDB store that behaves 
exactly like the disk one.

Please can you provide complete, minimal and portable examples using 
that? thanks.

	Andy




>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Thursday, January 16, 2014 1:48 PM
> To: users@jena.apache.org
> Subject: Re: Another Problem: can't set default graph
>
> On 16/01/14 18:40, Ed Swing wrote:
>> I made the change below, and now I notice that the setNsPrefix() method doesn't seem to work. More specifically, when I later retrieve the stored model, getNsPrefix("") returns null.
>
> Model.add does not copy prefixes.
>
> You'll need to set them on the model for the default graph of the dataset.
>
> 	Andy
>
>>
>> -----Original Message-----
>> From: Andy Seaborne [mailto:andy@apache.org]
>> Sent: Thursday, January 16, 2014 1:16 PM
>> To: users@jena.apache.org
>> Subject: Re: Another Problem: can't set default graph
>>
>> On 16/01/14 17:55, Ed Swing wrote:
>>> Onto another problem...
>>>
>>>            File dir = new File(baseDir + "/" + projName);
>>>            if (!dir.exists()) {
>>>                dir.mkdirs();s
>>>                Dataset dataset =
>>>                    TDBFactory.createDataset(baseDir + "/" + projName);
>>
>> The dataset now exists.
>>
>>>                dataset.begin(ReadWrite.WRITE);
>>>                OntModel project =
>>>                    ModelFactory
>>>                        .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>>>                model.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>>>                    + "/");
>>>                dataset.setDefaultModel(project);
>>
>> Same issue - a dataset in TDB is not something you flip graphs on - they have to be copied in and out because they are bytes on disk (+caching).
>>
>> The default graph is already there.  You need to add to it.
>>
>> dataset.getDefaultModel().add(project);
>>
>>>
>>> throws the following exception:
>>> Exception in thread "main" java.lang.UnsupportedOperationException: Can't set default graph via GraphStore on a TDB-backed dataset
>>>           at com.hp.hpl.jena.tdb.store.DatasetGraphTDB.setDefaultGraph(DatasetGraphTDB.java:314)
>>>           at com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.setDefaultGraph(DatasetGraphTrackActive.java:115)
>>>           at com.hp.hpl.jena.sparql.core.DatasetImpl.setDefaultModel(DatasetImpl.java:215)
>>>           at
>>> com.sas.store.service.SemanticStoreService.createProject(SemanticStore
>>> Service.java:203)
>>>
>>> I'm not sure what's going on here. How would you set the default graph of a newly created dataset? Note that this code is for the case when the dataset does not exist yet.
>>>
>>> On a side note, it might be nice to add a method for TDBFactory.createDataset(File dir)...
>>
>> Fore now, you can use:
>> TDBFactory.createDataset(dir.getAbsolutePath()) ;
>>
>>>
>>>
>>> Edward Swing
>>> Applied Research Technologist
>>> Vision Systems + Technology, Inc., a SAS Company
>>> 6021 University Boulevard * Suite 360 * Ellicott City * Maryland *
>>> 21043
>>> Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
>>> Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
>>> Web: http://www.vsticorp.com<http://www.vsticorp.com/>
>>>
>>>
>>
>>
>>
>
>
>


RE: Another Problem: can't set default graph

Posted by Ed Swing <Ed...@sas.com>.
Here's the write code block:

            Dataset dataset =
                TDBFactory.createDataset(baseDir + "/" + projName);
            dataset.begin(ReadWrite.WRITE);
            Model defModel = dataset.getDefaultModel();
            defModel.setNsPrefix("", SemanticStoreService.BASE_URI + projName
                + "/");
            OntModel project =
                ModelFactory
                    .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
            defModel.add(project);
            OntModel projMeta =
                ModelFactory
                    .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
            projMeta.setNsPrefix("", SemanticStoreService.BASE_URI);
            dataset.addNamedModel("metadata", projMeta);
            OntModel projOnt =
                ModelFactory
                    .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
            projOnt.setNsPrefix("", SemanticStoreService.BASE_URI + projName
                + "/");
            dataset.addNamedModel("ontology", projOnt);
            dataset.commit();
            dataset.end();

It doesn't seem to set the NsPrefix even when I supposedly set it on the default model. Here's the fragment where I get the model and print the namespace:

        Dataset dataset =
            dir.exists() ? TDBFactory.createDataset(directory) : null;
        Model model = null;
        dataset.begin(ReadWrite.WRITE);
        model =
            (modelName == null) ? dataset.getDefaultModel() : dataset
                .getNamedModel(modelName);
        System.out.println("Read model " + projName + " " + modelName
            + " baseURI=" + model.getNsPrefixURI(""));

The model.getNsPrefixURI returns null for all three graphs (default, ontology, and metadata).

-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org] 
Sent: Thursday, January 16, 2014 1:48 PM
To: users@jena.apache.org
Subject: Re: Another Problem: can't set default graph

On 16/01/14 18:40, Ed Swing wrote:
> I made the change below, and now I notice that the setNsPrefix() method doesn't seem to work. More specifically, when I later retrieve the stored model, getNsPrefix("") returns null.

Model.add does not copy prefixes.

You'll need to set them on the model for the default graph of the dataset.

	Andy

>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Thursday, January 16, 2014 1:16 PM
> To: users@jena.apache.org
> Subject: Re: Another Problem: can't set default graph
>
> On 16/01/14 17:55, Ed Swing wrote:
>> Onto another problem...
>>
>>           File dir = new File(baseDir + "/" + projName);
>>           if (!dir.exists()) {
>>               dir.mkdirs();s
>>               Dataset dataset =
>>                   TDBFactory.createDataset(baseDir + "/" + projName);
>
> The dataset now exists.
>
>>               dataset.begin(ReadWrite.WRITE);
>>               OntModel project =
>>                   ModelFactory
>>                       .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>>               model.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>>                   + "/");
>>               dataset.setDefaultModel(project);
>
> Same issue - a dataset in TDB is not something you flip graphs on - they have to be copied in and out because they are bytes on disk (+caching).
>
> The default graph is already there.  You need to add to it.
>
> dataset.getDefaultModel().add(project);
>
>>
>> throws the following exception:
>> Exception in thread "main" java.lang.UnsupportedOperationException: Can't set default graph via GraphStore on a TDB-backed dataset
>>          at com.hp.hpl.jena.tdb.store.DatasetGraphTDB.setDefaultGraph(DatasetGraphTDB.java:314)
>>          at com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.setDefaultGraph(DatasetGraphTrackActive.java:115)
>>          at com.hp.hpl.jena.sparql.core.DatasetImpl.setDefaultModel(DatasetImpl.java:215)
>>          at
>> com.sas.store.service.SemanticStoreService.createProject(SemanticStore
>> Service.java:203)
>>
>> I'm not sure what's going on here. How would you set the default graph of a newly created dataset? Note that this code is for the case when the dataset does not exist yet.
>>
>> On a side note, it might be nice to add a method for TDBFactory.createDataset(File dir)...
>
> Fore now, you can use:
> TDBFactory.createDataset(dir.getAbsolutePath()) ;
>
>>
>>
>> Edward Swing
>> Applied Research Technologist
>> Vision Systems + Technology, Inc., a SAS Company
>> 6021 University Boulevard * Suite 360 * Ellicott City * Maryland *
>> 21043
>> Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
>> Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
>> Web: http://www.vsticorp.com<http://www.vsticorp.com/>
>>
>>
>
>
>




Re: Another Problem: can't set default graph

Posted by Andy Seaborne <an...@apache.org>.
On 16/01/14 18:40, Ed Swing wrote:
> I made the change below, and now I notice that the setNsPrefix() method doesn't seem to work. More specifically, when I later retrieve the stored model, getNsPrefix("") returns null.

Model.add does not copy prefixes.

You'll need to set them on the model for the default graph of the dataset.

	Andy

>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Thursday, January 16, 2014 1:16 PM
> To: users@jena.apache.org
> Subject: Re: Another Problem: can't set default graph
>
> On 16/01/14 17:55, Ed Swing wrote:
>> Onto another problem...
>>
>>           File dir = new File(baseDir + "/" + projName);
>>           if (!dir.exists()) {
>>               dir.mkdirs();s
>>               Dataset dataset =
>>                   TDBFactory.createDataset(baseDir + "/" + projName);
>
> The dataset now exists.
>
>>               dataset.begin(ReadWrite.WRITE);
>>               OntModel project =
>>                   ModelFactory
>>                       .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>>               model.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>>                   + "/");
>>               dataset.setDefaultModel(project);
>
> Same issue - a dataset in TDB is not something you flip graphs on - they have to be copied in and out because they are bytes on disk (+caching).
>
> The default graph is already there.  You need to add to it.
>
> dataset.getDefaultModel().add(project);
>
>>
>> throws the following exception:
>> Exception in thread "main" java.lang.UnsupportedOperationException: Can't set default graph via GraphStore on a TDB-backed dataset
>>          at com.hp.hpl.jena.tdb.store.DatasetGraphTDB.setDefaultGraph(DatasetGraphTDB.java:314)
>>          at com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.setDefaultGraph(DatasetGraphTrackActive.java:115)
>>          at com.hp.hpl.jena.sparql.core.DatasetImpl.setDefaultModel(DatasetImpl.java:215)
>>          at
>> com.sas.store.service.SemanticStoreService.createProject(SemanticStore
>> Service.java:203)
>>
>> I'm not sure what's going on here. How would you set the default graph of a newly created dataset? Note that this code is for the case when the dataset does not exist yet.
>>
>> On a side note, it might be nice to add a method for TDBFactory.createDataset(File dir)...
>
> Fore now, you can use:
> TDBFactory.createDataset(dir.getAbsolutePath()) ;
>
>>
>>
>> Edward Swing
>> Applied Research Technologist
>> Vision Systems + Technology, Inc., a SAS Company
>> 6021 University Boulevard * Suite 360 * Ellicott City * Maryland *
>> 21043
>> Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
>> Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
>> Web: http://www.vsticorp.com<http://www.vsticorp.com/>
>>
>>
>
>
>


RE: Another Problem: can't set default graph

Posted by Ed Swing <Ed...@sas.com>.
I made the change below, and now I notice that the setNsPrefix() method doesn't seem to work. More specifically, when I later retrieve the stored model, getNsPrefix("") returns null.

-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org] 
Sent: Thursday, January 16, 2014 1:16 PM
To: users@jena.apache.org
Subject: Re: Another Problem: can't set default graph

On 16/01/14 17:55, Ed Swing wrote:
> Onto another problem...
>
>          File dir = new File(baseDir + "/" + projName);
>          if (!dir.exists()) {
>              dir.mkdirs();s
>              Dataset dataset =
>                  TDBFactory.createDataset(baseDir + "/" + projName);

The dataset now exists.

>              dataset.begin(ReadWrite.WRITE);
>              OntModel project =
>                  ModelFactory
>                      .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>              model.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>                  + "/");
>              dataset.setDefaultModel(project);

Same issue - a dataset in TDB is not something you flip graphs on - they have to be copied in and out because they are bytes on disk (+caching).

The default graph is already there.  You need to add to it.

dataset.getDefaultModel().add(project);

>
> throws the following exception:
> Exception in thread "main" java.lang.UnsupportedOperationException: Can't set default graph via GraphStore on a TDB-backed dataset
>         at com.hp.hpl.jena.tdb.store.DatasetGraphTDB.setDefaultGraph(DatasetGraphTDB.java:314)
>         at com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.setDefaultGraph(DatasetGraphTrackActive.java:115)
>         at com.hp.hpl.jena.sparql.core.DatasetImpl.setDefaultModel(DatasetImpl.java:215)
>         at 
> com.sas.store.service.SemanticStoreService.createProject(SemanticStore
> Service.java:203)
>
> I'm not sure what's going on here. How would you set the default graph of a newly created dataset? Note that this code is for the case when the dataset does not exist yet.
>
> On a side note, it might be nice to add a method for TDBFactory.createDataset(File dir)...

Fore now, you can use:
TDBFactory.createDataset(dir.getAbsolutePath()) ;

>
>
> Edward Swing
> Applied Research Technologist
> Vision Systems + Technology, Inc., a SAS Company
> 6021 University Boulevard * Suite 360 * Ellicott City * Maryland * 
> 21043
> Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
> Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
> Web: http://www.vsticorp.com<http://www.vsticorp.com/>
>
>




Re: Another Problem: can't set default graph

Posted by Andy Seaborne <an...@apache.org>.
On 16/01/14 17:55, Ed Swing wrote:
> Onto another problem...
>
>          File dir = new File(baseDir + "/" + projName);
>          if (!dir.exists()) {
>              dir.mkdirs();
>              Dataset dataset =
>                  TDBFactory.createDataset(baseDir + "/" + projName);

The dataset now exists.

>              dataset.begin(ReadWrite.WRITE);
>              OntModel project =
>                  ModelFactory
>                      .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>              model.setNsPrefix("", SemanticStoreService.BASE_URI + projName
>                  + "/");
>              dataset.setDefaultModel(project);

Same issue - a dataset in TDB is not something you flip graphs on - they 
have to be copied in and out because they are bytes on disk (+caching).

The default graph is already there.  You need to add to it.

dataset.getDefaultModel().add(project);

>
> throws the following exception:
> Exception in thread "main" java.lang.UnsupportedOperationException: Can't set default graph via GraphStore on a TDB-backed dataset
>         at com.hp.hpl.jena.tdb.store.DatasetGraphTDB.setDefaultGraph(DatasetGraphTDB.java:314)
>         at com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.setDefaultGraph(DatasetGraphTrackActive.java:115)
>         at com.hp.hpl.jena.sparql.core.DatasetImpl.setDefaultModel(DatasetImpl.java:215)
>         at com.sas.store.service.SemanticStoreService.createProject(SemanticStoreService.java:203)
>
> I'm not sure what's going on here. How would you set the default graph of a newly created dataset? Note that this code is for the case when the dataset does not exist yet.
>
> On a side note, it might be nice to add a method for TDBFactory.createDataset(File dir)...

Fore now, you can use:
TDBFactory.createDataset(dir.getAbsolutePath()) ;

>
>
> Edward Swing
> Applied Research Technologist
> Vision Systems + Technology, Inc., a SAS Company
> 6021 University Boulevard * Suite 360 * Ellicott City * Maryland * 21043
> Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
> Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
> Web: http://www.vsticorp.com<http://www.vsticorp.com/>
>
>