ontocast.onto.ontology_apply¶
Apply ontology update deltas onto catalog ontologies by namespace ownership.
U → O*: complement inserts and catalog deletes are partitioned by
subject namespace onto writable catalog IRIs, then applied
(delete-then-insert) onto each ontology's freshest terminal — or an explicit
in-run base override.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
OntologyDelta
¶
Bases: BasePydanticModel
Net ontology change relative to a prompt snapshot.
inserts holds complement triples (U \ S); deletes holds
snapshot triples removed by GraphUpdate delete operations, destined for
propagation onto catalog terminals.
Source code in ontocast/onto/ontology_apply.py
Functions:¶
apply_partitioned_updates(partitioned_inserts, *, ontology_manager, normalize_units_fn, tools, partitioned_deletes=None, base_overrides=None)
¶
Apply each per-IRI delta (delete-then-insert) onto its catalog base.
The base is the catalog head for the IRI unless base_overrides supplies
an in-run artifact (e.g. the map-stage output a consolidation delta must
build on). normalize_units_fn is typically
:func:ontocast.agent.normalize_ontology.normalize_ontology_units.
Triples whose subject is the ontology IRI itself are dropped before the
apply, with the blank-node structures they point at, and counted as
apply_header_triples_dropped: the version header is written by code,
never by a render. Deletes keep the base's blank-node structures whole
(:func:_keep_structures_whole).
Returns (artifacts, metrics, applied_updates_by_iri) where the updates
are the GraphUpdates actually executed on each IRI, for its version label.
Source code in ontocast/onto/ontology_apply.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
build_namespace_owner_map(ontology_manager, writable_iris, base_overrides=None)
¶
Map namespace stem → catalog ontology IRI for writable sources.
An ontology owns the stems of its IRI and namespace. A namespace it only binds as a prefix is a weaker claim, honoured when no writable ontology owns that stem outright: an ontology binds the prefixes of the terms it refers to, and a statement about another ontology's term must not follow the prefix into the referring one. Between two claims of the same strength, the first writable IRI keeps the stem.
base_overrides supplies in-run artifacts (not yet registered with the
manager) whose namespaces must resolve, keyed by ontology IRI.
Source code in ontocast/onto/ontology_apply.py
complement_inserts(inserts, snapshot_graph)
¶
Return insert triples not already present in the prompt snapshot.
Source code in ontocast/onto/ontology_apply.py
partition_triples_by_namespace(triples, *, writable_iris, ontology_manager, current_domain, base_overrides=None)
¶
Partition delta triples onto writable catalog IRIs by namespace ownership.
Works for both insert and delete deltas. A triple belongs to the ontology that owns its subject. A named subject no writable ontology owns is never filed by its predicate or object: that would write an assertion about an individual, or an axiom about a term whose declaration went nowhere, into whichever ontology owns the property it uses.
Blank nodes are filed as structures (:mod:ontocast.onto.blank_structures): a
restriction or a list goes whole with the owner of the named subject that
points at it, so _:r owl:onProperty ext:p never lands in ext. A structure
nothing points at ([] a owl:AllDisjointClasses) goes to the single
owner of the named terms it uses; an owl:Axiom annotation goes with its
owl:annotatedSource. A structure whose anchors or terms have no single
writable owner is unattributed, together with the statements pointing at it.
An external ontology (outside current_domain) among writable_iris
owns its namespaces, so no other ontology claims them through a bound
prefix, but nothing is filed into it: what it would own is unattributed.
Returns (iri → graph, unattributed_triple_count).
Source code in ontocast/onto/ontology_apply.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
refile_fresh_statements(fresh, *, writable_iris, ontology_manager, current_domain, base_overrides=None)
¶
File a fresh ontology's statements by subject, as an update delta's are.
A fresh render writes a whole new ontology, but a statement in it about
another ontology's term belongs to that ontology. The header and every
statement :func:partition_triples_by_namespace files to fresh stay in
its graph; the rest leave it. Returns the statements another writable
ontology owns, to be applied there, and how many statements no writable
ontology owns (removed).