feat: add annotation_assertion_axioms() to SyncOntology and RDFLibOntology - #277
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #268. As the reporter put it: given a class
:Studentwith anrdfs:labelandrdfs: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", andSyncOntologyhas 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/OWLAnnotationValueexist, are fully type-checked (#272), andowlapi_mapper.pyalready 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 ownOWLOntology.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 declaredrdf:type owl:AnnotationPropertyin 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
OWLEntityor anIRIdirectly. Write support (add_axiom(OWLAnnotationAssertionAxiom(...))) forRDFLibOntologyremains unimplemented -- this PR is read-only, matching the issue's ask.Also updated
.claude/rules/ontology-management.mdandCHANGELOG.md.Test plan
ruff checkon all changed files,--line-length=200PYTHONPATH=. 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