2

(Thanks of the comments, I am updating my code and question. Maybe it will be useful for others.)
Update
I am doing several edit processes in one ontology, at the end, I realized my ontology is inconsistent. Now I should get rid of all the unsatisfiable classes. I searched a lot, but there is no code to solve the inconsistencies.

Follow the approach of this paper and the library of Matthew Horridge and this, still I am struggling with this issue. I update my code and question, this is my solution. Is there any more suggestion for it?

What I am doing to solve the inconsistencies:

  1. Run a reasoner to find unsatisfiable classes
  2. From the all unsatisfiable classes, only find the root-unsatisfiable-classes
  3. Find explanation axioms for them
  4. Rank them and select the axioms which should be deleted (or rewrite) by the user

In my below code (using other existing solutions), I only need to implement rank function (the left open issue in inconsistency resolver).

For example, for my ontology, it has 25 unsatisfiable classes, which only 2 of them are the root of inconsistencies. These 2 root-classes, has 11 axioms (which I get them by getExplanations)

import java.io.File;
import java.util.Iterator;
import java.util.Set;
import org.semanticweb.owl.explanation.impl.rootderived.CompleteRootDerivedReasoner;
import org.semanticweb.owl.explanation.impl.rootderived.StructuralRootDerivedReasoner;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import com.clarkparsia.owlapi.explanation.BlackBoxExplanation;
import com.clarkparsia.owlapi.explanation.HSTExplanationGenerator;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;

public class InconsistencyTest {
 public static void main(String areg[]) throws Exception {

  File fileM = new File("address\\to\\my\\ontology\\myOnt.owl");
  OWLOntologyManager tempManager = OWLManager.createOWLOntologyManager();
  OWLOntology ont = tempManager.loadOntologyFromOntologyDocument(fileM);

  // run an reasoner
  OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
  OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ont);
  if (reasoner.isConsistent()) {
    // an ontology can be consistent, but have unsatisfiable classes.
    if (reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size() > 0) {
    // means: an ontology is consistent but unsatisfiable!
        System.out.println("The ontology FAILED satisfiability test with Pellet reasoner. \n Unsatisfiable classes detected: "
                + reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size());

        // This line return all unsatisfibaleClasses, but I do not need it
        // Iterator<OWLClass> aList=reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().iterator();

        // get root of unstaisfiableClasses, and get their explanations 
        BlackBoxExplanation bb = new BlackBoxExplanation(ont, reasonerFactory, reasoner);
        HSTExplanationGenerator multExplanator = new HSTExplanationGenerator(bb);

        CompleteRootDerivedReasoner rdr = new CompleteRootDerivedReasoner(tempManager, reasoner, reasonerFactory);
        for (OWLClass cls : rdr.getRootUnsatisfiableClasses()) {
            System.out.println("**** ROOT! " + cls);
            int maxEntailment = 5;
            Set<Set<OWLAxiom>> exSet = multExplanator.getExplanations(cls, maxEntailment);
            OWLAxiom deletedAxiom = rankAxiom(exSet);
            //return these axioms to user to delete or rewrite them
        }
    } else {
        System.out.println("The ontology PASSED the consistency test.");
    }
} else {
    System.out.println("The ontology FAILED the consistency test, please review the Axioms or debug using Protege");
    }
reasoner.dispose();
  }

Do I follow everything correct? Is there any suggestion for rank the axioms?
Very Thanks

Sami
  • 109
  • 2
  • 6
  • Computing the root unsatisfiable classes is explained in [this paper](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.456.3784&rep=rep1&type=pdf). By the way, this is already implemented in the Explanation API from Matthew Horridge, see the class [StructuralRootDerivedReasoner](https://github.com/matthewhorridge/owlexplanation/blob/master/src/main/java/org/semanticweb/owl/explanation/impl/rootderived/StructuralRootDerivedReasoner.java) – UninformedUser Oct 16 '18 at 06:36
  • Ranking by syntactic relevance is explained in your paper. I don't know why you're referring to HST in (4) ? HST is used to compute multiple explanations more efficiently. Nothing more. But it's not used for ranking. – UninformedUser Oct 16 '18 at 06:37
  • Once you ranked the axioms by whatever, what is done next? In general, the ranking was part of a UI to show the user the axioms that might be more appropriate for removal. In any case, a user was doing the final step. Moreover, it might be even better to rewrite the axiom - there is also a lots of research about this, e.g. strengthening or weakening an axiom in order to fix issues in an ontology. – UninformedUser Oct 16 '18 at 06:44
  • For (4), to find which axioms should be deleted, in the paper they explained to create an `HSTree`, which there is ranks value on the edges. In `HSTExplanationGenerator` when I asked to `getExplanations`, I see it build the `HSTree` and also for rank, it calculates the number of occurrences. But I do not know how to return the final solution from this tree. Thanks, I did not know about this function, so now I am using `getRootUnsatisfiableClasses` from `StructuralRootDerivedReasoner`. – Sami Oct 16 '18 at 06:53
  • Yes, thanks, once I find those axioms, I will delete them or re-write them in the next step. So, I edit my question regarding this issue. – Sami Oct 16 '18 at 06:56
  • Could you please tell me how should I find those erroneous axioms for unsatisfiable classes? I just need this issue (then I will delete/rewrite them in someway) – Sami Oct 16 '18 at 06:59
  • I don't understand? This line `Set> exSet = multExplanator.getExplanations(p, maxEntailment); ` already gives you a set of explanations. An explanation is a set of axioms together making the class unsatisfiable. And you got a set of a set of those axioms. – UninformedUser Oct 16 '18 at 08:44
  • I have 25 unsatisfiable classes, even if I get for all of them, 5 explanations with 10 axioms, then I need to know which axioms should be deleted, when I manually edit it, with deleting 3 axioms (or rewrite them), all unstaisfibale classes will be solved and the ontology is not anymore inconsistent. So I want to find those three axioms. – Sami Oct 16 '18 at 11:10
  • You can't determine which to remove automatically / I mean *how* should this be possible? This requires domain knowledge and that's why in the end a human has to decide on whether removing an axiom makes sense, or not. The only thing you could do is to rank among the axioms of all explanations by some metric. And it's your turn to develop such a metric. There is no perfect one because it's just impossible. A metric on syntactic relevance is described in the paper I linked to in my first comment – UninformedUser Oct 16 '18 at 11:19

0 Answers0