ontometer_corpus.pipeline.db¶
SQLite corpus registry.
About
Defines the corpus_registry and fetch_attempts table schemas, provides a connection factory, and handles idempotent seeding from manifest.jsonl (Phase 0).
The corpus_registry is the single source of truth for the processing pipeline. One row per ontology file version, covering: - Raw file provenance (from manifest; Phase 0 seed) - Parse status and extracted metadata (Phase 1 parse) - Deduplication decisions (Phase 2 dedup)
The database lives in the corpus directory as <corpus>/corpus.db
(see CorpusPaths.db_path).
Columns added after the initial schema are applied to existing databases by _migrate_schema (guarded ALTER TABLE), so additive schema changes never need a re-seed. Registry metadata is projected to a field allowlist before storage, and parse errors are bounded (see MAX_PARSE_ERROR_CHARS).
Attributes¶
MAX_PARSE_ERROR_CHARS = 2000
module-attribute
¶
Functions:¶
get_connection(db_path)
¶
Open (or create) the SQLite corpus database.
Returns a connection with: - WAL journal for concurrent read safety - Row factory set to sqlite3.Row (column-name access) - Foreign keys enabled
Source code in ontometer_corpus/pipeline/db.py
create_schema(conn)
¶
Create all tables and indexes (idempotent — safe to call on every run).
seed_from_manifest(conn, manifest_path)
¶
Read manifest.jsonl and seed both tables from it:
- fetch_attempts — EVERY attempt (status ok and fail), so capture rates are queryable. Idempotent via UNIQUE(source_id, retrieval_date, status).
- corpus_registry — only successful attempts (status == 'ok'), one row per source_id. Idempotent on source_id (re-runs never duplicate rows).
A record without a status field is treated as successful ('ok').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Open SQLite connection with schema already created. |
required |
manifest_path
|
Path
|
Path to the manifest.jsonl written by the fetcher orchestrator. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Counts keyed |
dict
|
|
Source code in ontometer_corpus/pipeline/db.py
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 | |
fetch_capture_stats(conn)
¶
Return per-registry fetch capture statistics from fetch_attempts.
Each row has: source_registry, captured, failed, attempts, pct_captured. 'pct_captured' is captured / attempts as a percentage (one decimal place).
Source code in ontometer_corpus/pipeline/db.py
update_parse_ok(conn, row_id, *, parse_format, ontology_iri, ontology_version_iri, ontology_version_info, triple_count, class_count, property_count, individual_count, imports, content_hash, referenced_namespaces=None, own_namespaces=None, iri_source=None, declared_individual_count=None, skos_concept_count=None, licence=None)
¶
Write a successful parse result back to corpus_registry.
Source code in ontometer_corpus/pipeline/db.py
update_parse_fail(conn, row_id, error)
¶
Write a parse failure back to corpus_registry.
Source code in ontometer_corpus/pipeline/db.py
update_parse_feed(conn, row_id, error)
¶
Write a feed parse status back to corpus_registry.
Source code in ontometer_corpus/pipeline/db.py
update_parse_unsupported(conn, row_id, error)
¶
Write an unsupported parse status back to corpus_registry.
Source code in ontometer_corpus/pipeline/db.py
update_duplicate(conn, row_id, canonical_entry_id)
¶
Mark a row as a duplicate pointing to the canonical winner.
Source code in ontometer_corpus/pipeline/db.py
reset_parse_state(conn)
¶
Clear every parse- and dedup-derived column so the next parse re-reads all rows.
Seeded columns and structural sidecars are kept; sidecars are write-once per file hash. Returns the number of rows reset.
Source code in ontometer_corpus/pipeline/db.py
log_dedup_exclusion(log_path, source_id, reason, detail='')
¶
Append a record of a row that was excluded (or only partially covered) by a dedup identity check, so there's a durable trail even though the exclusion itself only shows as an absence in corpus_registry.
Used for: rows with zero classes/properties excluded from Pass B's content-hash grouping (dedup.py).