使用Pellet推理程序的Java中的OWL本体的一致性和可满足性

问题描述 投票:0回答:2

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

但是我的问题是,当本体不能通过一致性测试时,即它是没有意义的(情况B)。我的问题是,即使在案例B中,我也无法获得无法满足的本体分类。

我的最终目标是处理不满意的类,以对它们进行一些更改,并使不一致的本体成为一致的本体。因此,我可以在案例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中处理本体?

java ontology consistency owl-api reasoner
2个回答
0
投票

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

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

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


0
投票

更新

基于@Ignazio的评论,在我对问题的原始代码中,代替// 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()) {
        if (reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size() > 0) {
            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);
            }
            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中的代码。对于给定的示例,该代码将在几秒钟内运行,但是对于我的samll不完善的本体,即使在1天之后,也不会打印任何结果。

还有其他想法如何获取不满意的类及其理由集?

© www.soinside.com 2019 - 2024. All rights reserved.