简体   繁体   English

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

[英]Inconsistency and satisfiability of an OWL ontology in Java using Pellet reasoner

I am trying to see whether an ontology is consistent or not.我正在尝试查看本体是否一致。 The ontology can be consistent, but still, it might have some unsatisfiable classes.本体可以是一致的,但仍然可能有一些无法满足的类。 Let's call it Case A .我们称它为案例 A。

But my problem is, when the ontology can not pass the consistency test, ie, it is inconsisetnt ( Case B ).但我的问题是,当本体不能通过一致性测试时,即不一致(案例B )。 My problem is even I cannot get unsatifiable classes of the ontology in Case B .我的问题是,即使在Case B中我也无法获得无法满足的本体类。

My final aim is to process the unsatisfiable classes to make some changes to them and make the inconsistent ontology to the consistent ones.我的最终目标是处理不可满足的类以对其进行一些更改,并将不一致的本体变为一致的本体。 So, I can achieve my aim in Case A (I have access to the unsatisfiable classes), I process them and revise some of them.所以,我可以在案例 A中实现我的目标(我可以访问无法满足的类),我处理它们并修改其中的一些。 But, now, what can I do for Case B ?但是,现在,我能为案例 B做些什么呢?

The following code shows these two cases.以下代码显示了这两种情况。

   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
    }

For Case B , What can I do?对于案例 B ,我该怎么办? In here , it wrote:这里,它写道:

If you want to find the unsatisfiable classes, you just need to call the isSatisfiable method on all the classes: reasoner.isSatisfiable(className);如果要查找无法满足的类,只需对所有类调用 isSatisfiable 方法即可: reasoner.isSatisfiable(className);

I put the following code in Case B :我将以下代码放在案例 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");
            }
    }

but I get an error, as:但我收到一个错误,如:

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)

So how can I process the ontology in Case B ?那么如何处理案例 B中的本体呢?

Update更新

Based on the comments of @Ignazio, in the code of my question, in the place of //CASE B, I call this new function:根据@Ignazio 的评论,在我的问题代码中,在 //CASE B 的位置,我将其称为新的 function:

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!!!!!");
}

Even with this new function, no unsatisfiable calsses can be found!即使有了这个新的 function,也找不到不满意的课程!

I also tried the code in here that @Ignazio posted.我还尝试@Ignazio 发布的代码。 For the given exmple there, that code will be run in a few seconds, but for my small inconsistent ontology even after 1 day, no result would be printed.对于那里给定的示例,该代码将在几秒钟内运行,但对于我的小型不一致本体,即使在 1 天后,也不会打印任何结果。

Any more idea how to get unsatisfiable classes alongside with their justification sets?还有更多想法如何获得不满意的课程以及他们的理由集吗?

Inconsistent ontology means there are instances of unsatisfiable classes, or there are instances of two or more classes that are declared disjoint.不一致的本体意味着存在不可满足的类的实例,或者存在两个或多个被声明为不相交的类的实例。

(Possibly, there might be individuals declared to be of type owl:Nothing, but that's easy to detect and probably an error.) (可能有些人被声明为 owl:Nothing 类型,但这很容易检测到并且可能是一个错误。)

To figure out whether the inconsistency depends on unsatisfiable classes or not, you can try separating the abox and tbox - then check the tbox alone.要确定不一致是否取决于不可满足的类,您可以尝试将 abox 和 tbox 分开 - 然后单独检查 tbox。 You can list the axiom types that belong to the tbox with the convenience methods in AxiomType.您可以使用 AxiomType 中的便捷方法列出属于 tbox 的公理类型。

Update: Looking at the code, there are a few things to fix:更新:查看代码,有一些问题需要修复:

    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());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM