Skip to content

feat: add annotation_assertion_axioms() to SyncOntology and RDFLibOntology - #277

Merged
Demirrr merged 1 commit into
developfrom
worktree-issue-268-annotation-retrieval
Sep 7, 2026
Merged

Demirrr merged 1 commit into
developfrom
worktree-issue-268-annotation-retrieval

Conversation

@Demirrr

@Demirrr Demirrr commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #268. As the reporter put it: given a class :Student with an rdfs:label and rdfs:comment, there was no way to retrieve either annotation through owlapy's own API without dropping down to the OWLAPI Java object directly, or loading the ontology a second time with rdflib. Confirmed in code: RDFLibOntology.get_tbox_axioms()'s own docstring says annotation predicates are "silently skipped", and SyncOntology has no annotation-retrieval method at all -- get_tbox_axioms()/get_abox_axioms() never include annotation assertions, since OWLAPI itself categorizes them separately from TBox/ABox/RBox.

The maintainer agreed this needs no reasoning and is cheap to add (#268 (comment)). The hard part was already done: OWLAnnotationAssertionAxiom/OWLAnnotationProperty/OWLAnnotationValue exist, are fully type-checked (#272), and owlapi_mapper.py already round-trips them to/from Java -- it was just never exposed as a read method.

What's added

  • SyncOntology.annotation_assertion_axioms(entity) -- thin wrapper around OWLAPI's own OWLOntology.getAnnotationAssertionAxioms(subject). Verified end-to-end against a live JVM-backed ontology before writing the final implementation.
  • RDFLibOntology.annotation_assertion_axioms(entity) -- scans triples under the well-known annotation predicates (rdfs:label, rdfs:comment, rdfs:seeAlso, rdfs:isDefinedBy, owl:versionInfo, owl:deprecated, owl:priorVersion, owl:backwardCompatibleWith, owl:incompatibleWith) plus any predicate explicitly declared rdf:type owl:AnnotationProperty in the loaded graph. A blank-node annotation value (an anonymous individual) is skipped, matching how blank nodes are handled elsewhere in this class.

Both accept either an OWLEntity or an IRI directly. Write support (add_axiom(OWLAnnotationAssertionAxiom(...))) for RDFLibOntology remains unimplemented -- this PR is read-only, matching the issue's ask.

onto = SyncOntology("ontology.owl")
for a in onto.annotation_assertion_axioms(OWLClass(NS + "Student")):
    print(a.get_property(), "->", a.get_value())

Also updated .claude/rules/ontology-management.md and CHANGELOG.md.

Test plan

  • ruff check on all changed files, --line-length=200
  • PYTHONPATH=. pytest tests/test_sync_ontology_annotations.py tests/test_rdflib_ontology.py tests/test_sync_ontology.py -p no:warnings -q (101 passed)
  • PYTHONPATH=. pytest --ignore=tests/test_z_do_last_ebr_retrieval.py -p no:warnings -q (1337 passed, 25 skipped; the only failures are 3 pre-existing environment issues unrelated to this change, already flagged in earlier PRs)

Closes #268.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M1RdTi68z3rkZzTohwSZ5F

…ology

Closes #268: retrieving an entity's rdfs:label/rdfs:comment (or any other
annotation) previously required either dropping down to the OWLAPI Java
object directly, or loading the ontology a second time with rdflib --
get_tbox_axioms()/get_abox_axioms() never surfaced annotation assertions,
since OWLAPI itself doesn't categorize them as TBox/ABox/RBox (RDFLibOntology's
own get_tbox_axioms() docstring says as much: annotation predicates are
"silently skipped").

- SyncOntology.annotation_assertion_axioms(entity): thin wrapper around
  OWLAPI's own OWLOntology.getAnnotationAssertionAxioms(subject), verified
  against a live JVM-backed ontology.
- RDFLibOntology.annotation_assertion_axioms(entity): scans triples under
  the well-known annotation predicates (rdfs:label, rdfs:comment, rdfs:seeAlso,
  rdfs:isDefinedBy, owl:versionInfo, owl:deprecated, owl:priorVersion,
  owl:backwardCompatibleWith, owl:incompatibleWith) plus any predicate
  explicitly declared rdf:type owl:AnnotationProperty in the loaded graph.
  Blank-node annotation values (anonymous individuals) are skipped, matching
  how blank nodes are handled elsewhere in this class. Write support
  (add_axiom) for OWLAnnotationAssertionAxiom remains unimplemented.

Both accept either an OWLEntity or an IRI directly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M1RdTi68z3rkZzTohwSZ5F
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.40%. Comparing base (5851191) to head (ac15309).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
owlapy/owl_ontology.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #277      +/-   ##
===========================================
+ Coverage    83.34%   83.40%   +0.05%     
===========================================
  Files           67       67              
  Lines        12408    12496      +88     
===========================================
+ Hits         10342    10422      +80     
- Misses        2066     2074       +8     
Flag Coverage Δ
unittests 83.40% <95.45%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Demirrr
Demirrr merged commit 5967a68 into develop Sep 7, 2026
4 checks passed
@Demirrr
Demirrr deleted the worktree-issue-268-annotation-retrieval branch September 7, 2026 14:22
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.

Retrieval of annotations

2 participants