engine.batch_dispatcher¶
Batching RDFLib store events for fixed-point reasoner execution.
Attributes¶
Classes¶
Base batch event carrying deduplicated triples for one graph context. |
|
Batch of triple additions delivered after fixed-point coalescing. |
|
Batch of triple removals delivered after fixed-point coalescing. |
|
A dispatcher that batches store events and drives fixed-point iteration. |
Module Contents¶
- engine.batch_dispatcher.logger¶
- class engine.batch_dispatcher.BatchEvent(events: set[axiom.common.Triple], context_id: axiom.common.ContextIdentifier)¶
Bases:
rdflib.events.EventBase batch event carrying deduplicated triples for one graph context.
- events: set[axiom.common.Triple]¶
- context_id: axiom.common.ContextIdentifier¶
- class engine.batch_dispatcher.TripleAddedBatchEvent(events: set[axiom.common.Triple], context_id: axiom.common.ContextIdentifier)¶
Bases:
BatchEventBatch of triple additions delivered after fixed-point coalescing.
- class engine.batch_dispatcher.TripleRemovedBatchEvent(events: set[axiom.common.Triple], context_id: axiom.common.ContextIdentifier)¶
Bases:
BatchEventBatch of triple removals delivered after fixed-point coalescing.
- class engine.batch_dispatcher.BatchDispatcher(*, source_dispatcher: rdflib.events.Dispatcher, backing_store: rdflib.store.Store)¶
Bases:
rdflib.events.DispatcherA dispatcher that batches store events and drives fixed-point iteration.
If a listener to a
rdflib.Storeis sensitive to reentrant event handlers, this dispatcher allows for batches of events to be handled without re-entrancy. Additionally, this dispatcher forwardsTripleAddedEventandTripleRemovedEventevents after deduplication; subscribers can assume that each event will be unique.Source-dispatcher contract (per DR-026)
The batch dispatcher subscribes its
_on_triple_addedand_on_triple_removedhandlers to a caller-suppliedsource_dispatcherrather than to the backing store’s dispatcher. The owner of the source dispatcher (in this codebase,RETEStorevia its private_raw_dispatcher) MUST emit oneTripleAddedEvent(respectivelyTripleRemovedEvent) per mutation, BEFORE performing the mutation, even when the triple is already present or absent. Pre-mutation semantics are required so that the dedup check_exists_in_storecorrectly reports “already present” for adds and “still present” for removes.The backing store reference is retained solely for the read-only
_exists_in_storededup check, which uses the standardStore.contexts(triple)API. The backing store’s own dispatcher is not consumed; events emitted there (for example byMemory.addviaStore.add(self, ...)) are ignored by the engine.Fixed-point procedure
If a
TripleAddedEventorTripleRemovedEventis received, it is added to the current batch for its context.If there are a nonzero number of batches for the context, the batch is popped and dispatched.
During dispatch, any additional events received for that context are added to the next batch for that context.
When the dispatch ends, we return to step 2.
Inference engine entrypoint
The entrypoint for the inference engine (e.g. RETE) is subscription to
TripleAddedBatchEvent(and optionallyTripleRemovedBatchEvent). Subscribers receive per-context batches and fixed point is achieved by the dispatcher’s loop. Reasoners SHOULD subscribe to these batch events and handle the batches accordingly (e.g. materialize derived triples).- backing_store: rdflib.store.Store¶