Evaluating WHY an ontology is inconsistent

76 views
Skip to first unread message

Kenny Cason

unread,
Jun 14, 2019, 10:04:20 AM6/14/19
to HermiT Users
I have an ontology file that Protege (v5.5.0, using HermiT) thinks is consistent. But, a java program with the same version of HermiT does not. The isConsistent() call comes back as false and the program crashes if I try to reason with it anyway.

Is there a way (programmatically, CLI, etc) to determine WHY there seems to be an inconsistency?

Kenny Cason

unread,
Jun 14, 2019, 4:22:20 PM6/14/19
to HermiT Users
BTW: I can import the same ontology into the HermiT Command Line Interface (CLI) and it process just fine, no inconsistency flagged.

But, in Java, the ontology is deemed inconsistent!
See my inline comments below:

public void createReasoner(OWLOntology ont) {

HxReasonerFactory factory = new HxReasonerFactory();

// do NOT crash when ont is inconsistent. This has NO effect :-(
Configuration config = new Configuration();
config.throwInconsistentOntologyException = false;

reasoner = factory.createReasoner(ont, config); // At this point in the debugger reasoner.m_isConsistent is null

System.out.println("---------------------------------------------------------");
System.out.println("\nHxReasoner.createReasoner: reasoner is: " + reasoner.getReasonerName() + " v" + reasoner.getReasonerVersion().toString());

if (!reasoner.isConsistent()) { // At this point in the debugger reasoner.m_isConsistent is true
System.out.println("---------------------------------------------------------");
System.out.println("HxReasoner.precompute: The Ontology is inconsistent!!!");
}
System.out.println("---------------------------------------------------------");
}

Ignazio Palmisano

unread,
Jun 14, 2019, 4:26:34 PM6/14/19
to Kenny Cason, HermiT Users
The owlexplanation library is used in Protege to determine
explanations for axiom inference, and that includes explaining
inconsistencies. See
https://search.maven.org/search?q=g:net.sourceforge.owlapi%20AND%20a:owlexplanation&core=gav
for the dependencies and check out
https://github.com/matthewhorridge/owlexplanation for examples.

Cheers,
Ignazio

On Fri, 14 Jun 2019 at 15:04, Kenny Cason <kenny...@gmail.com> wrote:
>
> I have an ontology file that Protege (v5.5.0, using HermiT) thinks is consistent. But, a java program with the same version of HermiT does not. The isConsistent() call comes back as false and the program crashes if I try to reason with it anyway.
>
> Is there a way (programmatically, CLI, etc) to determine WHY there seems to be an inconsistency?
>
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/c15909b4-4634-4357-beaf-d8b5b480e09e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ignazio Palmisano

unread,
Jun 14, 2019, 4:31:45 PM6/14/19
to Kenny Cason, HermiT Users
I'm not clear on what HxReasonerFactory is. The HermiT factory is
called ReasonerFactory only.

Cheers,
I.
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/7d7d6c9b-06b5-4ebd-82e8-193d79ec721b%40googlegroups.com.

Kenny Cason

unread,
Jun 14, 2019, 4:34:47 PM6/14/19
to HermiT Users
For Clarification: HxReasoner is defined as:
class HxReasonerFactory extends org.semanticweb.HermiT.Reasoner

Kenny Cason

unread,
Jun 14, 2019, 4:37:22 PM6/14/19
to HermiT Users
Thanks, I'll try that!

Kenny Cason

unread,
Jun 24, 2019, 8:41:28 AM6/24/19
to HermiT Users
The link to the explanation library source code above states the following as the Maven dependency:

<dependency>
    <
groupId>net.sourceforge.owlapitools</groupId>
    <
artifactId>owlexplanation</artifactId>
    <
version>1.0.0</version>
</
dependency> But as far as I can tell that jar file does not exist there. I can compile it and use it as a local library but that is really a work-around. Do you have a better Maven entry for this jar file?

Birte Glimm

unread,
Jun 24, 2019, 10:05:37 AM6/24/19
to Kenny Cason, HermiT Users
I just use

<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlexplanation</artifactId>
<version>2.0.0</version>
</dependency>

Birte
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/44cf5c9e-e834-4405-974e-1cd076289056%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Prof. Dr. Birte Glimm Tel.: +49 731 50 24125
Inst. of Artificial Intelligence Secr: +49 731 50 24258
University of Ulm Fax: +49 731 50 24188
D-89069 Ulm birte...@uni-ulm.de
Germany

Kenny Cason

unread,
Jun 24, 2019, 12:29:19 PM6/24/19
to HermiT Users
Very helpful, vielen Dank!

BTW: what happened to the Reasoner.ReasonerFactory() class? My IDE says it is deprecated.
What is the current way to instantiate a HermitT reasoner?

Kenny Cason

unread,
Jun 24, 2019, 2:53:46 PM6/24/19
to HermiT Users
Now that I have owlexplanation compiling without errors I'm still unable to determine WHY my ontology is considered inconsistent. :-(

I have an ontology with 208 classes and Protege processes it just fine using the HermiT reasoner. No inconsistencies found.

But if I use the same ontology and the HermiT reasoner in Java it is flagged as inconsistent. I would like to know what is causing the inconsistency.
In both cases below the call to reasoner.isConsistent() is true. Before the call my debugger shows isConsistent=false in the reasoner meta-data.

I've tried determining the offending classes two ways, both have yielded unsatisfactory results.

Here is the first attempt, which yields an empty set.
It uses reasoner.getSubClasses(nothing, false):

   public void createReasoner(OWLOntology ont) {
        Configuration config=new Configuration();
        config.reasonerProgressMonitor = new HxProgressMonitor();
        config.ignoreUnsupportedDatatypes = false;
        config.throwInconsistentOntologyException = false;

        org.semanticweb.HermiT.Reasoner reasoner;
        reasoner = new Reasoner(config, ont);

        if (!reasoner.isConsistent()) {

            System.out.println("---------------------------------------------------------");
            System.out.println("HxReasoner.precompute: The Ontology is inconsistent!!!");
            OWLOntologyManager manager= OWLManager.createOWLOntologyManager();
            OWLDataFactory dataFactory=manager.getOWLDataFactory();
            OWLClass nothing = dataFactory.getOWLNothing();

            // Note: I've tried true and false, same result
            NodeSet<OWLClass> subClasses = reasoner.getSubClasses(nothing, false);
            System.out.println("\n" + subClasses.toString());
        }
    }


The output is:
NodeSet[]
--------------

My second attempt uses reasoner.getUnsatisfiableClasses() and returns every class in the ontology, including owl:thing and owl:nothing:

    public void precompute() {
        Configuration config=new Configuration();
        config.reasonerProgressMonitor = new HxProgressMonitor();
        config.ignoreUnsupportedDatatypes = false;
        config.throwInconsistentOntologyException = false;
        org.semanticweb.HermiT.Reasoner reasoner;
        reasoner = new Reasoner(config, ont);
        // Set the config to inference every type available
        Set<InferenceType> precompute = EnumSet.of(InferenceType.CLASS_HIERARCHY);
        precompute.addAll(reasoner.getPrecomputableInferenceTypes());
        if (!reasoner.isConsistent()) {
            System.out.println("---------------------------------------------------------");
            System.out.println("Here are the bad classes:\n");

            Node<OWLClass> badClasses = reasoner.getUnsatisfiableClasses();
            Iterator itr = badClasses.iterator();
            while (itr.hasNext()) {
                OWLClass myClass = (OWLClass)itr.next();
                System.out.println(myClass.toString());
            }

            System.out.println("---------------------------------------------------------");
        }
        // Do the actual inferencing
        reasoner.precomputeInferences(precompute.toArray(new InferenceType[precompute.size()]));
    }

The fact that Protege doesn't find the ontology inconsistent makes me think I am doing something wrong, but what?.
BTW: the ending call to reasoner.precomputeInferences(…) crashes with a null pointer exception.

Your help is greatly appreciated.


Ignazio Palmisano

unread,
Jun 24, 2019, 3:32:10 PM6/24/19
to Kenny Cason, HermiT Users
Can you share the ontology?

Cheers,
Ignazio
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/23ea2ce0-7dcd-4524-8c95-815dbe90370d%40googlegroups.com.

Ignazio Palmisano

unread,
Jun 24, 2019, 3:41:31 PM6/24/19
to Kenny Cason, HermiT Users
Unsatisfiable classes are both subclasses and superclasses of
owl:Nothing, so they end up in the equivalent classes category - try
looking for equivalent classes, you should get the same results as
unsatisfiable classes.

However, just having unsatisfiable classes won't be enough - the
ontology is inconsistent, which means one of these classes has an
instance. Since all your classes seem to be unsatisfiable, look for
all individuals - any of them might suggest why the ontology is
inconsistent.

Cheers,
Ignazio

On Mon, 24 Jun 2019 at 19:53, Kenny Cason <kenny...@gmail.com> wrote:
>>
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/23ea2ce0-7dcd-4524-8c95-815dbe90370d%40googlegroups.com.

Kenny Cason

unread,
Jun 24, 2019, 6:36:54 PM6/24/19
to HermiT Users
Unfortunately the ontology is confidential. ☹️

Birte Glimm

unread,
Jun 25, 2019, 3:28:35 AM6/25/19
to Kenny Cason, HermiT Users
I suggest you check HermiT's example, where Explanation.java shows how
to get explanations for both unsatisfiable classes and inconsistent
ontologies. I also attach the file for your convenience. Needless to
say that you need to adapt the path to the pizza ontology and possible
the Java package declaration depending on where you put the files...

Birte

On Tue, 25 Jun 2019 at 00:37, Kenny Cason <kenny...@gmail.com> wrote:
>
> Unfortunately the ontology is confidential. ☹️
>
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/1ba86b07-7e0d-45aa-b26e-f3fba5157167%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



Explanations.java
pizza.owl

Kenny Cason

unread,
Jun 25, 2019, 9:04:26 AM6/25/19
to HermiT Users
The HermiT Explanations.java is the first thing I tried. It worked well with the pizza ontology but when I fed it mine it ran for eight hours before I had to kill it.
Below is the second thing I tried to explain the inconsistency, it too ran and ran and never finished.

package emap.backend_apps.web.util;
import java.util.Set;
import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owl.explanation.impl.blackbox.checker.InconsistentOntologyExplanationGeneratorFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;

import org.semanticweb.owl.explanation.api.*;

public class ExplainInconsistentOntology  {

    public Set<Explanation<OWLAxiom>> wtf(OWLOntology ontology) {
        // First, we create an OWLOntologyManager object. The manager will load and
        // save ontologies.
        OWLOntologyManager manager=OWLManager.createOWLOntologyManager();
        // We will create several things, so we save an instance of the data factory
        OWLDataFactory dataFactory=manager.getOWLDataFactory();
        // Now we can start and create the reasoner. Since explanation is not natively supported by
        // HermiT and is realised in the OWL API, we need to instantiate HermiT
        // as an OWLReasoner. This is done via a ReasonerFactory object.
        OWLReasonerFactory factory = new ReasonerFactory(); // Get hold of a reasoner factory
        //
        // Create the explanation generator which uses reasoners provided by the specified
        // reasoner factory
        ExplanationGenerator<OWLAxiom> explainInconsistency = new
                InconsistentOntologyExplanationGeneratorFactory(factory,
                100000L).createExplanationGenerator(ontology);
        // Ask for an explanation of `Thing subclass of Nothing` - this axiom is entailed in any inconsistent ontology
        Set<Explanation<OWLAxiom>> explanations =
                explainInconsistency.getExplanations(dataFactory.getOWLSubClassOfAxiom(dataFactory
                .getOWLThing(), dataFactory.getOWLNothing()));
        System.out.println("TestExplanation.main() " + explanations);

        return explanations;
    }
}

Birte Glimm

unread,
Jun 25, 2019, 9:44:49 AM6/25/19
to Kenny Cason, HermiT Users
Well, then your ontology seems too complex for the explanation
generation code. Anyway, if HermiT via Protege works fine and HermiT
via command line/Java does not, my guess is that the problem is
related to unsupported datatypes. The configuration used for Protege
basically ignores unrecognized datatypes, whereas HermiT in normal
modes tries to makes as much sense of them as possible. This is just
speculation though, since I don't know whether your ontology uses
datatypes. If so, the inconsistency has not directly anything to do
with the classes. The HermiT debugger could help, but is not meant to
be used by non-experts, i.e. it shows directly HermiT's internal
representation (HermiT translates the ontology to logic clauses,
individuals are just numbers etc.). Summing up, mail support will
probably not get you much further :-(

Birte
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/65188c82-bdee-4d7a-b72d-6622e05b8c59%40googlegroups.com.

Ignazio Palmisano

unread,
Jun 25, 2019, 10:03:36 AM6/25/19
to Birte Glimm, Kenny Cason, hermit-users
Given that all your classes show up as unsatisfiable, one possibility is to try removing axioms and try again. If you find a small set of axioms that still reproduces the inconsistency, use that with the explanation code - it might prove more tractable.

Cheers,
Ignazio

Kenny Cason

unread,
Jun 25, 2019, 11:01:55 AM6/25/19
to HermiT Users
The weird thing is HermiT from the command line works fine, just like Protege:

$ java -jar HermiT.jar -U -k file:///test.owl
Classes equivalent to 'owl:Nothing':
        owl:Nothing
http://www.w3.org/2002/07/owl#Thing is satisfiable.

I'm going to dig into the command line code to see if I can determine what it is doing differently than what my Java program is doing.

One more thing: if I load the ontology into Protege, run the reasoner, then save that data as a file it should contain pre-inferenced data. If I then feed that file into the HermiT command line I get this result:

$ java -jar HermiT.jar -U -k file:///Inferred.owl
Exception in thread "main" java.lang.IllegalArgumentException: Non-simple property '<http://...a specific IRI is here>' or its inverse appears in asymmetric object property axiom.
        at org.semanticweb.HermiT.structural.ObjectPropertyInclusionManager.rewriteAxioms(Unknown Source)
        at org.semanticweb.HermiT.structural.OWLClausification.preprocessAndClausify(Unknown Source)
        at org.semanticweb.HermiT.Reasoner.loadOntology(Unknown Source)
        at org.semanticweb.HermiT.Reasoner.<init>(Unknown Source)
        at org.semanticweb.HermiT.Reasoner.<init>(Unknown Source)
        at org.semanticweb.HermiT.cli.CommandLine.main(Unknown Source)

This looks suspicious to me.

Ignazio Palmisano

unread,
Jun 25, 2019, 4:54:32 PM6/25/19
to Kenny Cason, HermiT Users
That's not suspicious. The inferred axioms generated with this process
cause this effect often. It could be considered a bug, but it's a
behaviour most reasoners exhibit. They're not designed to deal some
kind of axioms asserted explicitly in the knowledge base. I don't
believe this is related to the problem you're facing.

Cheers,
Ignazio
> --
> You received this message because you are subscribed to the Google Groups "HermiT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hermit-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hermit-users/b1bfbc0e-520d-40ff-a9a3-b39ec9575050%40googlegroups.com.

Kenny Cason

unread,
Jul 1, 2019, 1:40:27 PM7/1/19
to HermiT Users
Chalk this up to user error.
The ontology was first being read into Jena, then "converted" to an OWLOntology. Apparently the conversion isn't reliable, causing HermiT to consider the converted ontology as inconsistent. I pulled out all the Jena code and now HermiT is happy.
Reply all
Reply to author
Forward
0 new messages