Package org.incenp.obofoundry.kgcl.owl
Class OntologyPatcher
java.lang.Object
org.incenp.obofoundry.kgcl.owl.OntologyPatcher
- All Implemented Interfaces:
IPatcher,RejectedChangeListener
A class to apply KGCL-described changes to a OWL API ontology. This class is
intended to be at a slightly higher level than
DirectOWLTranslator
and as such is the preferred way of modifying an ontology with KGCL.
Typical usage:
List<Change> changeSet = ... ;
OWLOntology ontology = ... ;
OWLReasoner reasoner = ... ;
OntologyPatcher patcher = new OntologyPatcher(ontology, reasoner);
if ( patcher.apply(changeSet) ) {
// All changes were successfully applied
ontology.saveOntology(...);
} else {
// Some changes at least could not be applied
for ( RejectedChange rc : patcher.getRejectedChanges() ) {
System.err.printf("Change rejected: %s\n", rc.getReason());
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionOntologyPatcher(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasoner reasoner) Creates a new instance to update the specified ontology. -
Method Summary
Modifier and TypeMethodDescriptionbooleanApplies a changeset to the knowledge graph.booleanApplies a single change to the knowledge graph.Gets the changes that have been rejected by this patcher.booleanIndicates whether changes have been rejected by this patcher.voidThis method is called whenever a change is rejected.voidsetProvisional(boolean provisional) Sets this patcher object in "provisional" mode, where changes are recorded in the ontology rather applied.
-
Constructor Details
-
OntologyPatcher
public OntologyPatcher(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasoner reasoner) Creates a new instance to update the specified ontology.- Parameters:
ontology- The ontology that changes should be applied to.reasoner- The reasoner to use (needed for operations such asNodeDeepeningandNodeShallowing).
-
-
Method Details
-
setProvisional
public void setProvisional(boolean provisional) Sets this patcher object in "provisional" mode, where changes are recorded in the ontology rather applied.- Parameters:
provisional-trueto enable "provisional" mode,falsefor "normal" mode.
-
apply
Description copied from interface:IPatcherApplies a single change to the knowledge graph. -
apply
Description copied from interface:IPatcherApplies a changeset to the knowledge graph.- Specified by:
applyin interfaceIPatcher- Parameters:
changes- The list of changes to apply.noPartialApply- Iftrue, changes shall only be applied if all the changes in the list can be applied; iffalse, changes that can be applied will be effectively applied, while rejected changes will be ignored.- Returns:
trueif all changes were applied successfully, otherwisefalse.
-
hasRejectedChanges
public boolean hasRejectedChanges()Description copied from interface:IPatcherIndicates whether changes have been rejected by this patcher.- Specified by:
hasRejectedChangesin interfaceIPatcher- Returns:
trueif at least one change has ever been rejected in the lifetime of this object, otherwisefalse.
-
getRejectedChanges
Description copied from interface:IPatcherGets the changes that have been rejected by this patcher.A change may be “rejected” if the contents of the knowledge graph does not match what is expected by the change. For example, a change that attempts to modify a node will be rejected if the node does not exist in the knowledge graph.
- Specified by:
getRejectedChangesin interfaceIPatcher- Returns:
- A list of all the changes that have been rejected in the lifetime of this patcher.
-
rejected
This method is called whenever a change is rejected. For internal use only, it should never be called by client code.- Specified by:
rejectedin interfaceRejectedChangeListener- Parameters:
change- The change that is rejected.reason- A human-readable reason for the rejection.
-