Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explanations for Inconsistent Ontologies with OWL API 5.1.14 #4

Open
mthl opened this issue May 20, 2020 · 3 comments
Open

Explanations for Inconsistent Ontologies with OWL API 5.1.14 #4

mthl opened this issue May 20, 2020 · 3 comments

Comments

@mthl
Copy link

mthl commented May 20, 2020

Hello,

I am trying to use this package for checking inconsistencies in an OWL 2 DL ontology. I am using OWL API 5.1.14 and owlexplanation 5.0.0 but I am failing to adapt an old example found on stackoverflow to OWL API v5.

Any help would be welcome.

@ignazio1977
Copy link
Owner

This version compiles on owlexplanation version 5:

OWLOntology ont = OWLManager.createOWLOntologyManager().createOntology();
OWLOntologyManager m = ont.getOWLOntologyManager();
OWLDataFactory df = m.getOWLDataFactory();
OWLClass class1 = df.getOWLClass(IRI.create("urn:test:class1"));
OWLClass class2 = df.getOWLClass(IRI.create("urn:test:class2"));
OWLIndividual i = df.getOWLNamedIndividual(IRI.create("urn:test:i"));
// create an inconsistent ontology by declaring an individual member of two disjoint classes
m.addAxiom(ont, df.getOWLDisjointClassesAxiom(class1, class2));
m.addAxiom(ont, df.getOWLClassAssertionAxiom(class1, i));
m.addAxiom(ont, df.getOWLClassAssertionAxiom(class2, i));
// create the explanation generator
ExplanationGenerator<OWLAxiom> explainInconsistency = new InconsistentOntologyExplanationGeneratorFactory(rf, 
// these are the two arguments needed - a data factory and a supplier of ontology managers.
    OWLManager.getOWLDataFactory(), ()->OWLManager.createOWLOntologyManager(),
    1000L).createExplanationGenerator(ont);
// Ask for an explanation of `Thing subclass of Nothing` - this axiom is entailed in any inconsistent ontology
Set<Explanation<OWLAxiom>> explanations = explainInconsistency.getExplanations(df.getOWLSubClassOfAxiom(df
    .getOWLThing(), df.getOWLNothing()));

@mthl
Copy link
Author

mthl commented May 20, 2020

Thanks for your quick reply,

I have indeed something that is compiling but failing at runtime with an Illegal state exception.

Exception in thread "main" java.lang.IllegalStateException: value cannot be null at this stage
	at org.semanticweb.owlapi.util.OWLAPIPreconditions.verifyNotNull(OWLAPIPreconditions.java:56)
	at org.semanticweb.owlapi.util.OWLAPIPreconditions.verifyNotNull(OWLAPIPreconditions.java:40)
	at uk.ac.manchester.cs.owl.explanation.ordering.ExplanationOrdererImplNoManager$SeedExtractor.getTarget(ExplanationOrdererImplNoManager.java:311)
	at uk.ac.manchester.cs.owl.explanation.ordering.ExplanationOrdererImplNoManager.getOrderedExplanation(ExplanationOrdererImplNoManager.java:174)
	at org.semanticweb.owl.explanation.api.Explanation.toString(Explanation.java:149)
	at java.base/java.lang.String.valueOf(String.java:2951)
	at java.base/java.io.PrintStream.println(PrintStream.java:897)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.w3id.Http.main(Http.java:41)

Here is the code I am running

package org.w3id;

import java.util.Set;

import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owl.explanation.api.Explanation;
import org.semanticweb.owl.explanation.api.ExplanationGenerator;
import org.semanticweb.owl.explanation.impl.blackbox.checker.InconsistentOntologyExplanationGeneratorFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class Http {
    public static void main(String[] args) throws Exception {
        OWLOntology ont = OWLManager.createOWLOntologyManager().createOntology();
        OWLOntologyManager m = ont.getOWLOntologyManager();
        OWLDataFactory df = m.getOWLDataFactory();
        OWLClass class1 = df.getOWLClass(IRI.create("urn:test:class1"));
        OWLClass class2 = df.getOWLClass(IRI.create("urn:test:class2"));
        OWLIndividual i = df.getOWLNamedIndividual(IRI.create("urn:test:i"));
        // create an inconsistent ontology by declaring an individual member of two disjoint classes
        m.addAxiom(ont, df.getOWLDisjointClassesAxiom(class1, class2));
        m.addAxiom(ont, df.getOWLClassAssertionAxiom(class1, i));
        m.addAxiom(ont, df.getOWLClassAssertionAxiom(class2, i));
        ReasonerFactory rf = new ReasonerFactory();
        // create the explanation generator
        ExplanationGenerator<OWLAxiom> explainInconsistency =
                new InconsistentOntologyExplanationGeneratorFactory(rf,
                        OWLManager.getOWLDataFactory(),
                        OWLManager::createOWLOntologyManager,
                        1000L).createExplanationGenerator(ont);
        // Ask for an explanation of `Thing subclass of Nothing` - this axiom is entailed in any inconsistent ontology
        Set<Explanation<OWLAxiom>> explanations = explainInconsistency.getExplanations(
                df.getOWLSubClassOfAxiom(df.getOWLThing(), df.getOWLNothing()));
        explanations.forEach(System.out::println);
    }
}

My dependency specification is the following

  <dependencies>
    <dependency>
      <groupId>net.sourceforge.owlapi</groupId>
      <artifactId>org.semanticweb.hermit</artifactId>
      <version>1.3.8.510</version>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.owlapi</groupId>
      <artifactId>owlapi-distribution</artifactId>
      <version>5.1.14</version>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.owlapi</groupId>
      <artifactId>owlexplanation</artifactId>
      <version>5.0.0</version>
    </dependency>
    <dependency>
      <groupId>net.sf.trove4j</groupId>
      <artifactId>core</artifactId>
      <version>3.1.0</version>
    </dependency>
  </dependencies>

trove4j seems to be implicitly required by HermiT.

@m0squito
Copy link

m0squito commented May 5, 2023

@mthl Were you able to make this work? I know it has been a while, but I got to the same "value cannot be null at this stage" exception with a very similar setup and code as yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants