apache / jena

Apache Jena
https://jena.apache.org/
Apache License 2.0
1.12k stars 652 forks source link

ontapi: do not allow OntDisjoints with no items #2783

Closed sszuev closed 1 month ago

sszuev commented 1 month ago

Version

5.2.0

What happened?

this is bug, regression of 73699fc1b1268f97121d6e292dafdbd1849cd879 (the problem was found while running owlcs/ont-api tests)

When there is no items it is impossible to distinguish OntDisjoint.ObjectProperties and OntDisjoint.DataProperties, which currently leads to wrong situation when OntDisjoint.DataProperties treated as OntDisjoint.ObjectProperties (because the last one has more priority). Moreover, such OntDisjoints do not make sense, so there must be at least one element even for DL/FULL.

The test-case for catching problem:

        var m = ModelFactory.createDefaultModel().setNsPrefixes(PrefixMapping.Standard);
        var p1 = m.createResource("p1", OWL.DatatypeProperty);
        var p2 = m.createResource("p2", OWL.DatatypeProperty);
        var d = m.createResource().addProperty(RDF.type, OWL.AllDisjointProperties);
        var list = m.createList(p1, p2);
        d.addProperty(OWL.members, list);

        var ont = OntModelFactory.createModel(m.getGraph());
        var actual1 = ont.ontObjects(OntDisjoint.DataProperties.class).toList();
        Assertions.assertEquals(1, actual1.size());

        var actual2 = ont.ontObjects(OntDisjoint.ObjectProperties.class).toList();
        Assertions.assertEquals(0, actual2.size());

        var actual3 = ont.ontObjects(OntDisjoint.class).toList();
        Assertions.assertEquals(1, actual3.size());
        Assertions.assertEquals(OntDisjoint.DataProperties.class, OntModels.getOntType(actual3.get(0)));

Relevant output and stacktrace

No response

Are you interested in making a pull request?

Yes