Integration ports¶
The stable protocols integrations bind to. Each port is a
typing.Protocol. Codec, Exporter, and KnowledgeBase are
generic over their concrete payload and return types; StorageBackend
is non-generic and types its methods directly against str,
bytes, and bool. Either way no method returns a widened type.
Adapters bind a port to concrete didactic models and framework objects.
For the design see Concepts >
Integrations and ports.
lairs.integrations.ports.Codec ¶
Bases: Protocol
A bidirectional converter between an external format and lairs records.
A codec translates an external annotation format's spans and labels into lairs anchors and one of the seven annotation kinds; lairs owns the rest.
A codec is generic over the corpus-fragment model it produces and the record model it consumes, so neither method returns a widened type.
decode ¶
Decode an external source into a corpus fragment.
| PARAMETER | DESCRIPTION |
|---|---|
src
|
The external source (path text or raw bytes) to decode.
TYPE:
|
into
|
An existing corpus fragment to extend, if any.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Fragment
|
A corpus fragment of lairs records. |
encode ¶
Encode lairs records into the external format.
| PARAMETER | DESCRIPTION |
|---|---|
records
|
The lairs records to encode.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes or str
|
The encoded external representation. |
lairs.integrations.ports.Exporter ¶
Bases: Protocol
A data-plane exporter that emits a framework-native dataset.
An exporter consumes the flattened Arrow views plus the anchor resolver and
produces a target-framework object (for example a datasets.Dataset or a
torch.utils.data.Dataset). It is generic over the view, the export
specification, and the framework object it returns.
export ¶
Export an Arrow view into a framework-native dataset.
| PARAMETER | DESCRIPTION |
|---|---|
view
|
The Arrow view to export.
TYPE:
|
spec
|
An optional export specification (task template, columns).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
T_co
|
A framework-native dataset object. |
lairs.integrations.ports.KnowledgeBase ¶
Bases: Protocol
A connector to an external knowledge base.
Used to resolve, entity-link, reconcile, and enrich Layers records against external knowledge graphs and lexical resources. It is generic over the entity, candidate, and edge models it returns.
resolve ¶
Resolve an identifier or URI to an entity.
| PARAMETER | DESCRIPTION |
|---|---|
ref
|
The external identifier or URI to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Entity
|
The resolved entity (label, aliases, types, description, sameAs). |
search ¶
search(
text: str,
*,
lang: str | None = None,
types: Sequence[str] | None = None,
) -> list[Candidate]
Search for candidate entities (entity linking / reconciliation).
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The surface text to link.
TYPE:
|
lang
|
An optional language filter.
TYPE:
|
types
|
An optional set of type constraints.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list
|
A ranked list of candidate entities. |
neighbors ¶
Expand an entity's graph neighbourhood.
| PARAMETER | DESCRIPTION |
|---|---|
ref
|
The external identifier or URI to expand.
TYPE:
|
rels
|
An optional set of relation filters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list
|
The neighbouring edges. |
lairs.integrations.ports.StorageBackend ¶
Bases: Protocol
A pluggable storage backend for blobs and materialized views.
Used to back the blob cache and Parquet views with local or remote storage (for example an fsspec filesystem over s3, gcs, or local disk).
read_bytes ¶
Read an object's bytes by key.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The storage key to read.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The object's bytes. |
write_bytes ¶
Write an object's bytes by key.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The storage key to write.
TYPE:
|
data
|
The bytes to store.
TYPE:
|
exists ¶
Report whether a key exists.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The storage key to test.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|