lacing.store.base#
IntervalAnnotationStore — the headline Pythonic API.
A MutableMapping[TimeInterval, list[Annotation]] facade with methods
named after Allen’s relations. See ANN-DOC §C (“a natural design target”)
and BACK-DOC §4.1.
The facade hides the index. Phase 0 ships MemoryStore over
intervaltree. Phase 1 adds SQLite + R*Tree (.annot) and PostgreSQL
tstzrangeGiST. The mapping interface is the same in all three.
Classes
|
Protocol for any interval-keyed annotation store. |
- class lacing.store.base.IntervalAnnotationStore(*args, **kwargs)[source]#
Bases:
ProtocolProtocol for any interval-keyed annotation store.
Conceptually a
MutableMapping[TimeInterval, list[Annotation]]: keys areTimeInterval; values are lists because multiple annotations can share an interval (different tiers, multiple annotators, soft labels).We use
Protocolrather than inheriting fromMutableMappingso backends (in-memory, SQLite, Postgres) can structurally conform without forcing a single class hierarchy. The mapping methods below match theMutableMappingABC; concrete backends likeMemoryStoreimplement the full interface.- contains(query)[source]#
Annotations whose interval strictly contains
query(Allendi).- Return type:
- extend(annotations)[source]#
Add many; equivalent to repeated
.addbut adapters can optimize.- Return type:
- lock(key)[source]#
Exclusive lock named
key, held for thewithblock.Scoped to this store’s data (for
PostgresStore, its owner and project): holders of the same key exclude each other, different keys do not. The reach of the exclusion is the backend’s:MemoryStoreexcludes threads of this process,SqliteStorealso other processes on the host,PostgresStoreevery client of the database, on any host. A holder that dies releases the lock. Not re-entrant.- Return type:
- relate(query, relations)[source]#
Annotations whose interval has any of the named
relationstoquery.Generic dispatch — useful when relations are computed at runtime.
- Return type:
- remove(annotation_id)[source]#
Remove and return the annotation with this id, or None if absent.
- Return type:
- tiers()[source]#
Registered tiers. Annotations may reference tiers not yet registered; callers decide whether that’s an error.
- update(annotation)[source]#
Replace the stored annotation that has
annotation.id, atomically.One commit: a concurrent reader sees the old annotation or the new one, never neither (
remove(id)thenadd(...)leaves a gap in between). The replacement may move to a different interval or tier. RaisesKeyErrorwhen no annotation has that id — useadd()for a new one.- Return type: