middleware.shared_services¶
Shared in-process services for dataset sessions and run-local RDF term telemetry.
Classes¶
Mutable dataset state. |
|
Shared mutable dataset coordination boundary for middleware. |
|
Default in-memory run-local telemetry for asserted RDF term usage. |
Module Contents¶
- class middleware.shared_services.DatasetSession¶
Mutable dataset state.
This developer-facing session remains internal runtime infrastructure rather than copied agent state. The shared
DatasetRuntimeservice owns the active session for middleware that needs coordinated access to the same dataset.The
datasetis a mutablerdflib.Datasetobject, whose thread safety depends on the underlying store and the usage of transactions by client code. To avoid any unexpected behavior, all interactions with the dataset should be performed through theDatasetRuntimeservice.- dataset: rdflib.Dataset¶
- class middleware.shared_services.DatasetRuntime¶
Shared mutable dataset coordination boundary for middleware.
You MUST NOT assume that the synchronization primitives used by this runtime are re-entrant. That is, you MUST NOT invoke other
DatasetRuntimeinside any context managers provided by this class (e.g., the one provided by :dataset_write()).- specification: engine.api.ReasonerSpecification¶
- dataset_size() → int¶
Return the total quad count in the live dataset.
This method obtains a read lock on the runtime.
- dataset_write() → collections.abc.Generator[rdflib.Dataset, None, None]¶
Context manager for write access to the live dataset.
You MUST NOT mutate the dataset outside of this context manager. You MUST NOT invoke other
DatasetRuntimemethods INSIDE this context manager.This method obtains a write lock on the runtime.
- graph_size(context: axiom.common.ContextIdentifier | None = None) → int¶
Return the triple count in a named or default graph.
This method obtains a read lock on the dataset.
- replace_dataset() → None¶
Close the current dataset and start a fresh empty session.
This method obtains a write lock on the runtime.
- snapshot_dataset() → rdflib.Dataset¶
Return a deep copy of the live dataset.
This method obtains a read lock on the runtime.
- snapshot_graph(context: axiom.common.ContextIdentifier | None = None) → rdflib.Graph¶
Return a deep copy of a named or default graph.
This method obtains a read lock on the runtime.
- class middleware.shared_services.RunTermTelemetry¶
Default in-memory run-local telemetry for asserted RDF term usage.
Following DR-020 (preceded by DR-019 and DR-017), this data object is notified when terms are used by
DatasetMiddleware. Not yet implemented is usage byRDFVocabularyMiddlewareto be able to rank/boost terms in search results.If some more sophisticated search strategy is implemented, the application of this class will need to be revisited.
- record_asserted_terms(terms: collections.abc.Iterable[rdflib.URIRef]) → None¶
Increment per-IRI counts for terms asserted during the current run.
- asserted_term_count(term: rdflib.URIRef | str) → int¶
Return how many times
termwas recorded in this run.
- snapshot_asserted_term_counts() → collections.abc.Mapping[str, int]¶
Return a copy of asserted-term counts keyed by IRI string.