Skip to content

Backport fix for #1080 to 5.1.1 + unit tests - #1178

Closed
Artemis-IA wants to merge 2 commits into
owlcs:version5from
Artemis-IA:fix-1080-from-5.1.1
Closed

Artemis-IA wants to merge 2 commits into
owlcs:version5from
Artemis-IA:fix-1080-from-5.1.1

Conversation

@Artemis-IA

Copy link
Copy Markdown

Summary

Problem

When an ontology document declares owl:imports AND has an annotation whose rdf:resource value equals the ontology's own IRI (a self-referencing annotation such as rdfs:isDefinedBy), OWL API incorrectly assigns an imported ontology's IRI as the main ontology IRI.

This affects:

Self-referencing annotations like rdfs:isDefinedBy → <ontology-itself> are valid and standard semantic web practice. The bug is in the RDF/XML parser, not in the ontology.

Root Cause

In OWLRDFConsumer.chooseAndSetOntologyIRI(), candidate IRIs are removed if they appear as the object of an annotation assertion. However, the subject of owl:imports (i.e., the importing ontology itself) should never be removed from candidates, even if it also appears as an annotation object.

Fix

Two files modified (same as the original commit b1768cdf):

  1. OWLRDFConsumer.java: Track IRIs used as subject of owl:imports in a new ontologySubImportIRIs set. In chooseAndSetOntologyIRI(), don't remove a candidate IRI if it's in this set.
  2. TripleHandlers.java: Call consumer.addOntology(s, true) when handling owl:imports triples to mark the subject as an import subject.

Tests

Added SelfReferenceAnnotationImportsTestCase.java with 6 tests:

Test Without fix With fix
testSelfReferenceWithImports ❌ FAIL ✅ PASS
testMultipleSelfReferencesWithImports ❌ FAIL ✅ PASS
testImportsWithoutSelfReference ✅ PASS ✅ PASS
testSelfReferenceWithoutImports ✅ PASS ✅ PASS
testAnnotationWithDifferentIRI ✅ PASS ✅ PASS
testSelfReferenceAsLiteral ✅ PASS ✅ PASS

The first two tests fail without the fix and pass with it. The other four are regression tests.

Motivation

OWL API 5.1.1 is still widely used (e.g., WebVOWL/OWL2VOWL pins this version). A Maven release (5.1.2) containing this fix would allow downstream projects to upgrade without API changes.

Test plan

  • Unit tests pass with the fix (6/6)
  • Unit tests fail without the fix (2 failures, 4 passes)
  • Functional test: WebVOWL with patched OWL API correctly displays https://w3id.org/earthsemantics/OSO instead of http://www.w3.org/ns/prov-o

Victor Chavez and others added 2 commits September 2, 2026 11:30
This fix adds a condition to check whether the parsed IRIs
are used as subject for the owl#imports. This fixes owlcs#1080
for owl api version 5.
@Artemis-IA

Copy link
Copy Markdown
Author

Closing this PR. We need to run more comprehensive tests across all OSO ontology versions before submitting. Will reopen once validation is complete.

@Artemis-IA Artemis-IA closed this Sep 2, 2026
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

Successfully merging this pull request may close these issues.

1 participant