ontometer_corpus.pipeline.dedup¶
Phase 2: Dedup.
About
Identifies duplicate ontologies across registries and marks non-canonical
rows in corpus_registry (is_duplicate=1, canonical_entry_id=
Version tracking: Different versions of the same ontology are preserved as separate canonical rows. Only rows that represent the SAME version fetched from multiple registries are collapsed as duplicates.
Passes, in order:
Pass 0 — Exact-byte dedup (file_hash) Groups all parse_status='ok' rows by file_hash (SHA-256 of the raw fetched bytes). Byte-identical files are unambiguously the same content regardless of any parsed metadata, so this needs no guard — it is the strongest, cheapest identity signal and collapses mirrors serving the exact same file before either semantic pass runs.
Pass A — Version-aware IRI dedup Groups all remaining is_duplicate=0 rows by (ontology_iri, ontology_version_iri). Rows with the same IRI but DIFFERENT version IRI are distinct versions and are NEVER marked as duplicates. Rows where ontology_version_iri IS NULL are preserved: a stable ontology IRI and class/property signature do not prove that two files are the same release, because relationships, individuals and annotations may change.
Pass B — Content-hash dedup Groups remaining rows by content_hash (the coarse class+property IRI set), but only an identical, non-null ontology_version_iri is strong enough to mark a duplicate. Rows with no classes or properties are excluded (they would all share the empty-set hash) and logged to dedup_exclusions.log.
Pass C — Release-family selection
Groups the remaining canonical rows by release family (the fetch
identifier before its final ::), then sets is_latest_version=1 on
the most recent representative in each family. Earlier releases stay
canonical so longitudinal analyses retain their full history.
Pass D — One latest row per ontology
Release families are per registry, so Pass C keeps one latest row per
registry: RO arrives as obo:ro, agroportal:RO and okg:Q28729320, each
a different release. Two latest rows are one ontology when either
holds:
* they share an ontology IRI (ontology_key: scheme, trailing
separator and OBO build artifacts such as x/x-full.owl or
x-base.owl ignored) and their declared terms (structural
sidecars) overlap: across registries, at least CONTAINMENT_SAME
of the smaller copy's terms are in the larger, since a registry
often holds an older, smaller release; within one registry, which
lists them as separate entries, the two sets must overlap by
CONTAINMENT_SAME of their union, so a module or extract published
under its parent's IRI stays its own ontology. Two releases under
the ontology's own OBO PURL that share a term, and a copy
declaring nothing, also join;
* one of them, or an earlier canonical release of its family,
declares the identical non-empty class and property set
(content_hash) as the other or one of its family's releases,
with or without an IRI (_same_terms): a copy of an old
release is that ontology even after a release renamed its terms.
Only the newest of each such group keeps is_latest_version (see
_newness_key). When an IRI covers several distinct ontologies (a
placeholder such as http://iri/, or a tool's default IRI reused by
several projects), the IRI is no identity: those rows get
shared_iri=1 and become their own network nodes (row:
Pass E — An ontology declares something A latest row declaring no class, property, individual or SKOS concept (an import-only aggregator, an empty submission, a failed conversion) loses is_latest_version: it is a pointer, not an ontology.
Winner election within a group (no registry is treated as inherently more authoritative than another): 1. Highest triple_count 2. Tie-break: latest retrieval_date (lexicographic ISO-8601) 3. Tie-break: lowest row id (first one seeded, purely for determinism)
Raw-byte, declared-IRI, content-hash, and release-family checks avoid a graph-isomorphism digest, whose rdflib canonicalisation can run unboundedly long on blank-node-dense graphs.
Attributes¶
CONTAINMENT_SAME = 0.5
module-attribute
¶
MIN_IDENTICAL_TERMS = 20
module-attribute
¶
Functions:¶
run_dedup(db_path, exclusion_log=None, sidecar_path=None)
¶
Run all deduplication passes on the corpus_registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path
|
Path to corpus.db. |
required |
exclusion_log
|
Path | None
|
Where rows excluded from Pass B are logged. Defaults to
|
None
|
sidecar_path
|
Callable[[str], Path] | None
|
Maps a content hash to its structural sidecar
( |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Summary counts keyed |
dict
|
|
dict
|
|
dict
|
|
Source code in ontometer_corpus/pipeline/dedup.py
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 258 259 260 261 262 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 453 454 | |
mark_latest_versions(conn)
¶
Flag the most-recent canonical release in each release family with is_latest_version=1; every other row is reset to 0, including rows that were flagged earlier and have since become duplicates or failed to parse.
Only successfully-parsed, non-duplicate rows (parse_status='ok',
is_duplicate=0) are considered — those are the usable canonical versions.
Experiments that don't care about history can then simply filter
WHERE is_latest_version=1. Idempotent: safe to re-run.
A stub release is flagged only when every release of its family is a stub; a canonical row competes with the newest date of its in-family duplicates.
Returns the number of ontologies flagged (one winner per group).
Source code in ontometer_corpus/pipeline/dedup.py
ontology_key(iri)
¶
Match key for the ontology an IRI names.
iri_key (scheme and trailing separator ignored), with an OBO build
artifact mapped to its ontology's PURL: …/obo/pco/pco-full.owl,
…/obo/oba/oba-base.owl, …/obo/go/extensions/go-plus.owl and
…/obo/subsets/envo-basic.obo.owl all read as …/obo/<id>.owl, with
the id lower-cased as OBO file names are. Other files under an OBO folder
(…/obo/uberon/chebi_import.owl) keep their own key.
Source code in ontometer_corpus/pipeline/dedup.py
release_day(row)
¶
The release date of a row: the date its version IRI adds to its ontology IRI, which the ontology itself publishes, else the registry's release date.
Source code in ontometer_corpus/pipeline/dedup.py
unify_latest_by_iri(conn, entities, inherited=None, folded=None)
¶
Pass D. Returns (rows unflagged as latest, IRIs marked shared, IRIs left
undecided for want of a readable sidecar). inherited maps a canonical
row id to the newest date among its in-family duplicates; folded, when
given, receives each unflagged row id mapped to the row id kept for it.
An undecided IRI contributes no IRI evidence and is never marked shared; its copies can still join others through an identical term set.
Source code in ontometer_corpus/pipeline/dedup.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
drop_stub_latest(conn, exclusion_log=None)
¶
Pass E. Unflag every latest row that declares no class, property,
individual or SKOS concept (_is_stub); returns the rows unflagged.
Each is logged to exclusion_log when given.