engine.batch_dispatcher

Batching RDFLib store events for fixed-point reasoner execution.

Attributes

logger

Classes

BatchEvent

Base batch event carrying deduplicated triples for one graph context.

TripleAddedBatchEvent

Batch of triple additions delivered after fixed-point coalescing.

TripleRemovedBatchEvent

Batch of triple removals delivered after fixed-point coalescing.

BatchDispatcher

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.Event

Base 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: BatchEvent

Batch of triple additions delivered after fixed-point coalescing.

class engine.batch_dispatcher.TripleRemovedBatchEvent(events: set[axiom.common.Triple], context_id: axiom.common.ContextIdentifier)

Bases: BatchEvent

Batch 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.Dispatcher

A dispatcher that batches store events and drives fixed-point iteration.

If a listener to a rdflib.Store is sensitive to reentrant event handlers, this dispatcher allows for batches of events to be handled without re-entrancy. Additionally, this dispatcher forwards TripleAddedEvent and TripleRemovedEvent events after deduplication; subscribers can assume that each event will be unique.

Source-dispatcher contract (per DR-026)

The batch dispatcher subscribes its _on_triple_added and _on_triple_removed handlers to a caller-supplied source_dispatcher rather than to the backing store’s dispatcher. The owner of the source dispatcher (in this codebase, RETEStore via its private _raw_dispatcher) MUST emit one TripleAddedEvent (respectively TripleRemovedEvent) 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_store correctly reports “already present” for adds and “still present” for removes.

The backing store reference is retained solely for the read-only _exists_in_store dedup check, which uses the standard Store.contexts(triple) API. The backing store’s own dispatcher is not consumed; events emitted there (for example by Memory.add via Store.add(self, ...)) are ignored by the engine.

Fixed-point procedure

  1. If a TripleAddedEvent or TripleRemovedEvent is received, it is added to the current batch for its context.

  2. If there are a nonzero number of batches for the context, the batch is popped and dispatched.

  3. During dispatch, any additional events received for that context are added to the next batch for that context.

  4. 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 optionally TripleRemovedBatchEvent). 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