Class OntologyPatcher

java.lang.Object
org.incenp.obofoundry.kgcl.owl.OntologyPatcher
All Implemented Interfaces:
IPatcher, RejectedChangeListener

public class OntologyPatcher extends Object implements 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

    Constructors
    Constructor
    Description
    OntologyPatcher(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 Type
    Method
    Description
    boolean
    apply(List<Change> changes, boolean noPartialApply)
    Applies a changeset to the knowledge graph.
    boolean
    apply(Change change)
    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
    rejected(Change change, String reason)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.incenp.obofoundry.kgcl.IPatcher

    apply
  • 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 as NodeDeepening and NodeShallowing).
  • 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

      public boolean apply(Change change)
      Description copied from interface: IPatcher
      Applies a single change to the knowledge graph.
      Specified by:
      apply in interface IPatcher
      Parameters:
      change - The change to apply.
      Returns:
      true if the change has been successfully applied, or false if the change has been rejected.
    • apply

      public boolean apply(List<Change> changes, boolean noPartialApply)
      Description copied from interface: IPatcher
      Applies a changeset to the knowledge graph.
      Specified by:
      apply in interface IPatcher
      Parameters:
      changes - The list of changes to apply.
      noPartialApply - If true, changes shall only be applied if all the changes in the list can be applied; if false, changes that can be applied will be effectively applied, while rejected changes will be ignored.
      Returns:
      true if all changes were applied successfully, otherwise false.
    • hasRejectedChanges

      public boolean hasRejectedChanges()
      Description copied from interface: IPatcher
      Indicates whether changes have been rejected by this patcher.
      Specified by:
      hasRejectedChanges in interface IPatcher
      Returns:
      true if at least one change has ever been rejected in the lifetime of this object, otherwise false.
    • getRejectedChanges

      public List<RejectedChange> 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 interface IPatcher
      Returns:
      A list of all the changes that have been rejected in the lifetime of this patcher.
    • rejected

      public void rejected(Change change, String reason)
      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 interface RejectedChangeListener
      Parameters:
      change - The change that is rejected.
      reason - A human-readable reason for the rejection.