Search code examples
owlontologyowl-api

Extract a fraction of an ontology that is expressed by OWL-Full


I have an ontology expressed in OWL-Full, however, I need a subset of this ontology in the OWL-QL profile. In other words, I want to remove all axioms that violate the OWL-QL. I wonder if there is a tool for that.


Solution

  • You can use the org.semanticweb.owlapi.profiles.Profiles enumeration to choose the profile you wish your ontology to conform to.

    OWLProfileReport report = Profiles.OWL2_QL.checkOntology(ontology)
    

    This will return an OWLProfileReport. It contains all the violations found. For each violation, you can either remove the axiom it references from the ontology:

    for (OWLProfileViolation v : report.getViolations()) {
        if (v.getAxiom() != null) {
            // OWLAPI 5 for this
            ontology.removeAxiom(v.getAxiom());
            // OWLAPI 4 for this
            ontology.getOWLOntologyManager().removeAxiom(ontology, v.getAxiom());
        }
    }
    

    or collect the repair changes from the violations (a list of changes to apply to the ontology to fix the violation) and then apply the changes.