I want to programmatically get explanations for inferred axioms in consistent ontologies, in a similar manner that one can do in the Protégé UI. I cannot find any straightforward way. I have found the owlexplanation repo, but I cannot for the life of me solve the dependency issues to set up the owlexplanation
environment. I have also browsed the javadoc of owlapi regarding explanations (to avoid the other repo altogether), but I don't see anything useful beyond what I can already see browsing the Java source code.
I have thought of simply negating the inferred axiom, to get explanations through inconsistencies, but I would prefer something cleaner, and I am not sure this approach is correct anyway.
Other (possibly) useful context:
- I had used some Java years ago, but I now primarily use Python (I try to use OWL API with JPype and OWL in general with Owlready2).
- I am using HermiT reasoner (again through JPype) (according to build.xml file,
latest stableversion 1.3.8). - I have managed to get explanations for unsatisfiability and inconsistency in my setup, without
owlexplanation
, following this example from the HermiT source code. - I fell in the rabbit hole wanting to make a usable
.jar
file forowlexplanation
, in order to add it in my JPype classpath. My plan went sideways when I couldn't get the Java project to build in the first place. - I am using Intellij IDE.
I would appreciate any insight or tips.
UPDATE Jan 6, 2022:
I decided to try once more with the owlexplanation
code with a clean head so here is where I am at:
- Downloaded the source code from github and extracted the zip.
- Started IntelliJ and instead from "Creating a project from Existing sources", I clicked "Open" and selected the extracted directory.
- I built the project and it did successfully.
- From Maven tools, I run clean, validate, compile and test succesfully.
- If I run "package" Maven action, it throws as error that "The environment variable JAVA_HOME is not correctly set". The thing is that if I go File>Project Structure, I see that SDK is set to 11, it's not empty.
- Additionally, from the
pom.xml
file I get these problems:Plugin 'org.apache.maven.plugins:maven-gpg-plugin:1.5' not found
Plugin 'org.sonatype.plugins:nexus-staging-maven-plugin:1.6.6' not found
UPDATE Jan 8, 2022: (Trying @Ignazio's answer)
I created a new IntelliJ project, and added the Maven dependencies @Ignazio mentioned (plus some others like slf4j
etc) and I got a working example (I think). Moving to my main project (using JPype), I had to manually download some .jars to include in the classpath (as maven can't be used here). These are the ones downloaded so far:
caffeine-3.0.5.jar hppcrt-0.7.5.jar org.semanticweb.hermit-1.4.5.519.jar slf4j-api-1.7.32.jar
commons-rdf-api-0.5.0.jar javax.inject-1.jar owlapi-distribution-5.1.9.jar slf4j-nop-1.7.32.jar
google-collect-1.0.jar owlexplanation-5.0.0.jar
Next, a NullPointerException
is thrown when trying to use loadOntologyFromOntologyDocument()
. I have tried re-downloading the jars as proposed here, but the Exception remains. Could it be that some .jar is missing? I downloaded them based on the thrown NoClassDefFoundError
that would occur.
This occurs with a common pizza.owl
file that it is otherwise fully working.
EDIT: I used mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR
to get the dependencies and by using OUTPUT_DIR as the classpath, the NullPointerException
is gone, so it seems I was indeed missing some .jar file.
For the record, I then got other issues (gen.getExplanations()
was throwing a NoSuchMethodError
error), but I have no more time for debugging this. I will ditch JPype, however convenient it is, and simply call Java from Python with subprocess
. These are (I guess) Jpype problems, so I am accepting Ignazio's answer as it solved my Java/OWL API/owlexplanation side of things.
owlexplanation
project. Is it theowlexplanation
code you used successfully?