owlcs / owlapi

OWL API main repository
828 stars 315 forks source link

same-as handling failing when more than 2. #994

Closed phillord closed 3 years ago

phillord commented 3 years ago

I have rendered the same ontology once as RDF and once OWX, using the OWL API version 4. The RDF version is missing most of the same as declarations, which the OWX version has.

I am seeing the same problem with the ttl output, so this seems a general issue.

I guess I need to update to version 5 soon:-)

<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
     xml:base="http://www.example.com/iri"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     ontologyIRI="http://www.example.com/iri"
     versionIRI="http://www.example.com/viri">
    <Prefix name="o" IRI="http://www.example.com/iri#"/>
    <Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
    <Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
    <Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
    <Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
    <Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
    <Declaration>
        <NamedIndividual IRI="#r"/>
    </Declaration>
    <Declaration>
        <NamedIndividual IRI="#s"/>
    </Declaration>
    <Declaration>
        <NamedIndividual IRI="#t"/>
    </Declaration>
    <Declaration>
        <NamedIndividual IRI="#u"/>
    </Declaration>
    <SameIndividual>
        <NamedIndividual IRI="#r"/>
        <NamedIndividual IRI="#s"/>
        <NamedIndividual IRI="#t"/>
        <NamedIndividual IRI="#u"/>
    </SameIndividual>
</Ontology>
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.example.com/iri#"
     xml:base="http://www.example.com/iri"
     xmlns:o="http://www.example.com/iri#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology rdf:about="http://www.example.com/iri">
        <owl:versionIRI rdf:resource="http://www.example.com/viri"/>
    </owl:Ontology>

    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Individuals
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    <!-- http://www.example.com/iri#r -->

    <owl:NamedIndividual rdf:about="http://www.example.com/iri#r">
        <owl:sameAs rdf:resource="http://www.example.com/iri#s"/>
    </owl:NamedIndividual>

    <!-- http://www.example.com/iri#s -->

    <owl:NamedIndividual rdf:about="http://www.example.com/iri#s"/>

    <!-- http://www.example.com/iri#t -->

    <owl:NamedIndividual rdf:about="http://www.example.com/iri#t"/>

    <!-- http://www.example.com/iri#u -->

    <owl:NamedIndividual rdf:about="http://www.example.com/iri#u"/>
</rdf:RDF>
ignazio1977 commented 3 years ago

Yet another case of special treatment for RDF/XML, sameAs with more than two individuals get broken up into multiple independent axioms (I believe to reuse RDF axioms). I was convinced these are covered in tests for all formats.

ignazio1977 commented 3 years ago

The test exist for three individuals and an annotation - without annotation tings work out differently.

ignazio1977 commented 3 years ago

Same bug exists for equivalent classes, data properties and object properties.

When rendering an entity a1, a RDFGraph object is created. This holds all the triples that need to be stored, and contains all triples required for one of these axioms, but they look like:

(a1 sameAs a2)
(a2 sameAs a3)...

Once the graph is created, standard procedure is to render starting from the a1 entity, then rendering all anonymous roots inside the element for a1 (on account of anonymous nodes having to be included here). This makes the rendering work for annotated axioms (because annotated axioms force a blank node to be created, and that acts as a hook to pull in all the required triples. But when no annotations are there, rendering a1 only pulls in the first triple (IRIs used in multiple places, like a2, are not followed in the graph - if they did, other axioms would be rendered in unexpected ways).

Only these four axiom types generate disjoint graphs of this sort - so, for these, the easiest fix is to store the information about other entities that need rendering and render them after a1 is completed.

phillord commented 3 years ago

Ah, yes, I had puzzled over that bit of the spec. It's a bit ambiguous. I had figured something like this would make sense:

<rdf:Description rdf:about="http://www.example.com/iri#s"
    <owl:sameAs rdf:resource="http://www.example.com/iri#p"/>
    <owl:sameAs rdf:resource="http://www.example.com/iri#q"/>
    <owl:sameAs rdf:resource="http://www.example.com/iri#r"/>
</rdf:Description>

but you are correct that this:

<owl:NamedIndividual rdf:about="http://www.example.com/iri#p">
    <owl:sameAs rdf:resource="http://www.example.com/iri#q"/>
</owl:NamedIndividual>

<rdf:Description rdf:about="http://www.example.com/iri#q">
    <owl:sameAs rdf:resource="http://www.example.com/iri#r"/>
</rdf:Description>

<rdf:Description rdf:about="http://www.example.com/iri#r">
    <owl:sameAs rdf:resource="http://www.example.com/iri#s"/>
</rdf:Description>

appears to be what the spec says.

On dear, this means some of my other rendering in horned-owl is wrong. What a pain!

Thanks for the fix, confirmed and running for me.