【问题标题】:Inconsistency and satisfiability of an OWL ontology in Java using Pellet reasoner使用 Pellet 推理器的 Java 中 OWL 本体的不一致性和可满足性
【发布时间】:2020-04-20 14:02:54
【问题描述】:

我正在尝试查看本体是否一致。 本体可以是一致的,但仍然可能有一些无法满足的类。我们称之为案例A。

但我的问题是,当本体无法通过一致性测试时,即不一致(Case B)。我的问题是即使在案例 B 中我也无法获得无法满足的本体类。

我的最终目标是处理不可满足的类以对其进行一些更改,并将不一致的本体变为一致的本体。因此,我可以在 Case A 中实现我的目标(我可以访问无法满足的类),我会处理它们并修改其中的一些。但是,现在,我能为案例 B 做些什么呢?

下面的代码展示了这两种情况。

   OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
   OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(myOntology);

    if (reasoner.isConsistent()) {
        if (reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size() > 0) {
            System.out.println("ontology is consistent but has unsatisfiable classes! FAILED");
                    // CASE A
        } else {
            System.out.println("ontology is consistent and safe without any unsatisfiable classes! PASSED");
        }

    } else {
        System.out.println("ontology is inconsistent!FAILED");
                // CASE B
    }

对于案例 B,我能做什么? 在here,它写道:

如果要查找不可满足的类,只需对所有类调用 isSatisfiable 方法即可: reasoner.isSatisfiable(className);

我在案例B中加入了以下代码:

    Iterator<OWLClass> cAll = myOntology.getClassesInSignature().iterator();
    while (cAll.hasNext()) {
            OWLClass c = cAll.next();
            if (!reasoner.isSatisfiable(c)) {
                System.out.println("class " + c + "is not satisfibale");
            }
    }

但我得到一个错误,如:

Exception in thread "main" org.semanticweb.owlapi.reasoner.InconsistentOntologyException: Inconsistent ontology
    at com.clarkparsia.pellet.owlapiv3.PelletReasoner.convert(PelletReasoner.java:360)
    at com.clarkparsia.pellet.owlapiv3.PelletReasoner.isSatisfiable(PelletReasoner.java:890)

那么如何处理案例B中的本体呢?

更新

基于@Ignazio 的cmets,在我的问题代码中,在 //CASE B 的位置,我调用了这个新函数:

public static void run(OWLOntology myOnt) {
    // save the Tbox and Abox of the original ontology
    Set<OWLAxiom> originalTboxAxioms = myOnt.getTBoxAxioms(true);
    Set<OWLAxiom> originalAboxAxioms = myOnt.getABoxAxioms(true);

    // create new empty ontology
    String name = "local_path//name.owl";
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    File fileM = new File(name);
    OWLOntology newOntology = null;

    try {
        newOntology = manager.createOntology(IRI.create(fileM));
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
    }

    // add only Tboxes from the orginal ontology to the new one
    manager.addAxioms(newOntology, originalTboxAxioms);

    // checking the consistency of the new ontology which contain only tbox
    OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
    Configuration configuration = new Configuration();
    configuration.throwInconsistentOntologyException = false;
    OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(newOntology, configuration);

    if (reasoner.isConsistent()) {
       Set<OWLClass> unSat = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom();        
       if (unSat.size() > 0) {
            Iterator<OWLClass> unClassList = unSat.iterator();

            Set<OWLClass> listOfUnsatisfiableClasses = new HashSet<OWLClass>();
            while (unClassList.hasNext()) {
                /*
                 * if the unsatisfiable class appear in the original Abox,
                 * we mark it as an unsatisfiable class
                 */
                OWLClass myClass = unClassList.next();
                Iterator<OWLAxiom> iter = originalAboxAxioms.iterator();
                    while (iter.hasNext()){
                        OWLAxiom ax = iter.next();
                        if (ax.getClassesInSignature().contains(myClass)){
                            listOfUnsatisfiableClasses.add(myClass);    
                        }
                    }
            }
            System.out.println("number of unsatisfiable classes: " + listOfUnsatisfiableClasses.size());
        }
    }
    System.out.println("The ontology is inconsistent but does not have any unsatisfiable classes!!!!!");
}

即使有了这个新功能,也找不到不满意的课程!

我还尝试了@Ignazio 发布的here 中的代码。对于那里给定的示例,该代码将在几秒钟内运行,但对于我小的不一致本体,即使在 1 天后,也不会打印任何结果。

您知道如何将不可满足的类连同它们的理由集一起获得吗?

【问题讨论】:

  • 超过一天的运行时间没有任何输出意味着推理器在检索所有无法满足的类时陷入困境——这表明本体非常庞大。它是一个公开可用的本体吗?如果是这样,请链接它,以便我们可以看到您正在使用的相同数据。我查看了代码并指出了一些改进,但如果本体非常复杂以至于推理器无法检索到无法满足的类,它们不会改变结果。
  • 谢谢,我按照您的建议更新了代码。我的本体不可用,而且它很大,有近 150,000 个公理。还有一个问题:如果本体不一致,说明它没有任何模型。如果它是连贯的,则意味着它没有任何不可满足的类别和理由。对于这种情况,当本体没有任何模型,也没有不可满足的类时,我该怎么办?您能否为没有任何模型的本体提供更多解释(不一致)?
  • 对于一个大的复杂本体,没有可用的推理器可以检索到不可满足的类,或者这是Pellet推理器的问题?
  • 关于本体的复杂性有很多变量,以及推理器中的潜在错误。我无法判断另一个推理器是否会更好,这还取决于您使用的版本和本体配置文件。对于 EL++ 本体,ELK 可能是最佳选择;对于 OWL 2 DL,您可以尝试 Konclude 或 Openllet。
  • “它没有不可满足的类”这个定义不太有用——所有本体都有 owl:Nothing,因为它是语言的一部分。大多数情况下,无法满足的类可能是建模错误 - 几乎没有其他理由拥有它们。

标签: java ontology consistency owl-api reasoner


【解决方案1】:

不一致的本体意味着存在无法满足的类的实例,或者存在两个或多个被声明为不相交的类的实例。

(可能有些人被声明为 owl:Nothing 类型,但这很容易检测到并且可能是一个错误。)

要确定不一致是否取决于不可满足的类,您可以尝试将 abox 和 tbox 分开 - 然后单独检查 tbox。您可以使用 AxiomType 中的便捷方法列出属于 tbox 的公理类型。

更新:查看代码,有几处需要修复:

    if (reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size() > 0) {
        ^^^^^^^^^^^^^^ you're calling reasoner.getUnsatisfiableClasses() twice,
                       forcing the reasoner to do more work than necessary.
                       Store this set in a local variable, or skip the size check
                       (if the set is empty, the iterator will be empty
                       and you'll skip the while anyway.
      Iterator<OWLClass> unClassList = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().iterator();


        Set<OWLClass> listOfUnsatisfiableClasses = new HashSet<OWLClass>();
        while (unClassList.hasNext()) {
            /*
             * if the unsatisfiable class appear in the original Abox,
             * we mark it as an unsatisfiable class
             */
            OWLClass myClass = unClassList.next();
            if (originalAboxAxioms.contains(myClass))
                listOfUnsatisfiableClasses.add(myClass);
            ^^^^^^ this code is not doing what the comment is saying.
                   originalAboxAxioms contains abox axioms, not classes,
                   so you'll never get true as a result of this lookup.
                   Also, the classes will necessarily be part of the ontology,
                   so you can skip this altogether.
        }
        System.out.println("number of unsatisfiable classes: " + listOfUnsatisfiableClasses.size());
    }

【讨论】:

  • 谢谢。我可以得到Tbox,比如myOnt..getTBoxAxioms(true)。但是我能用它们做什么呢?你能解释一下吗?我还可以获得特殊类型的公理,例如myOnt.getAxioms(AxiomType.CLASS_ASSERTION);。但是我应该检查哪种类型的实体或公理?
  • 我还获取了我的所有课程并检查它们是否等同于 OLW:Nothing。那是对的吗? if (myClass.isBottomEntity()){System.out.println(c + " is equivalent to OWL:Nothing, thus we mark it as an unsatisfiable class." );} 如果是,那么我可以说,我的本体是不一致的,包括这些不能满足的类。如果是这样,我怎样才能得到他们的解释和理由集(原因无法处理)
  • 要检查一个类是否不可满足,您需要询问推理器 - 检查它是否是底部实体只是 OWLAPI 检查 IRI 是否与 owl:Nothing 但它不推理。
  • 类断言是声明哪些个体属于哪些类的 abox 公理;在您的情况下,我会采用 tbox 公理并将它们存储在一个单独的本体中,然后检查新本体的一致性(我希望它在这一点上是一致的)并寻找无法满足的类。如果您发现无法满足的类,请检查它们是否出现在原始本体的类断言中。如果他们这样做,他们就是你不一致的原因。
猜你喜欢
  • 2015-09-02
  • 2013-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多