You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Zhiyun Qian <zh...@umich.edu> on 2013/09/30 05:33:04 UTC

how to persist ontology and model?

Hi there,

I have been trying to persist my ontology (a .owl file that I defined on my
own) and some models I created based on the it. However, I could't seem to
read what I have previously written.

The way I wrote to TDB is as follows:

Dataset dataset = TDBFactory.createDataset(dir);
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
dataset.addNamedModel(graph_name, m);
FileManager.get().readModel(m, "ontology/test.owl");

... add triples to model m.

TDB.sync(dataset);

Did I do anything wrong here? I was trying to find some examples on jena
documentation. However there's on link on
http://jena.apache.org/documentation/ontology/ that points to
http://jena.apache.org/documentation/examples/persistent-ont-model/index.html
which
is broken...Please help...

Thanks.

Re: how to persist ontology and model?

Posted by Zhiyun Qian <zh...@umich.edu>.
Thanks very much for the response. I have been able to persist the ontology
and triples successfully now using either methods.

Best,
-Zhiyun


On Tue, Oct 1, 2013 at 3:42 AM, Andy Seaborne <an...@apache.org> wrote:

> On 30/09/13 16:23, Zhiyun Qian wrote:
>
>> Please help...A friendly reminder...
>>
>
> Whatelse have you tried?
>
> Responses come from volunteers - there is no gauarnteed response time.
>
>
>
>>
>>
>> On Sun, Sep 29, 2013 at 11:33 PM, Zhiyun Qian <zh...@umich.edu> wrote:
>>
>>  Hi there,
>>>
>>> I have been trying to persist my ontology (a .owl file that I defined on
>>> my own) and some models I created based on the it. However, I could't
>>> seem
>>> to read what I have previously written.
>>>
>>> The way I wrote to TDB is as follows:
>>>
>>> Dataset dataset = TDBFactory.createDataset(dir);
>>> OntModel m = ModelFactory.**createOntologyModel( OntModelSpec.OWL_MEM,
>>> null
>>> );
>>> dataset.addNamedModel(graph_**name, m);
>>> FileManager.get().readModel(m, "ontology/test.owl");
>>>
>>> ... add triples to model m.
>>>
>>> TDB.sync(dataset);
>>>
>>> Did I do anything wrong here? I was trying to find some examples on jena
>>> documentation. However there's on link on
>>> http://jena.apache.org/**documentation/ontology/<http://jena.apache.org/documentation/ontology/>that points to
>>> http://jena.apache.org/**documentation/examples/**
>>> persistent-ont-model/index.**html<http://jena.apache.org/documentation/examples/persistent-ont-model/index.html>which
>>> is broken...Please help...
>>>
>>
> Adding a model copies the contents into the database.  But you added
> material after the copy, so it's only in the in-memory m.
>
> Use Dataset.getNamedModel, which is a view of the database, then,
> optiomnally, create the OntModel with that as the base, then read into it.
>
> Or reverse the two lines for read and add above.
>
>         Andy
>
>

Re: how to persist ontology and model?

Posted by Andy Seaborne <an...@apache.org>.
On 30/09/13 16:23, Zhiyun Qian wrote:
> Please help...A friendly reminder...

Whatelse have you tried?

Responses come from volunteers - there is no gauarnteed response time.

>
>
>
> On Sun, Sep 29, 2013 at 11:33 PM, Zhiyun Qian <zh...@umich.edu> wrote:
>
>> Hi there,
>>
>> I have been trying to persist my ontology (a .owl file that I defined on
>> my own) and some models I created based on the it. However, I could't seem
>> to read what I have previously written.
>>
>> The way I wrote to TDB is as follows:
>>
>> Dataset dataset = TDBFactory.createDataset(dir);
>> OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null
>> );
>> dataset.addNamedModel(graph_name, m);
>> FileManager.get().readModel(m, "ontology/test.owl");
>>
>> ... add triples to model m.
>>
>> TDB.sync(dataset);
>>
>> Did I do anything wrong here? I was trying to find some examples on jena
>> documentation. However there's on link on
>> http://jena.apache.org/documentation/ontology/ that points to
>> http://jena.apache.org/documentation/examples/persistent-ont-model/index.html which
>> is broken...Please help...

Adding a model copies the contents into the database.  But you added 
material after the copy, so it's only in the in-memory m.

Use Dataset.getNamedModel, which is a view of the database, then, 
optiomnally, create the OntModel with that as the base, then read into it.

Or reverse the two lines for read and add above.

	Andy


Re: how to persist ontology and model?

Posted by Zhiyun Qian <zh...@umich.edu>.
Please help...A friendly reminder...



On Sun, Sep 29, 2013 at 11:33 PM, Zhiyun Qian <zh...@umich.edu> wrote:

> Hi there,
>
> I have been trying to persist my ontology (a .owl file that I defined on
> my own) and some models I created based on the it. However, I could't seem
> to read what I have previously written.
>
> The way I wrote to TDB is as follows:
>
> Dataset dataset = TDBFactory.createDataset(dir);
> OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null
> );
> dataset.addNamedModel(graph_name, m);
> FileManager.get().readModel(m, "ontology/test.owl");
>
> ... add triples to model m.
>
> TDB.sync(dataset);
>
> Did I do anything wrong here? I was trying to find some examples on jena
> documentation. However there's on link on
> http://jena.apache.org/documentation/ontology/ that points to
> http://jena.apache.org/documentation/examples/persistent-ont-model/index.html which
> is broken...Please help...
>
> Thanks.
>
>