ontometer_corpus.network.construction¶
Ontology dependency network construction.
Builds a directed multigraph of the corpus from corpus.db plus the structural
sidecars written by the Phase 1 parse (see ontometer_corpus/pipeline/parse.py),
and writes it as two Parquet tables (corpus/network_nodes.parquet and
corpus/network_edges.parquet, see save_network) for downstream analysis. No
raw ontology is parsed here: the sidecars supply declaration counts used to
settle namespace ownership.
Two edge types, both derived straight from corpus_registry: - "import": declared owl:imports targets (column: imports) - "usage": namespaces an ontology actually references but doesn't own (column: referenced_namespaces, minus the namespaces it owns) A pair of ontologies connected by both gets both edges (hence MultiDiGraph) — the gap between "declared" and "actually used" is itself a signal.
Nodes are the corpus at its latest, canonical, successfully-parsed version per ontology (parse_status='ok' AND is_duplicate=0 AND is_latest_version=1 — the Phase 2 dedup only sets is_latest_version on parsed, non-duplicate rows, so it already implies the first two). Import/usage targets that don't resolve unambiguously to another row in the corpus become external leaf nodes (is_external=True, no row behind them) rather than being dropped — that is itself useful signal (what is referenced outside the corpus).
Usage edges resolve a namespace to the ontology that owns it. Several rows can
claim one namespace (a file that copies BFO terms declares them just as BFO
does), so claims are settled by the same rule the term network uses
(ontometer_corpus.network.entities.pick_home; modelling-language
namespaces such as SWRL are never owned): the ontology whose IRI names the
namespace, else a claimant declaring at least ten times as many terms in it
as any other (counted from the structural sidecars when the object store is
available); otherwise it stays external.
A node is identified by its ontology IRI, or by row:<id> when the row has
none or dedup found the IRI shared by distinct ontologies (node_id_of).
Every relation preserves all original evidence in reference_iris and its
cardinality in evidence_count. Usage edges also carry coarse
reference_kinds (language for RDF/OWL and the other representation
languages, metadata_or_identifier, malformed_or_local,
domain_vocabulary) and, when ontometer-corpus term-coupling has written
namespace_usage.parquet, how many distinct terms the source uses from the
target logically, as annotation, or only in declarations
(n_logical_terms, n_annotation_terms, n_declared_terms; see
ontometer_corpus.usage). Whether a vocabulary is reused for modelling is
read from those counts, not from a list of vocabularies.
Usage
uv run ontometer-corpus network --store /path/to/ontologies
or:¶
from ontometer_corpus.network.construction import build_network, load_network G = build_network(paths)
Attributes¶
Classes¶
Functions:¶
normalize_iri(iri)
¶
Normalise an IRI so two different-looking URLs for the same ontology compare equal: expands known XML entities, strips import-module suffixes, collapses version-specific path segments, and reads https as http. The result is a match key, not an IRI to store or display.
Source code in ontometer_corpus/network/construction.py
identity_iri(row)
¶
The row's ontology IRI if it identifies one ontology, else None.
Dedup sets shared_iri where distinct ontologies declare the same IRI
(placeholders such as http://iri/, a family of crop ontologies sharing
https://cropontology.org/rdf/); such an IRI names none of them.
Source code in ontometer_corpus/network/construction.py
node_id_of(row)
¶
build_network(paths=None)
¶
Build the ontology dependency graph from corpus.db (see module docstring for the node/edge model).
Source code in ontometer_corpus/network/construction.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 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 450 451 452 | |
save_network(G, paths=None)
¶
Write the graph as two Parquet tables: nodes and edges.
Parquet rather than a pickle, because loading a pickle executes arbitrary code; dictionary encoding keeps repeated namespace strings small.
Returns the (nodes, edges) paths.
Source code in ontometer_corpus/network/construction.py
load_network(paths=None)
¶
Rebuild the graph written by :func:save_network.
Raises:
| Type | Description |
|---|---|
ReleaseError
|
the corpus directory holds tables of another format. |
Source code in ontometer_corpus/network/construction.py
main(paths)
¶
Build the ontology dependency network from corpus.db and sidecars.