Class OntologyHelper


  • public class OntologyHelper
    extends Object
    Provides convenience methods for working with OWL ontologies.
    Author:
    James A. Overton
    • Constructor Summary

      Constructors 
      Constructor Description
      OntologyHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addAxiomAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAxiom axiom, Set<org.semanticweb.owlapi.model.OWLAnnotation> annotations)
      Given an ontology, an axiom, and a set of annotations, annotate the axiom with the annotations in the ontology.
      static void addAxiomAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAxiom axiom, org.semanticweb.owlapi.model.IRI propertyIRI, org.semanticweb.owlapi.model.OWLAnnotationValue value)
      Given an ontology, an axiom, a property IRI, and a value string, add an annotation to this ontology with that property and value.
      static void addAxiomAnnotations​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI propertyIRI, org.semanticweb.owlapi.model.OWLAnnotationValue value)
      Given an ontology, an annotation property IRI, and an annotation value, annotate all axioms in the ontology with that property and value.
      static void addOntologyAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI propertyIRI, org.semanticweb.owlapi.model.OWLAnnotationValue value)
      Given an ontology, a property IRI, and a value string, add an annotation to this ontology with that property and value.
      static void addOntologyAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAnnotation annotation)
      Annotate the ontology with the annotation.
      static void collapseOntology​(org.semanticweb.owlapi.model.OWLOntology ontology, int threshold, Set<org.semanticweb.owlapi.model.IRI> precious, boolean repeat)
      Given an ontology, a threshold, and a set of precious IRIs (or empty set), minimize the input ontology's class hierarchy based on the threshold.
      static void collapseOntology​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.IRI> precious)
      Given an ontology and a set of IRIs that must be retained, remove intermediate superclasses (classes that only have one child) and update the subclass relationships to preserve structure.
      static void copy​(org.semanticweb.owlapi.model.OWLOntology inputOntology, org.semanticweb.owlapi.model.OWLOntology outputOntology, org.semanticweb.owlapi.model.OWLEntity entity, Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> annotationProperties)
      Given input and output ontologies, a target entity, and a set of annotation properties, copy the target entity from the input ontology to the output ontology, along with the specified annotations.
      static void copyAnnotations​(org.semanticweb.owlapi.model.OWLOntology inputOntology, org.semanticweb.owlapi.model.OWLOntology outputOntology, org.semanticweb.owlapi.model.OWLEntity entity, Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> annotationProperties)
      Given an input ontology, an output ontology, an entity to copy annotations of, and the annotation properties to copy (or null for all), copy annotations of the entity from the input to the output ontology.
      static boolean extendsAxiomTypes​(Class<? extends org.semanticweb.owlapi.model.OWLAxiom> axiom, Set<Class<? extends org.semanticweb.owlapi.model.OWLAxiom>> axiomTypes)
      Given an OWLAxiom class and a set of OWLAxiom classes, determine if the axiom class provided extends at least one of the classes in the set.
      static boolean extendsAxiomTypes​(org.semanticweb.owlapi.model.OWLAxiom axiom, Set<Class<? extends org.semanticweb.owlapi.model.OWLAxiom>> axiomTypes)
      Given an OWLAxiom and a set of OWLAxiom class, determine if the axiom's class is an extension of at least one of the given set.
      static Set<org.semanticweb.owlapi.model.IRI> filterExistingTerms​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.IRI> IRIs, boolean allowEmpty)
      Given an ontology and a set of IRIs, filter the set of IRIs to only include those that exist in the ontology.
      static Set<org.semanticweb.owlapi.model.IRI> filterExistingTerms​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.IRI> IRIs, boolean allowEmpty, org.semanticweb.owlapi.model.parameters.Imports imports)
      Given an ontology and a set of IRIs, filter the set of IRIs to only include those that exist in the ontology.
      static Set<org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom> getAnnotationAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties, Set<org.semanticweb.owlapi.model.IRI> subjects)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation assertion axioms for those subjects and those properties.
      static Set<org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom> getAnnotationAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAnnotationProperty property)
      Given an ontology, and an optional set of annotation properties, return a set of annotation assertion axioms for those properties, for all subjects.
      static Set<org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom> getAnnotationAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAnnotationProperty property, org.semanticweb.owlapi.model.IRI subject)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation assertion axioms for those subjects and those properties.
      static String getAnnotationString​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties, Set<org.semanticweb.owlapi.model.IRI> subjects)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return the alphanumerically first annotation value string for those subjects and those properties.
      static String getAnnotationString​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAnnotationProperty property, org.semanticweb.owlapi.model.IRI subject)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return the alphanumerically first annotation value string for those subjects and those properties.
      static Set<String> getAnnotationStrings​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties, Set<org.semanticweb.owlapi.model.IRI> subjects)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of strings for those subjects and those properties.
      static Set<String> getAnnotationStrings​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAnnotationProperty property, org.semanticweb.owlapi.model.IRI subject)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of strings for those subjects and those properties.
      static Set<org.semanticweb.owlapi.model.OWLAnnotationValue> getAnnotationValues​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties, Set<org.semanticweb.owlapi.model.IRI> subjects)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation values for those subjects and those properties.
      static Set<org.semanticweb.owlapi.model.OWLAnnotationValue> getAnnotationValues​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLAnnotationProperty property, org.semanticweb.owlapi.model.IRI subject)
      Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation values for those subjects and those properties.
      static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousAncestorAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLEntity entity)
      Given an ontology, an entity, and an empty set, fill the set with axioms representing any anonymous superclasses in the line of ancestors.
      static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousDescendantAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLEntity entity)
      Given an ontology and an entity, return a set of axioms containing any anonymous entities referenced in the descendants of the entity.
      static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousEquivalentAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLEntity entity)
      Given an ontology and an entity, return a set of axioms containing any anonymous entities referenced in equivalent entities.
      static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousParentAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLEntity entity)
      Given an ontology and an entity, return a set of axioms only corresponding to anonymous parents.
      static Set<org.semanticweb.owlapi.model.OWLEntity> getEntities​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an ontology, return a set of all the entities in its signature.
      static Set<org.semanticweb.owlapi.model.OWLEntity> getEntities​(org.semanticweb.owlapi.model.OWLOntology ontology, Set<org.semanticweb.owlapi.model.IRI> iris)
      Given an ontology and a set of term IRIs, return a set of entities for those IRIs.
      static org.semanticweb.owlapi.model.OWLEntity getEntity​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI iri)
      Given an ontology and an IRI, get the OWLEntity object represented by the IRI.
      static org.semanticweb.owlapi.model.OWLEntity getEntity​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI iri, boolean allowNull)
      Given an ontology, an IRI, and a boolean specifying if a null return value is allowed, get the OWLEntity object represented by the IRI.
      static Set<org.semanticweb.owlapi.model.IRI> getIRIs​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an ontology, return a set of IRIs for all the entities in its signature.
      static Set<org.semanticweb.owlapi.model.IRI> getIRIsInSignature​(org.semanticweb.owlapi.model.OWLAxiom axiom)
      Given an OWLAxiom, return all the IRIs in the signature.
      static Function<org.semanticweb.owlapi.model.OWLNamedObject,​String> getLabelFunction​(org.semanticweb.owlapi.model.OWLOntology ontology, boolean useIriAsDefault)
      Generates a function that returns a label string for any named object in the ontology
      static Map<String,​org.semanticweb.owlapi.model.IRI> getLabelIRIs​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an ontology, return a map from rdfs:label to IRIs.
      static Map<org.semanticweb.owlapi.model.IRI,​String> getLabels​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an ontology, return a map from IRIs to rdfs:labels.
      static Set<org.semanticweb.owlapi.model.OWLObject> getNamedObjects​(org.semanticweb.owlapi.model.OWLAxiom axiom)
      Get all named OWLObjects associated with an axiom.
      static Set<org.semanticweb.owlapi.model.OWLObject> getNamedObjects​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Get all named OWLObjects from an input ontology.
      static Set<org.semanticweb.owlapi.model.OWLObject> getObjects​(org.semanticweb.owlapi.model.OWLAxiom axiom)
      Get all OWLObjects associated with an axiom.
      static Set<org.semanticweb.owlapi.model.OWLObject> getObjects​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Get all OWLObjects from an input ontology.
      static org.semanticweb.owlapi.model.OWLDatatype getType​(org.semanticweb.owlapi.model.OWLAnnotationValue value)
      Given an annotation value, return its datatype, or null.
      static org.semanticweb.owlapi.model.IRI getTypeIRI​(org.semanticweb.owlapi.model.OWLAnnotationValue value)
      Given an annotation value, return the IRI of its datatype, or null.
      static String getValue​(Set<org.semanticweb.owlapi.model.OWLAnnotation> annotations)
      Given a set of OWLAnnotations, return the first string value as determined by natural string sorting.
      static String getValue​(org.semanticweb.owlapi.model.OWLAnnotation annotation)
      Given an OWLAnnotation, return its value as a string.
      static String getValue​(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom axiom)
      Given an OWLAnnotationAssertionAxiom, return its value as a string.
      static String getValue​(org.semanticweb.owlapi.model.OWLAnnotationValue value)
      Given an OWLAnnotationValue, return its value as a string.
      static Set<String> getValues​(Set<org.semanticweb.owlapi.model.OWLAnnotation> annotations)
      Given a set of OWLAnnotations, return a set of their value strings.
      static void removeImports​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an ontology, remove the import declarations.
      static void removeOntologyAnnotations​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Remove all annotations on this ontology.
      static String renderManchester​(org.semanticweb.owlapi.model.OWLObject object, org.semanticweb.owlapi.util.ShortFormProvider provider)
      Render a Manchester string for an OWLObject.
      static String renderManchester​(org.semanticweb.owlapi.model.OWLObject object, org.semanticweb.owlapi.util.ShortFormProvider provider, RendererType rt)
      Render a Manchester string for an OWLObject.
      static void setOntologyIRI​(org.semanticweb.owlapi.model.OWLOntology ontology, String ontologyIRIString, String versionIRIString)
      Set the ontology IRI and version IRI using strings.
      static void setOntologyIRI​(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI ontologyIRI, org.semanticweb.owlapi.model.IRI versionIRI)
      Set the ontology IRI and version IRI.
      static void trimOntology​(org.semanticweb.owlapi.model.OWLOntology ontology)
      Given an ontology, remove any dangling entities.
    • Constructor Detail

      • OntologyHelper

        public OntologyHelper()
    • Method Detail

      • addAxiomAnnotation

        public static void addAxiomAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                              org.semanticweb.owlapi.model.OWLAxiom axiom,
                                              org.semanticweb.owlapi.model.IRI propertyIRI,
                                              org.semanticweb.owlapi.model.OWLAnnotationValue value)
        Given an ontology, an axiom, a property IRI, and a value string, add an annotation to this ontology with that property and value.

        Note that as axioms are immutable, the axiom is removed and replaced with a new one.

        Parameters:
        ontology - the ontology to modify
        axiom - the axiom to annotate
        propertyIRI - the IRI of the property to add
        value - the IRI or literal value to add
      • addAxiomAnnotation

        public static void addAxiomAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                              org.semanticweb.owlapi.model.OWLAxiom axiom,
                                              Set<org.semanticweb.owlapi.model.OWLAnnotation> annotations)
        Given an ontology, an axiom, and a set of annotations, annotate the axiom with the annotations in the ontology.

        Note that as axioms are immutable, the axiom is removed and replaced with a new one.

        Parameters:
        ontology - the ontology to modify
        axiom - the axiom to annotate
        annotations - the set of annotation to add to the axiom
      • addAxiomAnnotations

        public static void addAxiomAnnotations​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                               org.semanticweb.owlapi.model.IRI propertyIRI,
                                               org.semanticweb.owlapi.model.OWLAnnotationValue value)
        Given an ontology, an annotation property IRI, and an annotation value, annotate all axioms in the ontology with that property and value.
        Parameters:
        ontology - the ontology to modify
        propertyIRI - the IRI of the property to add
        value - the IRI or literal value to add
      • addOntologyAnnotation

        public static void addOntologyAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                 org.semanticweb.owlapi.model.IRI propertyIRI,
                                                 org.semanticweb.owlapi.model.OWLAnnotationValue value)
        Given an ontology, a property IRI, and a value string, add an annotation to this ontology with that property and value.
        Parameters:
        ontology - the ontology to modify
        propertyIRI - the IRI of the property to add
        value - the IRI or literal value to add
      • addOntologyAnnotation

        public static void addOntologyAnnotation​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                 org.semanticweb.owlapi.model.OWLAnnotation annotation)
        Annotate the ontology with the annotation.
        Parameters:
        ontology - the ontology to modify
        annotation - the annotation to add
      • collapseOntology

        public static void collapseOntology​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                            Set<org.semanticweb.owlapi.model.IRI> precious)
                                     throws org.semanticweb.owlapi.model.OWLOntologyCreationException
        Given an ontology and a set of IRIs that must be retained, remove intermediate superclasses (classes that only have one child) and update the subclass relationships to preserve structure. The ontology passed in is updated. Do not perform collapse multiple times (some intermediate classes will remain after only one pass).
        Parameters:
        ontology - ontology to remove intermediates in
        precious - set of OWLEntities that should not be removed
        Throws:
        org.semanticweb.owlapi.model.OWLOntologyCreationException - on problem creating ontology
      • collapseOntology

        public static void collapseOntology​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                            int threshold,
                                            Set<org.semanticweb.owlapi.model.IRI> precious,
                                            boolean repeat)
                                     throws org.semanticweb.owlapi.model.OWLOntologyCreationException
        Given an ontology, a threshold, and a set of precious IRIs (or empty set), minimize the input ontology's class hierarchy based on the threshold. The threshold is the minimum number of child classes that an intermediate class should have. Any intermediate class that has less than the threshold number of children will be removed and its children will become children of the next level up. Bottom-level and top-level classes are not removed. Any class with an IRI in the precious set is not removed. If not repeat, collapse will only be performed once, meaning that some intermediate classes may remain.
        Parameters:
        ontology - OWLOntology to minimize
        threshold - minimum number of child classes
        precious - set of IRIs to keep
        repeat - if true, repeat collapsing until no intermediate classes remain
        Throws:
        org.semanticweb.owlapi.model.OWLOntologyCreationException - on problem creating copy to span gaps
      • copy

        public static void copy​(org.semanticweb.owlapi.model.OWLOntology inputOntology,
                                org.semanticweb.owlapi.model.OWLOntology outputOntology,
                                org.semanticweb.owlapi.model.OWLEntity entity,
                                Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> annotationProperties)
        Given input and output ontologies, a target entity, and a set of annotation properties, copy the target entity from the input ontology to the output ontology, along with the specified annotations. If the entity is already in the outputOntology, then return without making any changes. The input ontology is not changed.
        Parameters:
        inputOntology - the ontology to copy from
        outputOntology - the ontology to copy to
        entity - the target entity that will have its ancestors copied
        annotationProperties - the annotations to copy
      • copyAnnotations

        public static void copyAnnotations​(org.semanticweb.owlapi.model.OWLOntology inputOntology,
                                           org.semanticweb.owlapi.model.OWLOntology outputOntology,
                                           org.semanticweb.owlapi.model.OWLEntity entity,
                                           Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> annotationProperties)
        Given an input ontology, an output ontology, an entity to copy annotations of, and the annotation properties to copy (or null for all), copy annotations of the entity from the input to the output ontology.
        Parameters:
        inputOntology - OWLOntology to copy from
        outputOntology - OWLOntology to copy to
        entity - OWLEntity to copy annotations of
        annotationProperties - Set of annotation properties to copy, or null for all
      • filterExistingTerms

        public static Set<org.semanticweb.owlapi.model.IRI> filterExistingTerms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                Set<org.semanticweb.owlapi.model.IRI> IRIs,
                                                                                boolean allowEmpty)
        Given an ontology and a set of IRIs, filter the set of IRIs to only include those that exist in the ontology. Always include terms in imports.
        Parameters:
        ontology - the ontology to check for IRIs
        IRIs - Set of IRIs to filter
        allowEmpty - boolean specifying if an empty set can be returned
        Returns:
        Set of filtered IRIs
      • filterExistingTerms

        public static Set<org.semanticweb.owlapi.model.IRI> filterExistingTerms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                Set<org.semanticweb.owlapi.model.IRI> IRIs,
                                                                                boolean allowEmpty,
                                                                                org.semanticweb.owlapi.model.parameters.Imports imports)
        Given an ontology and a set of IRIs, filter the set of IRIs to only include those that exist in the ontology. Maybe include terms in imports.
        Parameters:
        ontology - the ontology to check for IRIs
        IRIs - Set of IRIs to filter
        allowEmpty - boolean specifying if an empty set can be returned
        imports - Imports INCLUDED or EXCLUDED
        Returns:
        Set of filtered IRIs
      • getNamedObjects

        public static Set<org.semanticweb.owlapi.model.OWLObject> getNamedObjects​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Get all named OWLObjects from an input ontology.
        Parameters:
        ontology - OWLOntology to retrieve objects from
        Returns:
        set of objects
      • getNamedObjects

        public static Set<org.semanticweb.owlapi.model.OWLObject> getNamedObjects​(org.semanticweb.owlapi.model.OWLAxiom axiom)
        Get all named OWLObjects associated with an axiom. This is builds on getSignature() by including annotation subjects, properties, and values.
        Parameters:
        axiom - The axiom to check
        Returns:
        The set of objects
      • getIRIsInSignature

        public static Set<org.semanticweb.owlapi.model.IRI> getIRIsInSignature​(org.semanticweb.owlapi.model.OWLAxiom axiom)
        Given an OWLAxiom, return all the IRIs in the signature. This is an add-on to the getSignature method to include OWLAnnotationAssertionAxioms.
        Parameters:
        axiom - OWLAxiom to get signature of
        Returns:
        IRIs used in OWLAxiom
      • getObjects

        public static Set<org.semanticweb.owlapi.model.OWLObject> getObjects​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Get all OWLObjects from an input ontology.
        Parameters:
        ontology - OWLOntology to retrieve objects from
        Returns:
        set of objects
      • getObjects

        public static Set<org.semanticweb.owlapi.model.OWLObject> getObjects​(org.semanticweb.owlapi.model.OWLAxiom axiom)
        Get all OWLObjects associated with an axiom. This is builds on getSignature() by including anonymous objects.
        Parameters:
        axiom - The axiom to check
        Returns:
        The set of objects
      • getAnonymousAncestorAxioms

        public static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousAncestorAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                            org.semanticweb.owlapi.model.OWLEntity entity)
        Given an ontology, an entity, and an empty set, fill the set with axioms representing any anonymous superclasses in the line of ancestors.
        Parameters:
        ontology - the ontology to search
        entity - the entity to search ancestors of
        Returns:
        set of OWLAxioms
      • getAnonymousDescendantAxioms

        public static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousDescendantAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                              org.semanticweb.owlapi.model.OWLEntity entity)
        Given an ontology and an entity, return a set of axioms containing any anonymous entities referenced in the descendants of the entity. Includes supers and equivalents.
        Parameters:
        ontology - the ontology to search
        entity - the entity to search descendants of
        Returns:
        set of OWLAxioms
      • getAnonymousEquivalentAxioms

        public static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousEquivalentAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                              org.semanticweb.owlapi.model.OWLEntity entity)
        Given an ontology and an entity, return a set of axioms containing any anonymous entities referenced in equivalent entities.
        Parameters:
        ontology - the ontology to search
        entity - the entity to search equivalents of
        Returns:
        set of OWLAxioms
      • getAnonymousParentAxioms

        public static Set<org.semanticweb.owlapi.model.OWLAxiom> getAnonymousParentAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                          org.semanticweb.owlapi.model.OWLEntity entity)
        Given an ontology and an entity, return a set of axioms only corresponding to anonymous parents.
        Parameters:
        ontology - the ontology to search
        entity - the entity to search parents of
        Returns:
        set of OWLAxioms
      • getAnnotationAxioms

        public static Set<org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom> getAnnotationAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                                        org.semanticweb.owlapi.model.OWLAnnotationProperty property)
        Given an ontology, and an optional set of annotation properties, return a set of annotation assertion axioms for those properties, for all subjects.
        Parameters:
        ontology - the ontology to search (including imports closure)
        property - an annotation property
        Returns:
        a filtered set of annotation assertion axioms
      • getAnnotationAxioms

        public static Set<org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom> getAnnotationAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                                        org.semanticweb.owlapi.model.OWLAnnotationProperty property,
                                                                                                        org.semanticweb.owlapi.model.IRI subject)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation assertion axioms for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        property - an annotation property
        subject - an annotation subject IRIs
        Returns:
        a filtered set of annotation assertion axioms
      • getAnnotationAxioms

        public static Set<org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom> getAnnotationAxioms​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                                        Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties,
                                                                                                        Set<org.semanticweb.owlapi.model.IRI> subjects)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation assertion axioms for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        properties - a set of annotation properties, or null if all properties should be included
        subjects - a set of annotation subject IRIs, or null if all subjects should be included
        Returns:
        a filtered set of annotation assertion axioms
      • getAnnotationString

        public static String getAnnotationString​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                 org.semanticweb.owlapi.model.OWLAnnotationProperty property,
                                                 org.semanticweb.owlapi.model.IRI subject)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return the alphanumerically first annotation value string for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        property - an annotation property
        subject - an annotation subject IRIs
        Returns:
        the first annotation string
      • getAnnotationString

        public static String getAnnotationString​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                 Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties,
                                                 Set<org.semanticweb.owlapi.model.IRI> subjects)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return the alphanumerically first annotation value string for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        properties - a set of annotation properties, or null if all properties should be included
        subjects - a set of annotation subject IRIs, or null if all subjects should be included
        Returns:
        the first annotation string
      • getAnnotationStrings

        public static Set<String> getAnnotationStrings​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                       org.semanticweb.owlapi.model.OWLAnnotationProperty property,
                                                       org.semanticweb.owlapi.model.IRI subject)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of strings for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        property - an annotation property
        subject - an annotation subject IRIs
        Returns:
        a filtered set of annotation strings
      • getAnnotationStrings

        public static Set<String> getAnnotationStrings​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                       Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties,
                                                       Set<org.semanticweb.owlapi.model.IRI> subjects)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of strings for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        properties - a set of annotation properties, or null if all properties should be included
        subjects - a set of annotation subject IRIs, or null if all subjects should be included
        Returns:
        a filtered set of annotation strings
      • getAnnotationValues

        public static Set<org.semanticweb.owlapi.model.OWLAnnotationValue> getAnnotationValues​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                               org.semanticweb.owlapi.model.OWLAnnotationProperty property,
                                                                                               org.semanticweb.owlapi.model.IRI subject)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation values for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        property - an annotation property
        subject - an annotation subject IRIs
        Returns:
        a filtered set of annotation values
      • getAnnotationValues

        public static Set<org.semanticweb.owlapi.model.OWLAnnotationValue> getAnnotationValues​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                               Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> properties,
                                                                                               Set<org.semanticweb.owlapi.model.IRI> subjects)
        Given an ontology, an optional set of annotation properties, and an optional set of subject, return a set of annotation values for those subjects and those properties.
        Parameters:
        ontology - the ontology to search (including imports closure)
        properties - a set of annotation properties, or null if all properties should be included
        subjects - a set of annotation subject IRIs, or null if all subjects should be included
        Returns:
        a filtered set of annotation values
      • getEntity

        public static org.semanticweb.owlapi.model.OWLEntity getEntity​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                       org.semanticweb.owlapi.model.IRI iri)
                                                                throws Exception
        Given an ontology and an IRI, get the OWLEntity object represented by the IRI. If it does not exist in the ontology, throw an exception.
        Parameters:
        ontology - OWLOntology to retrieve from
        iri - IRI to get type of
        Returns:
        OWLEntity
        Throws:
        Exception - if IRI is not in ontology
      • getEntity

        public static org.semanticweb.owlapi.model.OWLEntity getEntity​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                       org.semanticweb.owlapi.model.IRI iri,
                                                                       boolean allowNull)
                                                                throws Exception
        Given an ontology, an IRI, and a boolean specifying if a null return value is allowed, get the OWLEntity object represented by the IRI.
        Parameters:
        ontology - OWLOntology to retrieve from
        iri - IRI to get type of
        allowNull - if true, do not throw exception if IRI does not exist in ontology
        Returns:
        OWLEntity
        Throws:
        Exception - if allowNull is false and IRI is not in ontology
      • getEntities

        public static Set<org.semanticweb.owlapi.model.OWLEntity> getEntities​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                              Set<org.semanticweb.owlapi.model.IRI> iris)
        Given an ontology and a set of term IRIs, return a set of entities for those IRIs. The input ontology is not changed.
        Parameters:
        ontology - the ontology to search
        iris - the IRIs of the entities to find
        Returns:
        a set of OWLEntities with the given IRIs
      • getEntities

        public static Set<org.semanticweb.owlapi.model.OWLEntity> getEntities​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Given an ontology, return a set of all the entities in its signature.
        Parameters:
        ontology - the ontology to search
        Returns:
        a set of all entities in the ontology
      • getIRIs

        public static Set<org.semanticweb.owlapi.model.IRI> getIRIs​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Given an ontology, return a set of IRIs for all the entities in its signature.
        Parameters:
        ontology - the ontology to search
        Returns:
        a set of IRIs for all entities in the ontology
      • getLabelFunction

        public static Function<org.semanticweb.owlapi.model.OWLNamedObject,​String> getLabelFunction​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                                                                                          boolean useIriAsDefault)
        Generates a function that returns a label string for any named object in the ontology
        Parameters:
        ontology - to use
        useIriAsDefault - if true then label-less classes will return IRI
        Returns:
        function mapping object to label
      • getLabelIRIs

        public static Map<String,​org.semanticweb.owlapi.model.IRI> getLabelIRIs​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Given an ontology, return a map from rdfs:label to IRIs. Includes labels asserted in for all imported ontologies. Duplicates overwrite existing with a warning.
        Parameters:
        ontology - the ontology to use
        Returns:
        a map from label strings to IRIs
      • getLabels

        public static Map<org.semanticweb.owlapi.model.IRI,​String> getLabels​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Given an ontology, return a map from IRIs to rdfs:labels. Includes labels asserted in for all imported ontologies. If there are multiple labels, use the alphanumerically first.
        Parameters:
        ontology - the ontology to use
        Returns:
        a map from IRIs to label strings
      • getType

        public static org.semanticweb.owlapi.model.OWLDatatype getType​(org.semanticweb.owlapi.model.OWLAnnotationValue value)
        Given an annotation value, return its datatype, or null.
        Parameters:
        value - the value to check
        Returns:
        the datatype, or null if the value has none
      • getTypeIRI

        public static org.semanticweb.owlapi.model.IRI getTypeIRI​(org.semanticweb.owlapi.model.OWLAnnotationValue value)
        Given an annotation value, return the IRI of its datatype, or null.
        Parameters:
        value - the value to check
        Returns:
        the IRI of the datatype, or null if the value has none
      • getValue

        public static String getValue​(org.semanticweb.owlapi.model.OWLAnnotationValue value)
        Given an OWLAnnotationValue, return its value as a string.
        Parameters:
        value - the OWLAnnotationValue to get the string value of
        Returns:
        the string value
      • getValue

        public static String getValue​(org.semanticweb.owlapi.model.OWLAnnotation annotation)
        Given an OWLAnnotation, return its value as a string.
        Parameters:
        annotation - the OWLAnnotation to get the string value of
        Returns:
        the string value
      • getValue

        public static String getValue​(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom axiom)
        Given an OWLAnnotationAssertionAxiom, return its value as a string.
        Parameters:
        axiom - the OWLAnnotationAssertionAxiom to get the string value of
        Returns:
        the string value
      • getValue

        public static String getValue​(Set<org.semanticweb.owlapi.model.OWLAnnotation> annotations)
        Given a set of OWLAnnotations, return the first string value as determined by natural string sorting.
        Parameters:
        annotations - a set of OWLAnnotations to get the value of
        Returns:
        the first string value
      • getValues

        public static Set<String> getValues​(Set<org.semanticweb.owlapi.model.OWLAnnotation> annotations)
        Given a set of OWLAnnotations, return a set of their value strings.
        Parameters:
        annotations - a set of OWLAnnotations to get the value of
        Returns:
        a set of the value strings
      • extendsAxiomTypes

        public static boolean extendsAxiomTypes​(org.semanticweb.owlapi.model.OWLAxiom axiom,
                                                Set<Class<? extends org.semanticweb.owlapi.model.OWLAxiom>> axiomTypes)
        Given an OWLAxiom and a set of OWLAxiom class, determine if the axiom's class is an extension of at least one of the given set.
        Parameters:
        axiom - the OWLAxiom to check
        axiomTypes - classes of axioms desired
        Returns:
        true if axiom is an instantiation of one of the classes in set
      • extendsAxiomTypes

        public static boolean extendsAxiomTypes​(Class<? extends org.semanticweb.owlapi.model.OWLAxiom> axiom,
                                                Set<Class<? extends org.semanticweb.owlapi.model.OWLAxiom>> axiomTypes)
        Given an OWLAxiom class and a set of OWLAxiom classes, determine if the axiom class provided extends at least one of the classes in the set.
        Parameters:
        axiom - the OWLAxiom class to check
        axiomTypes - classes of axioms desired
        Returns:
        true if axiom class extends one of the classes in set
      • removeImports

        public static void removeImports​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Given an ontology, remove the import declarations.
        Parameters:
        ontology - OWLOntology to remove imports from
      • removeOntologyAnnotations

        public static void removeOntologyAnnotations​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Remove all annotations on this ontology. Just annotations on the ontology itself, not annotations on its classes, etc.
        Parameters:
        ontology - the ontology to modify
      • renderManchester

        public static String renderManchester​(org.semanticweb.owlapi.model.OWLObject object,
                                              org.semanticweb.owlapi.util.ShortFormProvider provider)
        Render a Manchester string for an OWLObject.
        Parameters:
        object - OWLObject to render
        provider - ShortFormProvider to resolve entities
        Returns:
        String rendering of OWLObject based on renderer type
      • renderManchester

        public static String renderManchester​(org.semanticweb.owlapi.model.OWLObject object,
                                              org.semanticweb.owlapi.util.ShortFormProvider provider,
                                              RendererType rt)
        Render a Manchester string for an OWLObject. The RendererType will determine what Manchester OWL Syntax renderer will be created.
        Parameters:
        object - OWLObject to render
        provider - ShortFormProvider to resolve entities
        rt - RendererType to use to render Manchester
        Returns:
        String rendering of OWLObject based on renderer type
      • setOntologyIRI

        public static void setOntologyIRI​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                          String ontologyIRIString,
                                          String versionIRIString)
        Set the ontology IRI and version IRI using strings.
        Parameters:
        ontology - the ontology to change
        ontologyIRIString - the ontology IRI string, or null for no change
        versionIRIString - the version IRI string, or null for no change
      • setOntologyIRI

        public static void setOntologyIRI​(org.semanticweb.owlapi.model.OWLOntology ontology,
                                          org.semanticweb.owlapi.model.IRI ontologyIRI,
                                          org.semanticweb.owlapi.model.IRI versionIRI)
        Set the ontology IRI and version IRI.
        Parameters:
        ontology - the ontology to change
        ontologyIRI - the new ontology IRI, or null for no change
        versionIRI - the new version IRI, or null for no change
      • trimOntology

        public static void trimOntology​(org.semanticweb.owlapi.model.OWLOntology ontology)
        Given an ontology, remove any dangling entities.
        Parameters:
        ontology - the ontology to trim