PatternsSubscriber Class

The PatternsSubscriber class provides an abstraction ontologenius subscription mechanism.More...

Header: #include "ontologenius/PatternsSubscriber.h"
Namespace: onto

Public Functions

PatternsSubscriber(const std::string& name)
int subscribe (const std::string& pattern, const std::function<void(const std::string&)>& callback, int count = -1)
bool cancel(size_t id)
bool end()

Detailed Description

The PatternsSubscriber class provides an abstraction ontologenius subscription mechanism.

Querying a knowledge base is interesting but when one is waiting a given fact, pulling the knowledge base can be an issue. To solve that, Ontologenius provide a subscription mechanism allowing to subscribe not one only to given facts but also to patterns.

Public Function Documentation

PatternsSubscriber::PatternsSubscriber(const std::string& name)

Constructs a pattern subscriber.

Can be used in a multi-ontology mode by specifying the name of the ontology name. For classic use, name should be defined as "".

int PatternsSubscriber::subscribe(const std::string& pattern, const std::function<void(const std::string&)>& callback, int count = -1)

Subscribes to a given pattern linked to a callback. Patterns are in the form "[add]subject|property|object". Subject and object can be set as classes such as "[add]Cube|isOnTopOf|Table" to subscibe to any fact representing a cube being on a table. In addition, any of the four elements can be setted with question mark which can be read as "any". For example, "[?]?isOnTopOf|Table" to subscribe to any deletion or addition of any thing being on a entity of type Table.

The parameter count can be set to limit the subscription. Default parameter -1 corresponds to an unlimited subscription.

This function returns the subscription id. This later is only used to manually unsubscribe.

bool PatternsSubscriber::cancel(size_t id)

Manualy unsubscribe from a pattern using the corresponding subscription id.

Return True if the unsubscription suceeded.

bool PatternsSubscriber::end()

Tests if any subscription is still ongoing.