Interface OWLOntology

All Superinterfaces:
Comparable<OWLObject>, HasAnnotationPropertiesInSignature, HasAnnotations, HasAnonymousIndividuals, HasApplyChange, HasApplyChanges, HasApplyDirectChange, HasAxioms, HasAxiomsByType, HasClassesInSignature, HasComponents, HasContainsAxiom, HasContainsEntityInSignature, HasDataPropertiesInSignature, HasDatatypesInSignature, HasDirectAddAxiom, HasDirectAddAxioms, HasDirectImports, HasDirectRemoveAxiom, HasDirectRemoveAxioms, HasGetEntitiesInSignature, HasHashIndex, HasImportsClosure, HasIndex, HasIndividualsInSignature, HasLogicalAxioms, HasObjectPropertiesInSignature, HasOntologyID, HasSignature, IsAnonymous, OWLAxiomCollection, OWLAxiomCollectionBooleanArgs, OWLAxiomIndex, OWLObject, OWLSignature, OWLSignatureBooleanArgs, Serializable
All Known Subinterfaces:
OWLMutableOntology
All Known Implementing Classes:
ConcurrentOWLOntologyImpl, OWLImmutableOntologyImpl, OWLOntologyImpl

Represents an OWL 2 Ontology in the OWL 2 specification.
An OWLOntology consists of a possibly empty set of OWLAxioms and a possibly empty set of OWLAnnotations. An ontology can have an ontology IRI which can be used to identify the ontology. If it has an ontology IRI then it may also have an ontology version IRI. Since OWL 2, an ontology need not have an ontology IRI. (See the OWL 2 Structural Specification An ontology cannot be modified directly. Changes must be applied via its OWLOntologyManager.
Since:
2.0.0
Author:
Matthew Horridge, The University Of Manchester, Bio-Health Informatics Group
  • Method Details

    • isAxiom

      default boolean isAxiom()
      Specified by:
      isAxiom in interface OWLObject
      Returns:
      true if this object is an axiom.
    • isIndividual

      default boolean isIndividual()
      Specified by:
      isIndividual in interface OWLObject
      Returns:
      true if this object is an individual.
    • isOntology

      default boolean isOntology()
      Specified by:
      isOntology in interface OWLObject
      Returns:
      true for ontologies, false for any other OWL object
    • components

      default Stream<?> components()
      Specified by:
      components in interface HasComponents
      Returns:
      components as a stream. The stream is ordered (by visit order) but not sorted. Implementations that override components() must ensure the order is compatible with equals() and hashCode().
    • initHashCode

      default int initHashCode()
      Specified by:
      initHashCode in interface OWLObject
      Returns:
      hash code for the object; called on first use, cached by OWLObjectImpl in the default implementation.
    • hashIndex

      default int hashIndex()
      Specified by:
      hashIndex in interface HasHashIndex
      Returns:
      index for this type. This is not a hashcode for instances, rather a hashcode for the types.
    • typeIndex

      default int typeIndex()
      Specified by:
      typeIndex in interface HasIndex
      Returns:
      index for this type. This is not a hashcode for instances, rather a sorting index for the types.
    • applyChange

      default ChangeApplied applyChange(OWLOntologyChange change)
      Description copied from interface: HasApplyChange
      A convenience method that applies just one change to an ontology. When this method is used through an OWLOntologyManager implementation, the instance used should be the one that the ontology returns through the getOWLOntologyManager() call. The reason is that some changes, e.g., change of ontology id and change of imports directives, affect data that only that manager instance knows about, such as the imports closure; changes of ontology id through the wrong manager will make the ontology unreachable through its new id in the manager associated with the ontology. Configuration for loading and saving parameters is also held by the manager, if not explicitly specified for the ontology. While the change might be successful, other bugs might be made apparent later.
      Specified by:
      applyChange in interface HasApplyChange
      Parameters:
      change - The change to be applied
      Returns:
      ChangeApplied.SUCCESSFULLY if the change is applied with success, ChangeApplied.UNSUCCESSFULLY otherwise.
    • applyDirectChange

      default ChangeApplied applyDirectChange(OWLOntologyChange change)
      Description copied from interface: HasApplyDirectChange
      A convenience method that applies just one change to this ontology. Note: ontology ID changes should not be passed directly to this method but applied through OWLOntologyManager. This is because the manager needs to update its internal structures for id changes.
      Specified by:
      applyDirectChange in interface HasApplyDirectChange
      Parameters:
      change - The change to be applied
      Returns:
      ChangeApplied.SUCCESSFULLY if the change is applied with success, ChangeApplied.UNSUCCESSFULLY otherwise.
    • applyChangesAndGetDetails

      default ChangeDetails applyChangesAndGetDetails(List<? extends OWLOntologyChange> changes)
      Description copied from interface: HasApplyChanges
      Applies a list ontology changes to a collection of ontologies. When this method is used through an OWLOntologyManager implementation, the instance used should be the one that the ontology returns through the getOWLOntologyManager() call. The reason is that some changes, e.g., change of ontology id and change of imports directives, affect data that only that manager instance knows about, such as the imports closure; changes of ontology id through the wrong manager will make the ontology unreachable through its new id in the manager associated with the ontology. Configuration for loading and saving parameters is also held by the manager, if not explicitly specified for the ontology. While the change might be successful, other bugs might be made apparent later.
      Specified by:
      applyChangesAndGetDetails in interface HasApplyChanges
      Parameters:
      changes - The changes to be applied.
      Returns:
      ChangeApplied.SUCCESSFULLY if the axiom is added, ChangeApplied.UNSUCCESSFULLY otherwise.
    • addAxiom

      default ChangeApplied addAxiom(OWLAxiom axiom)
      Description copied from interface: HasDirectAddAxiom
      A convenience method that adds a single axiom to an ontology. The appropriate AddAxiom change object is automatically generated.
      Specified by:
      addAxiom in interface HasDirectAddAxiom
      Parameters:
      axiom - The axiom to be added
      Returns:
      ChangeApplied.SUCCESSFULLY if the axiom is added, ChangeApplied.UNSUCCESSFULLY otherwise.
    • addAxioms

      default ChangeApplied addAxioms(Collection<? extends OWLAxiom> axioms)
      Description copied from interface: HasDirectAddAxioms
      A convenience method that adds a set of axioms to an ontology. The appropriate AddAxiom change objects are automatically generated.
      Specified by:
      addAxioms in interface HasDirectAddAxioms
      Parameters:
      axioms - The axioms to be added. Not null.
      Returns:
      ChangeApplied.SUCCESSFULLY if the axiom is added, ChangeApplied.UNSUCCESSFULLY otherwise.
    • addAxioms

      default ChangeApplied addAxioms(Stream<? extends OWLAxiom> axioms)
      Description copied from interface: HasDirectAddAxioms
      A convenience method that adds a set of axioms to an ontology. The appropriate AddAxiom change objects are automatically generated.
      Specified by:
      addAxioms in interface HasDirectAddAxioms
      Parameters:
      axioms - The axioms to be added. Not null.
      Returns:
      ChangeApplied.SUCCESSFULLY if the axiom is added, ChangeApplied.UNSUCCESSFULLY otherwise.
    • addAxioms

      default ChangeApplied addAxioms(OWLAxiom... axioms)
      Description copied from interface: HasDirectAddAxioms
      A convenience method that adds a set of axioms to an ontology. The appropriate AddAxiom change objects are automatically generated.
      Specified by:
      addAxioms in interface HasDirectAddAxioms
      Parameters:
      axioms - The axioms to be added. Not null.
      Returns:
      ChangeApplied.SUCCESSFULLY if the axiom is added, ChangeApplied.UNSUCCESSFULLY otherwise.
    • removeAxiom

      default ChangeApplied removeAxiom(OWLAxiom axiom)
      Description copied from interface: HasDirectRemoveAxiom
      A convenience method that removes a single axiom from this object. The appropriate RemoveAxiom change object is automatically generated.
      Specified by:
      removeAxiom in interface HasDirectRemoveAxiom
      Parameters:
      axiom - The axiom to be removed
      Returns:
      A list of ontology changes that represent the changes that actually took place.
    • removeAxioms

      default ChangeApplied removeAxioms(Collection<? extends OWLAxiom> axioms)
      Description copied from interface: HasDirectRemoveAxioms
      A convenience method that removes a set of axioms from this object. The appropriate RemoveAxiom change objects are automatically generated.
      Specified by:
      removeAxioms in interface HasDirectRemoveAxioms
      Parameters:
      axioms - The axioms to be removed.
      Returns:
      A list of ontology changes that represent the changes which took place in order to remove the axioms.
    • removeAxioms

      default ChangeApplied removeAxioms(Stream<? extends OWLAxiom> axioms)
      Description copied from interface: HasDirectRemoveAxioms
      A convenience method that removes a set of axioms from this object. The appropriate RemoveAxiom change objects are automatically generated.
      Specified by:
      removeAxioms in interface HasDirectRemoveAxioms
      Parameters:
      axioms - The axioms to be removed.
      Returns:
      A list of ontology changes that represent the changes which took place in order to remove the axioms.
    • removeAxioms

      default ChangeApplied removeAxioms(OWLAxiom... axioms)
      Description copied from interface: HasDirectRemoveAxioms
      A convenience method that removes a set of axioms from this object. The appropriate RemoveAxiom change objects are automatically generated.
      Specified by:
      removeAxioms in interface HasDirectRemoveAxioms
      Parameters:
      axioms - The axioms to be removed.
      Returns:
      A list of ontology changes that represent the changes which took place in order to remove the axioms.
    • accept

      default void accept(OWLNamedObjectVisitor visitor)
      accept for named object visitor
      Parameters:
      visitor - the visitor
    • accept

      default <O> O accept(OWLNamedObjectVisitorEx<O> visitor)
      Accepts a visitor
      Type Parameters:
      O - visitor return type
      Parameters:
      visitor - The visitor
      Returns:
      visitor return value
    • getOWLOntologyManager

      OWLOntologyManager getOWLOntologyManager()
      Gets the manager that manages this ontology. The manager is used by various methods on OWLOntology to resolve imports
      Returns:
      The manager for this ontology.
    • setOWLOntologyManager

      void setOWLOntologyManager(@Nullable OWLOntologyManager manager)
      Sets the manager for this ontology. This method is used when moving ontologies from one manager to another and when removing an ontology form a manager, and should be used by OWLOntologyManager implementations only.
      Parameters:
      manager - the new manager for this ontology
    • getFormat

      @Nullable default OWLDocumentFormat getFormat()
      Returns:
      ontology format for this ontology; can be null if the ontology has been created programmatically and not loaded/saved, so it does not have any format information associated.
    • getNonnullFormat

      default OWLDocumentFormat getNonnullFormat()
      Gets the ontology format for this ontology, ensuring it is not null (an error is thrown if the ontology has no format). Do not use this method to check if an ontology has a format associated with it; prefer getFormat().
      Returns:
      The format of the ontology
    • getImports

      default Set<OWLOntology> getImports()
      Gets the set of loaded ontologies that this ontology is related to via the transitive closure of the directlyImports relation.
      For example, if this ontology imports ontology B, and ontology B imports ontology C, then this method will return the set consisting of ontology B and ontology C.
      Returns:
      The set of ontologies that this ontology is related to via the transitive closure of the directlyImports relation. The set that is returned is a copy; modifications to the returned set will not be reflected in this object.
      Throws:
      UnknownOWLOntologyException - if this ontology is no longer managed by its manager because it was removed from the manager.
    • imports

      Stream<OWLOntology> imports()
      Gets the stream of loaded ontologies that this ontology is related to via the transitive closure of the directlyImports relation.
      For example, if this ontology imports ontology B, and ontology B imports ontology C, then this method will return the set consisting of ontology B and ontology C.
      Returns:
      The stream of ontologies that this ontology is related to via the transitive closure of the directlyImports relation.
      Throws:
      UnknownOWLOntologyException - if this ontology is no longer managed by its manager because it was removed from the manager.
    • getImportsDeclarations

      default Set<OWLImportsDeclaration> getImportsDeclarations()
      Gets the set of imports declarations for this ontology. The set returned represents the set of IRIs that correspond to the set of IRIs in an ontology's directlyImportsDocuments (see Section 3 in the OWL 2 structural specification).
      Returns:
      The set of imports declarations that correspond to the set of ontology document IRIs that are directly imported by this ontology. The set that is returned is a copy; modifications to the returned set will not be reflected in this object.
    • importsDeclarations

      Stream<OWLImportsDeclaration> importsDeclarations()
      Gets the stream of imports declarations for this ontology. These are the IRIs that correspond to the set of IRIs in an ontology's directlyImportsDocuments (see Section 3 in the OWL 2 structural specification).
      Returns:
      Sorted stream of imports declarations that correspond to the set of ontology document IRIs that are directly imported by this ontology.
    • isEmpty

      boolean isEmpty()
      Determines if this ontology is empty - an ontology is empty if it does not contain any axioms (i.e. HasAxioms.axioms() is empty), and it does not have any annotations (i.e. HasAnnotations.annotations() is empty).
      Returns:
      true if the ontology is empty, otherwise false.
    • getTBoxAxioms

      default Set<OWLAxiom> getTBoxAxioms(Imports includeImportsClosure)
      Gets the axioms that form the TBox for this ontology, i.e., the ones whose type is in the AxiomType::TBoxAxiomTypes.
      Parameters:
      includeImportsClosure - if INCLUDED, the imports closure is included.
      Returns:
      A set containing the axioms which are of the specified type. The set that is returned is a copy; modifications to the returned set will not be reflected in this object.
    • tboxAxioms

      Stream<OWLAxiom> tboxAxioms(Imports includeImportsClosure)
      Gets the axioms that form the TBox for this ontology, i.e., the ones whose type is in the AxiomType::TBoxAxiomTypes.
      Parameters:
      includeImportsClosure - if INCLUDED, the imports closure is included.
      Returns:
      A stream containing the axioms which are of the specified type.
    • getABoxAxioms

      default Set<OWLAxiom> getABoxAxioms(Imports includeImportsClosure)
      Gets the axioms that form the ABox for this ontology, i.e., the ones whose type is in the AxiomType::ABoxAxiomTypes.
      Parameters:
      includeImportsClosure - if INCLUDED, the imports closure is included.
      Returns:
      A set containing the axioms which are of the specified type. The set that is returned is a copy; modifications to the returned set will not be reflected in this object.
    • aboxAxioms

      Stream<OWLAxiom> aboxAxioms(Imports includeImportsClosure)
      Gets the axioms that form the ABox for this ontology, i.e., the ones whose type is in the AxiomType::ABoxAxiomTypes.
      Parameters:
      includeImportsClosure - if INCLUDED, the imports closure is included.
      Returns:
      A stream containing the axioms which are of the specified type.
    • getRBoxAxioms

      default Set<OWLAxiom> getRBoxAxioms(Imports includeImportsClosure)
      Gets the axioms that form the RBox for this ontology, i.e., the ones whose type is in the AxiomType::RBoxAxiomTypes.
      Parameters:
      includeImportsClosure - if INCLUDED, the imports closure is included.
      Returns:
      A set containing the axioms which are of the specified type. The set that is returned is a copy; modifications to the returned set will not be reflected in this object.
    • rboxAxioms

      Stream<OWLAxiom> rboxAxioms(Imports includeImportsClosure)
      Gets the axioms that form the RBox for this ontology, i.e., the ones whose type is in the AxiomType::RBoxAxiomTypes.
      Parameters:
      includeImportsClosure - if INCLUDED, the imports closure is included.
      Returns:
      A stream containing the axioms which are of the specified type.
    • getGeneralClassAxioms

      default Set<OWLClassAxiom> getGeneralClassAxioms()
      Gets the set of general axioms in this ontology. This includes:
      • Subclass axioms that have a complex class as the subclass
      • Equivalent class axioms that don't contain any named classes ( OWLClasses)
      • Disjoint class axioms that don't contain any named classes ( OWLClasses)
      Returns:
      The set of general axioms in this ontology. The set that is returned is a copy; modifications to the returned set will not be reflected in this object.
    • generalClassAxioms

      Stream<OWLClassAxiom> generalClassAxioms()
      Gets the stream of general axioms in this ontology. This includes:
      • Subclass axioms that have a complex class as the subclass
      • Equivalent class axioms that don't contain any named classes ( OWLClasses)
      • Disjoint class axioms that don't contain any named classes ( OWLClasses)
      Returns:
      The sorted stream containing the general axioms in the ontology.
    • getSignature

      default Set<OWLEntity> getSignature(Imports imports)
      Gets the entities that are in the signature of this ontology. The signature of an ontology is the set of entities that are used to build axioms and annotations in the ontology. (See The OWL 2 Structural Specification)
      Parameters:
      imports - if INCLUDED, the imports closure is included.
      Returns:
      A set of OWLEntity objects. The set that is returned is a copy; modifications to the returned set will not be reflected in this object.
      See Also:
    • signature

      default Stream<OWLEntity> signature(Imports imports)
      Gets the entities that are in the signature of this ontology. The signature of an ontology is the set of entities that are used to build axioms and annotations in the ontology. (See The OWL 2 Structural Specification)
      Parameters:
      imports - if INCLUDED, the imports closure is included.
      Returns:
      A stream of OWLEntity objects.
      See Also:
    • isDeclared

      boolean isDeclared(OWLEntity owlEntity)
      Determines if this ontology declares an entity i.e. it contains a declaration axiom for the specified entity.
      Parameters:
      owlEntity - The entity to be tested for
      Returns:
      true if the ontology contains a declaration for the specified entity, otherwise false.
    • isDeclared

      default boolean isDeclared(OWLEntity owlEntity, Imports imports)
      Determines if this ontology or its imports closure declares an entity i.e. contains a declaration axiom for the specified entity.
      Parameters:
      owlEntity - The entity to be tested for
      imports - if INCLUDED, the imports closure is included.
      Returns:
      true if the ontology or its imports closure contains a declaration for the specified entity, otherwise false.
    • saveOntology

      default void saveOntology() throws OWLOntologyStorageException
      Saves the ontology. The ontology will be saved to the location that it was loaded from, or if it was created programmatically, it will be saved to the location specified by an ontology IRI mapper at creation time. The ontology will be saved in the same format which it was loaded from, or the default ontology format if the ontology was created programmatically.
      Throws:
      OWLOntologyStorageException - An exception will be thrown if there is a problem with saving the ontology, or the ontology can't be saved in the format it was loaded from.
    • saveOntology

      default void saveOntology(IRI documentIRI) throws OWLOntologyStorageException
      Saves the ontology, using the specified document IRI to determine where/how the ontology should be saved.
      Parameters:
      documentIRI - The document IRI where the ontology should be saved to
      Throws:
      OWLOntologyStorageException - If the ontology cannot be saved
    • saveOntology

      default void saveOntology(OutputStream outputStream) throws OWLOntologyStorageException
      Saves the ontology, to the specified output stream
      Parameters:
      outputStream - The output stream where the ontology will be saved to
      Throws:
      OWLOntologyStorageException - If there was a problem saving this ontology to the specified output stream
    • saveOntology

      default void saveOntology(OWLDocumentFormat ontologyFormat) throws OWLOntologyStorageException
      Saves the ontology in the specified ontology format to its document URI.
      Parameters:
      ontologyFormat - The format in which the ontology should be saved.
      Throws:
      OWLOntologyStorageException - If the ontology cannot be saved.
    • saveOntology

      default void saveOntology(OWLDocumentFormat ontologyFormat, IRI documentIRI) throws OWLOntologyStorageException
      Saves the ontology to the specified document IRI in the specified ontology format.
      Parameters:
      ontologyFormat - The format in which to save the ontology
      documentIRI - The document IRI where the ontology should be saved to
      Throws:
      OWLOntologyStorageException - If the ontology could not be saved.
    • saveOntology

      default void saveOntology(OWLDocumentFormat ontologyFormat, OutputStream outputStream) throws OWLOntologyStorageException
      Saves the ontology to the specified output stream in the specified ontology format.
      Parameters:
      ontologyFormat - The format in which to save the ontology
      outputStream - The output stream where the ontology will be saved to.
      Throws:
      OWLOntologyStorageException - If the ontology could not be saved.
    • saveOntology

      default void saveOntology(OWLOntologyDocumentTarget documentTarget) throws OWLOntologyStorageException
      Saves the ontology to the specified OWLOntologyDocumentTarget.
      Parameters:
      documentTarget - The output target where the ontology will be saved to.
      Throws:
      OWLOntologyStorageException - If the ontology could not be saved.
    • saveOntology

      default void saveOntology(OWLDocumentFormat ontologyFormat, OWLOntologyDocumentTarget documentTarget) throws OWLOntologyStorageException
      Saves the ontology to the specified output target in the specified ontology format.
      Parameters:
      ontologyFormat - The output format in which to save the ontology
      documentTarget - The output target where the ontology will be saved to
      Throws:
      OWLOntologyStorageException - If the ontology could not be saved.
    • accept

      default void accept(OWLObjectVisitor visitor)
      Description copied from interface: OWLObject
      Accepts a visitor
      Specified by:
      accept in interface OWLObject
      Parameters:
      visitor - The visitor
    • accept

      default <O> O accept(OWLObjectVisitorEx<O> visitor)
      Description copied from interface: OWLObject
      Accepts a visitor
      Specified by:
      accept in interface OWLObject
      Type Parameters:
      O - visitor return type
      Parameters:
      visitor - The visitor
      Returns:
      visitor value