middleware.shared_services ========================== .. py:module:: middleware.shared_services .. autoapi-nested-parse:: Shared in-process services for dataset sessions and run-local RDF term telemetry. Classes ------- .. autoapisummary:: middleware.shared_services.DatasetSession middleware.shared_services.DatasetRuntime middleware.shared_services.RunTermTelemetry Module Contents --------------- .. py:class:: DatasetSession Mutable dataset state. This developer-facing session remains internal runtime infrastructure rather than copied agent state. The shared :class:`DatasetRuntime` service owns the active session for middleware that needs coordinated access to the same dataset. The :attr:`dataset` is a mutable :class:`rdflib.Dataset` object, 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 the :class:`DatasetRuntime` service. .. py:attribute:: dataset :type: rdflib.Dataset .. py:class:: 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 ``DatasetRuntime`` inside any context managers provided by this class (e.g., the one provided by ::meth:`dataset_write`). .. py:attribute:: specification :type: rdflib_reasoning.engine.api.ReasonerSpecification .. py:method:: dataset_size() -> int Return the total quad count in the live dataset. This method obtains a read lock on the runtime. .. py:method:: 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 ``DatasetRuntime`` methods INSIDE this context manager. This method obtains a write lock on the runtime. .. py:method:: graph_size(context: rdflib_reasoning.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. .. py:method:: replace_dataset() -> None Close the current dataset and start a fresh empty session. This method obtains a write lock on the runtime. .. py:method:: snapshot_dataset() -> rdflib.Dataset Return a deep copy of the live dataset. This method obtains a read lock on the runtime. .. py:method:: snapshot_graph(context: rdflib_reasoning.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. .. py:class:: 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 :class:`DatasetMiddleware`. Not yet implemented is usage by :class:`RDFVocabularyMiddleware` to 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. .. py:method:: record_asserted_terms(terms: collections.abc.Iterable[rdflib.URIRef]) -> None Increment per-IRI counts for terms asserted during the current run. .. py:method:: asserted_term_count(term: rdflib.URIRef | str) -> int Return how many times ``term`` was recorded in this run. .. py:method:: snapshot_asserted_term_counts() -> collections.abc.Mapping[str, int] Return a copy of asserted-term counts keyed by IRI string.