How can the reasoner be updated after a loaded ontology is modified?
When using OWLAPI v3.0
Pellet reasoner can be registered as an ontology change listener so it will be notified when a loaded ontology is modified and automatically update the loaded information. However, whether the modifications will be immediately visible in the reasoning results depends whether the reasoner was created as a buffering or non-buffering. For a non-buffering reasoner, the changes will impact the reasoning results for the next query asked. The following code snippet shows how to create a non-buffering reasoner and register a listener:
// import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
// import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
// create an ontology manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// create the Pellet reasoner
PelletReasoner reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner( ontology );
// add the reasoner as an ontology change listener
manager.addOntologyChangeListener( reasoner );
If a large number of updates occurs before the next query, tracking these changes may unnecessarily impact the performance of the reasoner. In such a case, a buffering reasoner may be a better choice—the modifications affect the reasoning results, only if the reasoner is explicitly notified by the following call:
reasoner.flush();
When using OWLAPI v2
Pellet reasoner can be registered as an ontology change listener so it will be notified when a loaded ontology is modified and automatically update the loaded information. The following code snippet shows how to do this:
// import org.mindswap.pellet.owlapi.Reasoner
// create an ontology manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// create the Pellet reasoner
Reasoner reasoner = new Reasoner( manager );
// add the reasoner as an ontology change listener
manager.addOntologyChangeListener( reasoner );
When an ontology is modified, reasoner will only load the new set of axioms to its internal memory but will not do perform any reasoning. Reasoning will be performed next time a query is asked. If there are a large number of ontology change events, tracking these changes as they occur might still slow down performance. If that is the case Pellet should not be registered as an ontology change listener and updated manually after changes occur with the following call:
reasoner.refresh();
