pacfactory v0.1.6
PacFactory
A collection of semantic clients implementing the PAC architecture
Introduction
PacFactory extends the standard JsapApi used for semantic queries, introducing 4 semantic modules:
- Producer
- Consumer
- CachedConsumer
- SynchronousConsumer
Installation
Usage
Import semantic modules:
Producer
Create a producer:
Update Sepa with forced bindings:
Alternatively, a new Class that extends the Producer can be created to implement a custom producer:
Consumer
Create a consumer:
A Consumer contains an event emitter that fires on: first,added and received results. The event emitter can be listened to react to a notification:
The Consumer class implements the wrapper method "on", which can be used to write a cleaner code:
Alternatively, a new Class that extends the Consumer can be created to implement a custom consumer:
After declaring the event listeners, the consumer needs to subscribe to sepa to begin receiving notifications:
Cached Consumer
A Cached Consumer is an extension of a consumer. In addition to emitting an event on results, it contains a builtin Map, which can be used to temporarily store sepa notification, effectively acting as a buffer fo sparql notifications. While the CachedConsumer constructor provides a basic implementation for the modules, it is recommended to implement a custom CachedConsumer which has its own caching logic.
Define a cached consumer with custom caching logic:
Create the CachedConsumer and subscribe:
Get the internal cache:
Synchronous Consumer
Similarly to the CachedConsumer, the SynchronousConsumer has an internal cache which gets updated on notification. The difference is that the SynchronousConsumer has a second subscription: the SynchronizationFlag. The SyncFlag can be used to signal the end of a notification stream. Usually, the producer sends two or more messages containing triples, and the SyncConsumer starts caching the messages. Then, the producer sends a Production finished flag. The SyncConsumer provides a custom emitter for this event, the 'newsyncflag' event. Being an extension of a cached consumer, it is necessary to implement a custom caching logic and specify the syncflag bindings. Define a SyncConsumer with custom flag and caching logic:
Create a SynchronousConsumer:
Listen to the syncflag event, then subscribe to sepa: