[Pellet-users] save realized KB

James Howison james at howison.name
Tue Jul 29 15:30:18 UTC 2008


On Jul 28, 2008, at 11:32 PM, Chuming Chen wrote:

> Dear List,
>
> Is there a way to save the realized KnowledgeBase after invoking the  
> KB
> realize() method and reload it back later? If the ontology does not
> change, reloaded KB should be ready for providing query services  
> instead
> of having to do the reasoning again. I wonder whether pellet provides
> this kind of functionality.

I'm not sure how you are accessing Pellet's reasoning abilities, but I  
do what you describe through the Jena interface.

OntModel reasoningModel =  
ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC );

reasoningModel.read( stringWithPathToYourOntology );

// This wrapping ensures that UTF-8 and not something else is used.
FileOutputStream fos = new  
FileOutputStream( stringWithPathToFullOutputFile );
OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8");

// writeAll(), unlike write(), ensures that entailments are also  
written out
// N-TRIPLES is a good format for serialization because it is quick to  
read and write
// If the resulting file is huge you could wrap the OutputStreamWriter  
so that it does
// gzip compression.
reasoningModel.writeAll(out, "N-TRIPLES", null);

the file at stringWithPathToFullOutputFile can then be loaded later  
into a non-reasoning Model, or even inserted into a database backed  
model for SPARQL querying (eg via Joseki).

This way of doing things makes sense if you have a 'reason-once'  
'query-many' model of use, the proviso is that you have to 're- 
reasonn' every time you change the model in some way.

This is, of course, different from serializing the Pellet objects in  
someway, which might be quicker still.

--J


More information about the Pellet-users mailing list