owlcs / jfact

JFact repository
13 stars 8 forks source link

Equivalent classes not correctly inferred #16

Open matentzn opened 7 years ago

matentzn commented 7 years ago

Two equal definitions are not inferred to be equivalent.

Tried with jfact 4.0.1 and 5.0.1 (and the latest OWL API versions for those, 5.0.5 and 4.3.1). Used fr Pellet:

net.sourceforge.owlapi pellet-owlapi-ignazio1977 2.4.0-ignazio1977 owlapi-distribution net.sourceforge.owlapi
public static void main(String[] args) {

        try {
            OWLOntologyManager man = OWLManager.createOWLOntologyManager();
            OWLDataFactory df = man.getOWLDataFactory();
            IRI base = IRI.create("http://owl.api.tutorial#");

            OWLOntology o = man.createOntology();

            // Classes
            OWLClass pizza = df.getOWLClass(IRI.create(base + "Pizza"));
            OWLClass meatPizza = df.getOWLClass(IRI.create(base + "MeatPizza1"));
            OWLClass meatTopping = df.getOWLClass(IRI.create(base + "MeatTopping"));
            OWLClass meatPizza2 = df.getOWLClass(IRI.create(base + "MeatPizza2"));
            OWLObjectProperty hasTopping = df.getOWLObjectProperty(IRI.create(base + "hasTopping"));

            OWLEquivalentClassesAxiom meatPizza_def = df.getOWLEquivalentClassesAxiom(meatPizza,
                    df.getOWLObjectIntersectionOf(pizza, df.getOWLObjectSomeValuesFrom(hasTopping, meatTopping)));

            OWLEquivalentClassesAxiom meatPizza_def2 = df.getOWLEquivalentClassesAxiom(meatPizza2,
                    df.getOWLObjectIntersectionOf(pizza, df.getOWLObjectSomeValuesFrom(hasTopping, meatTopping)));

            man.addAxiom(o,meatPizza_def);
            man.addAxiom(o,meatPizza_def2);

            OWLReasoner r = new JFactFactory().createReasoner(o);
            r.precomputeInferences(InferenceType.CLASS_HIERARCHY);

            System.out.println("Equivalent classes of MeatPizza:");
            r.getEquivalentClasses(meatPizza).getEntities().forEach(System.out::println);
            System.out.println(r.isEntailed(df.getOWLEquivalentClassesAxiom(meatPizza, meatPizza2)));

            r = new PelletReasonerFactory().createReasoner(o);
            r.precomputeInferences(InferenceType.CLASS_HIERARCHY);

            System.out.println("Equivalent classes of MeatPizza:");
            r.getEquivalentClasses(meatPizza).getEntities().forEach(System.out::println);
            System.out.println(r.isEntailed(df.getOWLEquivalentClassesAxiom(meatPizza, meatPizza2)));

            //saveOntology(man, o, IRI.create(new File("D:\\onto\\test2.owl").toURI()));

        } catch (OWLOntologyCreationException e) {
            e.printStackTrace();
        }
    }
ignazio1977 commented 6 years ago

The problem is with the anonymous intersection class. The second axiom using it is erasing the first axiom using it - looking up for its equivalent classes only beings up MeatPizza2. Using a named class in place of the intersection makes the issue disappear.