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 TypeMethodDescriptionboolean
Applies a changeset to the knowledge graph.boolean
Applies a single change to the knowledge graph.Gets the changes that have been rejected by this patcher.boolean
Indicates whether changes have been rejected by this patcher.void
This method is called whenever a change is rejected.void
setProvisional
(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 asNodeDeepening
andNodeShallowing
).
-
-
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
-true
to enable "provisional" mode,false
for "normal" mode.
-
apply
Description copied from interface:IPatcher
Applies a single change to the knowledge graph. -
apply
Description copied from interface:IPatcher
Applies a changeset to the knowledge graph.- Specified by:
apply
in 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:
true
if all changes were applied successfully, otherwisefalse
.
-
hasRejectedChanges
public boolean hasRejectedChanges()Description copied from interface:IPatcher
Indicates whether changes have been rejected by this patcher.- Specified by:
hasRejectedChanges
in interfaceIPatcher
- Returns:
true
if at least one change has ever been rejected in the lifetime of this object, otherwisefalse
.
-
getRejectedChanges
Description copied from interface:IPatcher
Gets 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:
getRejectedChanges
in 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:
rejected
in interfaceRejectedChangeListener
- Parameters:
change
- The change that is rejected.reason
- A human-readable reason for the rejection.
-