2

(感谢评论,我正在更新我的代码和问题。也许对其他人有用。)
更新
我在一个本体中进行了几个编辑过程,最后,我意识到我的本体不一致。现在我应该摆脱所有无法满足的课程。我搜索了很多,但没有解决不一致的代码。

按照本文的方法和Matthew Horridge的图书馆和this,我仍然在这个问题上苦苦挣扎。我更新了我的代码和问题,这是我的解决方案。还有什么建议吗?

我正在做什么来解决不一致的问题:

  1. 运行推理器以查找不可满足的类
  2. 从所有不可满足的类中,只找到根不可满足的类
  3. 为它们找到解释公理
  4. 对它们进行排名并选择用户应该删除(或重写)的公理

在我下面的代码中(使用其他现有的解决方案),我只需要实现排名函数(不一致解决器中的未解决问题)。

例如,对于我的本体,它有 25 个不可满足的类,其中只有 2 个是不一致的根源。这 2 个根类,有 11 个公理(我得到它们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();
  }

我遵循的一切正确吗?对公理进行排名有什么建议吗?
很感谢

4

0 回答 0