protegeproject / protege

Protege Desktop
http://protege.stanford.edu
Other
1.01k stars 231 forks source link

Ontology IRI is decoded incorrectly if annotation property subject and object use the ontology IRI #1181

Closed vChavezB closed 3 months ago

vChavezB commented 10 months ago

I found out that if the ontology is annotated with rdfs:isDefinedBy with an IRI value equal to the ontology IRI then Protege Editor displays the ontology iri as if was the last imported ontology.

How to reproduce

  1. Create a turtle file with this ontology
@prefix : <http://www.ontology_iri#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix untitled-ontology-232: <http://www.semanticweb.org/vc9917e/ontologies/2023/10/untitled-ontology-232#> .
@prefix www.ontology_iri_version: <http://www.ontology_iri_version#> .
@base <http://www.ontology_iri> .

<http://www.ontology_iri> rdf:type owl:Ontology ;
                           owl:versionIRI <http://www.ontology_iri_version> ;
                           owl:imports <http://www.co-ode.org/ontologies/pizza/2.0.0> ;
                           rdfs:isDefinedBy <http://www.ontology_iri> .

###  Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi

Open the file locally in protege

grafik

gouttegd commented 10 months ago

This looks like a problem in the OWL API, upstream of Protégé.

Minimal code to reproduce the problem outside of Protégé:

import java.io.File;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class Test {
    public static void main(String[] args) {
        OWLOntologyManager man = OWLManager.createConcurrentOWLOntologyManager();
        try {
            OWLOntology o = man.loadOntologyFromOntologyDocument(new File("sample.ttl"));
            System.out.printf("Ontology ID: %s\n", ontology.getOntologyID().getOntologyIRI().orNull());
        } catch (OWLOntologyCreationException e) {
            e.printStackTrace();
        }
    }
}

This yields the same result as what is shown in Protégé:

Ontology ID: http://www.co-ode.org/ontologies/pizza/2.0.0

Running the same code on a sample file that does not contain the rdfs:isDefinedBy annotation (or if that annotation has a value different from the ontology IRI) yields the normal expected result:

Ontology ID: http://www.ontology_iri
gouttegd commented 10 months ago

The problem is not specifically caused by rdfs:isDefinedBy: it seems any annotation can cause the same issue as long as its value is the same as the ontology IRI. For example, this file, with a rdfs:seeAlso annotation, triggers the issue as well:

@prefix : <http://www.ontology_iri#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix www.ontology_iri_version: <http://www.ontology_iri_version#> .
@base <http://www.ontology_iri> .

<http://www.ontology_iri> rdf:type owl:Ontology ;
                           owl:versionIRI <http://www.ontology_iri_version> ;
                           owl:imports <http://www.co-ode.org/ontologies/pizza/2.0.0> ;
                           rdfs:seeAlso <http://www.ontology_iri> .
gouttegd commented 10 months ago

Seems like an instance of an already reported bug: https://github.com/owlcs/owlapi/issues/1080

vChavezB commented 10 months ago

Thanks for the info. I think I found the bug in owl api https://github.com/owlcs/owlapi/issues/1080#issuecomment-1826175431

I will wait for a follow up on the owl api project.

vChavezB commented 10 months ago

Update: I have found the bug and made a pull request https://github.com/owlcs/owlapi/pull/1117

In the meanwhile the PR can be used to manually build the owl api distribution. I also provide the jar file from CI/CD in case anyone else wants to test it in Protege v5.6.3 (i.e. owl api version 4.5.26)

To test it just rename the jar file owlapi-osgidistribution-4.5.26.jar to owlapi-osgidistribution.jar and replace the one in the bundlesdirectory.

vChavezB commented 6 months ago

The PR I submitted has been accepted to the owlapi. This means that to fix this issue you can build the owlapi (branch version4) locally and replace the owlapi-osgidistribution.jar from the bundles directory.

vChavezB commented 4 months ago

I just saw that the owlapi has been updated to v4.5.29

https://github.com/protegeproject/protege/commit/e1b82ab189875f0e3ec6c0fb09ac560c3ebb086c

Will be waiting for the next release with bundled owlapi to test if the issue is now removed 👍

vChavezB commented 3 months ago

I have tested release 5.6.4 and can confirm that the bug is removed.