knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::Reasoner Class Referenceabstract

#include <Reasoner.h>

Inheritance diagram for knowrob::Reasoner:
Collaboration diagram for knowrob::Reasoner:

Public Member Functions

 Reasoner ()
 
virtual ~Reasoner ()=default
 
auto & reasonerName () const
 
auto reasonerLanguage () const
 
auto storage () const
 
template<class T >
std::shared_ptr< T > getTypedStorage () const
 
ReasonerManagerreasonerManager () const
 
void pushWork (const std::function< void(void)> &fn)
 
void setStorage (const StoragePtr &storage)
 
virtual bool initializeReasoner (const PropertyTree &ptree)=0
 
virtual void unload ()
 
 Reasoner ()
 
virtual ~Reasoner ()=default
 
auto & reasonerName () const
 
auto reasonerLanguage () const
 
auto storage () const
 
template<class T >
std::shared_ptr< T > getTypedStorage () const
 
ReasonerManagerreasonerManager () const
 
void pushWork (const std::function< void(void)> &fn)
 
void setStorage (const StoragePtr &storage)
 
virtual bool initializeReasoner (const PropertyTree &ptree)=0
 
virtual void unload ()
 
- Public Member Functions inherited from knowrob::DataSourceHandler
 DataSourceHandler ()=default
 
virtual ~DataSourceHandler ()=default
 
void addDataHandler (const std::string &format, const DataSourceLoader &fn)
 
bool loadDataSource (const DataSourcePtr &dataSource)
 
bool hasDataHandler (const DataSourcePtr &dataSource) const
 
 DataSourceHandler ()=default
 
virtual ~DataSourceHandler ()=default
 
void addDataHandler (const std::string &format, const DataSourceLoader &fn)
 
bool loadDataSource (const DataSourcePtr &dataSource)
 
bool hasDataHandler (const DataSourcePtr &dataSource) const
 

Friends

class ReasonerManager
 

Additional Inherited Members

- Protected Member Functions inherited from knowrob::DataSourceHandler
virtual bool loadDataSourceWithUnknownFormat (const DataSourcePtr &)
 
virtual bool loadDataSourceWithUnknownFormat (const DataSourcePtr &)
 
- Protected Attributes inherited from knowrob::DataSourceHandler
std::map< std::string, DataSourceLoaderdataSourceHandler_
 

Detailed Description

A reasoner is a component that can infer new knowledge. The inference process may refer to extensional data which is stored in a DataBackend. Note that a reasoner is also a data source handler, i.e. data which is needed by the reasoner to operate which is not stored in a backend.

Definition at line 28 of file Reasoner.h.

Constructor & Destructor Documentation

◆ Reasoner() [1/2]

Reasoner::Reasoner ( )

Definition at line 16 of file Reasoner.cpp.

16  :
17  reasonerManager_(nullptr),
18  reasonerLanguage_(PluginLanguage::CPP)
19 {
20  static const auto undefinedName = std::make_shared<Atom>("undefined");
21  t_reasonerName_ = undefinedName;
22 }

◆ ~Reasoner() [1/2]

virtual knowrob::Reasoner::~Reasoner ( )
virtualdefault

◆ Reasoner() [2/2]

knowrob::Reasoner::Reasoner ( )

◆ ~Reasoner() [2/2]

virtual knowrob::Reasoner::~Reasoner ( )
virtualdefault

Member Function Documentation

◆ getTypedStorage() [1/2]

template<class T >
std::shared_ptr<T> knowrob::Reasoner::getTypedStorage ( ) const
inline
Returns
the storage associated with this reasoner.

Definition at line 52 of file Reasoner.h.

52  {
53  auto typed = std::dynamic_pointer_cast<T>(storage_);
54  if (!typed) throw ReasonerError("Storage is not of the expected type.");
55  return typed;
56  }

◆ getTypedStorage() [2/2]

template<class T >
std::shared_ptr<T> knowrob::Reasoner::getTypedStorage ( ) const
inline
Returns
the storage associated with this reasoner.

Definition at line 52 of file Reasoner.h.

52  {
53  auto typed = std::dynamic_pointer_cast<T>(storage_);
54  if (!typed) throw ReasonerError("Storage is not of the expected type.");
55  return typed;
56  }

◆ initializeReasoner() [1/2]

virtual bool knowrob::Reasoner::initializeReasoner ( const PropertyTree ptree)
pure virtual

Initialize a reasoner by configuring it with a property tree.

Parameters
ptreea PropertyTree object.

Implemented in knowrob::PrologReasoner, knowrob::MongologReasoner, knowrob::PrologReasoner, and knowrob::MongologReasoner.

◆ initializeReasoner() [2/2]

virtual bool knowrob::Reasoner::initializeReasoner ( const PropertyTree ptree)
pure virtual

Initialize a reasoner by configuring it with a property tree.

Parameters
ptreea PropertyTree object.

Implemented in knowrob::PrologReasoner, knowrob::MongologReasoner, knowrob::PrologReasoner, and knowrob::MongologReasoner.

◆ pushWork() [1/2]

void Reasoner::pushWork ( const std::function< void(void)> &  fn)

Evaluate a lambda function in a worker thread.

Parameters
fna function to be executed.

Definition at line 44 of file Reasoner.cpp.

44  {
45  auto runner = std::make_shared<ReasonerTask>(fn);
46  DefaultThreadPool()->pushWork(runner, [](const std::exception &e) {
47  KB_ERROR("Error in reasoner worker thread: {}", e.what());
48  });
49 }
#define KB_ERROR
Definition: Logger.h:28
std::shared_ptr< ThreadPool > DefaultThreadPool()
Definition: ThreadPool.cpp:19

◆ pushWork() [2/2]

void knowrob::Reasoner::pushWork ( const std::function< void(void)> &  fn)

Evaluate a lambda function in a worker thread.

Parameters
fna function to be executed.

◆ reasonerLanguage() [1/2]

auto knowrob::Reasoner::reasonerLanguage ( ) const
inline
Returns
the language of the reasoner.

Definition at line 42 of file Reasoner.h.

42 { return reasonerLanguage_; }

◆ reasonerLanguage() [2/2]

auto knowrob::Reasoner::reasonerLanguage ( ) const
inline
Returns
the language of the reasoner.

Definition at line 42 of file Reasoner.h.

42 { return reasonerLanguage_; }

◆ reasonerManager() [1/2]

ReasonerManager & Reasoner::reasonerManager ( ) const
Returns
the reasoner manager associated with this reasoner.

Definition at line 24 of file Reasoner.cpp.

24  {
25  if (reasonerManager_) {
26  return *reasonerManager_;
27  } else {
28  throw ReasonerError("No ReasonerManager has been assigned to the reasoner.");
29  }
30 }

◆ reasonerManager() [2/2]

ReasonerManager& knowrob::Reasoner::reasonerManager ( ) const
Returns
the reasoner manager associated with this reasoner.

◆ reasonerName() [1/2]

auto& knowrob::Reasoner::reasonerName ( ) const
inline
Returns
a term representing the reasoner name.

Definition at line 37 of file Reasoner.h.

37 { return t_reasonerName_; }

◆ reasonerName() [2/2]

auto& knowrob::Reasoner::reasonerName ( ) const
inline
Returns
a term representing the reasoner name.

Definition at line 37 of file Reasoner.h.

37 { return t_reasonerName_; }

◆ setStorage() [1/2]

void knowrob::Reasoner::setStorage ( const StoragePtr storage)
inline

Assign a storage to the reasoner.

Parameters
storagethe storage to assign.

Definition at line 73 of file Reasoner.h.

73 { storage_ = storage; }
auto storage() const
Definition: Reasoner.h:47

◆ setStorage() [2/2]

void knowrob::Reasoner::setStorage ( const StoragePtr storage)
inline

Assign a storage to the reasoner.

Parameters
storagethe storage to assign.

Definition at line 73 of file Reasoner.h.

73 { storage_ = storage; }

◆ storage() [1/2]

auto knowrob::Reasoner::storage ( ) const
inline
Returns
the storage associated with this reasoner.

Definition at line 47 of file Reasoner.h.

47 { return storage_; }

◆ storage() [2/2]

auto knowrob::Reasoner::storage ( ) const
inline
Returns
the storage associated with this reasoner.

Definition at line 47 of file Reasoner.h.

47 { return storage_; }

◆ unload() [1/2]

virtual void knowrob::Reasoner::unload ( )
inlinevirtual

Unload the reasoner, meaning that all static resources associated to this reasoner are released.

Reimplemented in knowrob::SWRLReasoner, knowrob::PrologReasoner, knowrob::MongologReasoner, knowrob::SWRLReasoner, knowrob::PrologReasoner, and knowrob::MongologReasoner.

Definition at line 85 of file Reasoner.h.

85 {}

◆ unload() [2/2]

virtual void knowrob::Reasoner::unload ( )
inlinevirtual

Unload the reasoner, meaning that all static resources associated to this reasoner are released.

Reimplemented in knowrob::SWRLReasoner, knowrob::PrologReasoner, knowrob::MongologReasoner, knowrob::SWRLReasoner, knowrob::PrologReasoner, and knowrob::MongologReasoner.

Definition at line 85 of file Reasoner.h.

85 {}

Friends And Related Function Documentation

◆ ReasonerManager

Definition at line 99 of file Reasoner.h.


The documentation for this class was generated from the following files: