knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::MongologReasoner Class Reference

#include <MongologReasoner.h>

Inheritance diagram for knowrob::MongologReasoner:
Collaboration diagram for knowrob::MongologReasoner:

Public Member Functions

 MongologReasoner ()
 
 ~MongologReasoner () override
 
bool initializeReasoner (const PropertyTree &cfg) override
 
const auto & knowledgeGraph () const
 
void unload () override
 
 MongologReasoner ()
 
 ~MongologReasoner () override
 
bool initializeReasoner (const PropertyTree &cfg) override
 
const auto & knowledgeGraph () const
 
void unload () override
 
- Public Member Functions inherited from knowrob::PrologReasoner
 PrologReasoner ()
 
 ~PrologReasoner () override
 
 PrologReasoner (const PrologReasoner &)=delete
 
bool setReasonerSetting (const TermPtr &key, const TermPtr &valueString)
 
bool consult (const std::filesystem::path &uri, const char *module={}, bool doTransformQuery=true)
 
bool load_rdf_xml (const std::filesystem::path &rdfFile)
 
PrologTerm transformGoal (const PrologTerm &goal)
 
std::list< TermPtrrunTests (const std::string &target)
 
bool evaluate (GoalPtr query) override
 
 PrologReasoner ()
 
 ~PrologReasoner () override
 
 PrologReasoner (const PrologReasoner &)=delete
 
bool setReasonerSetting (const TermPtr &key, const TermPtr &valueString)
 
bool consult (const std::filesystem::path &uri, const char *module={}, bool doTransformQuery=true)
 
bool load_rdf_xml (const std::filesystem::path &rdfFile)
 
PrologTerm transformGoal (const PrologTerm &goal)
 
std::list< TermPtrrunTests (const std::string &target)
 
bool initializeReasoner (const PropertyTree &cfg) override
 
bool evaluate (GoalPtr query) override
 
void unload () override
 
- Public Member Functions inherited from knowrob::GoalDrivenReasoner
 GoalDrivenReasoner ()
 
bool hasFeature (GoalDrivenReasonerFeature feature) const
 
void enableFeature (GoalDrivenReasonerFeature feature)
 
bool isRelationDefined (const PredicateIndicator &indicator)
 
bool isClassDefined (const std::string_view &iri)
 
void defineRelation (const PredicateIndicator &indicator)
 
void defineRelation (const IRIAtomPtr &iri)
 
void undefineRelation (const PredicateIndicator &indicator)
 
void defineClass (const IRIAtomPtr &iri)
 
void undefineClass (const IRIAtomPtr &iri)
 
const auto & definedRelations () const
 
const auto & definedClasses () const
 
 GoalDrivenReasoner ()
 
bool hasFeature (GoalDrivenReasonerFeature feature) const
 
void enableFeature (GoalDrivenReasonerFeature feature)
 
bool isRelationDefined (const PredicateIndicator &indicator)
 
bool isClassDefined (const std::string_view &iri)
 
void defineRelation (const PredicateIndicator &indicator)
 
void defineRelation (const IRIAtomPtr &iri)
 
void undefineRelation (const PredicateIndicator &indicator)
 
void defineClass (const IRIAtomPtr &iri)
 
void undefineClass (const IRIAtomPtr &iri)
 
const auto & definedRelations () const
 
const auto & definedClasses () const
 
- Public Member Functions inherited from knowrob::Reasoner
 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)
 
 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)
 
- 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
 

Protected Member Functions

std::string_view callFunctor () override
 
bool initializeDefaultPackages () override
 
void initializeReasonerStorage () override
 
std::string_view callFunctor () override
 
bool initializeDefaultPackages () override
 
void initializeReasonerStorage () override
 
- Protected Member Functions inherited from knowrob::PrologReasoner
virtual bool initializeGlobalPackages ()
 
bool loadDataSourceWithUnknownFormat (const DataSourcePtr &dataFile) override
 
AnswerYesPtr yes (const GoalPtr &query, const PrologTerm &rdfGoal, const PrologTerm &frameTerm)
 
AnswerNoPtr no (const GoalPtr &query)
 
PrologTerm getReasonerQuery (const PrologTerm &goal)
 
virtual bool initializeGlobalPackages ()
 
bool loadDataSourceWithUnknownFormat (const DataSourcePtr &dataFile) override
 
AnswerYesPtr yes (const GoalPtr &query, const PrologTerm &rdfGoal, const PrologTerm &frameTerm)
 
AnswerNoPtr no (const GoalPtr &query)
 
PrologTerm getReasonerQuery (const PrologTerm &goal)
 

Protected Attributes

std::shared_ptr< MongoKnowledgeGraphknowledgeGraph_
 
- Protected Attributes inherited from knowrob::PrologReasoner
std::shared_ptr< PrologBackendknowledgeGraph_
 
- Protected Attributes inherited from knowrob::GoalDrivenReasoner
std::set< PredicateIndicatordefinedRelations_
 
std::set< PredicateIndicatordefinedClasses_
 
int features_
 
- Protected Attributes inherited from knowrob::DataSourceHandler
std::map< std::string, DataSourceLoaderdataSourceHandler_
 

Additional Inherited Members

- Static Public Member Functions inherited from knowrob::PrologReasoner
static std::shared_ptr< NamedReasonergetDefinedReasoner (const term_t &t_reasonerManager, const term_t &t_reasonerModule)
 
static std::shared_ptr< NamedReasonergetDefinedReasoner (const term_t &t_reasonerManager, const term_t &t_reasonerModule)
 
- Static Protected Member Functions inherited from knowrob::PrologReasoner
static bool putQueryFrame (PrologTerm &frameTerm, const GraphSelector &frame)
 
static std::shared_ptr< GraphSelectorcreateAnswerFrame (const PrologTerm &plTerm)
 
static bool putQueryFrame (PrologTerm &frameTerm, const GraphSelector &frame)
 
static std::shared_ptr< GraphSelectorcreateAnswerFrame (const PrologTerm &plTerm)
 
- Static Protected Attributes inherited from knowrob::PrologReasoner
static bool isKnowRobInitialized_ = false
 

Detailed Description

Definition at line 21 of file MongologReasoner.h.

Constructor & Destructor Documentation

◆ MongologReasoner() [1/2]

MongologReasoner::MongologReasoner ( )

Definition at line 31 of file MongologReasoner.cpp.

◆ ~MongologReasoner() [1/2]

MongologReasoner::~MongologReasoner ( )
overridedefault

◆ MongologReasoner() [2/2]

knowrob::MongologReasoner::MongologReasoner ( )

◆ ~MongologReasoner() [2/2]

knowrob::MongologReasoner::~MongologReasoner ( )
override

Member Function Documentation

◆ callFunctor() [1/2]

std::string_view MongologReasoner::callFunctor ( )
overrideprotectedvirtual

Reimplemented from knowrob::PrologReasoner.

Definition at line 85 of file MongologReasoner.cpp.

85  {
86  static const auto call_f = "mongolog_call";
87  return call_f;
88 }

◆ callFunctor() [2/2]

std::string_view knowrob::MongologReasoner::callFunctor ( )
overrideprotectedvirtual

Reimplemented from knowrob::PrologReasoner.

◆ initializeDefaultPackages() [1/2]

bool MongologReasoner::initializeDefaultPackages ( )
overrideprotectedvirtual

Reimplemented from knowrob::PrologReasoner.

Definition at line 44 of file MongologReasoner.cpp.

44  {
45  static bool initialized = false;
46 
47  if (!initialized) {
48  initialized = true;
49  // load mongolog code once globally into the Prolog engine
50  consult(std::filesystem::path("reasoner") / "mongolog" / "__init__.pl",
51  "user", false);
52 
53  PL_register_foreign("mng_is_readonly_cpp",
54  2, (pl_function_t) pl_is_readonly2, 0);
55  PL_register_foreign("mng_db_name_cpp",
56  3, (pl_function_t) pl_db_name3, 0);
57  PL_register_foreign("mng_uri_cpp",
58  3, (pl_function_t) pl_uri3, 0);
59 
60  PL_register_foreign("mng_assert_triple_cpp",
61  9, (pl_function_t) pl_assert_triple_cpp9, 0);
62  }
63 
64  return true;
65 }
foreign_t pl_is_readonly2(term_t, term_t)
foreign_t pl_assert_triple_cpp9(term_t, term_t, term_t, term_t, term_t, term_t, term_t, term_t, term_t)
foreign_t pl_uri3(term_t, term_t, term_t)
foreign_t pl_db_name3(term_t, term_t, term_t)
bool consult(const std::filesystem::path &uri, const char *module={}, bool doTransformQuery=true)

◆ initializeDefaultPackages() [2/2]

bool knowrob::MongologReasoner::initializeDefaultPackages ( )
overrideprotectedvirtual

Reimplemented from knowrob::PrologReasoner.

◆ initializeReasoner() [1/2]

bool MongologReasoner::initializeReasoner ( const PropertyTree ptree)
overridevirtual

Initialize a reasoner by configuring it with a property tree.

Parameters
ptreea PropertyTree object.

Implements knowrob::Reasoner.

Definition at line 67 of file MongologReasoner.cpp.

67  {
68  if (!PrologReasoner::initializeReasoner(reasonerConfiguration)) return false;
69 
70  if (!knowledgeGraph_) {
71  knowledgeGraph_ = std::make_shared<MongoKnowledgeGraph>();
72  knowledgeGraph_->setVocabulary(std::make_shared<Vocabulary>());
73  knowledgeGraph_->initializeBackend(
77  );
79  KB_WARN("Falling back to default configuration for MongoDB!");
80  }
81 
82  return true;
83 }
#define KB_WARN
Definition: Logger.h:27
static const std::string COLL_NAME_TRIPLES
static const std::string DB_NAME_KNOWROB
static const std::string DB_URI_DEFAULT
std::shared_ptr< MongoKnowledgeGraph > knowledgeGraph_
bool initializeReasoner(const PropertyTree &cfg) override
ReasonerManager & reasonerManager() const
Definition: Reasoner.cpp:24

◆ initializeReasoner() [2/2]

bool knowrob::MongologReasoner::initializeReasoner ( const PropertyTree ptree)
overridevirtual

Initialize a reasoner by configuring it with a property tree.

Parameters
ptreea PropertyTree object.

Reimplemented from knowrob::PrologReasoner.

◆ initializeReasonerStorage() [1/2]

void knowrob::MongologReasoner::initializeReasonerStorage ( )
inlineoverrideprotectedvirtual

Reimplemented from knowrob::PrologReasoner.

Definition at line 50 of file MongologReasoner.h.

50 { knowledgeGraph_ = getTypedStorage<MongoKnowledgeGraph>(); }

◆ initializeReasonerStorage() [2/2]

void knowrob::MongologReasoner::initializeReasonerStorage ( )
inlineoverrideprotectedvirtual

Reimplemented from knowrob::PrologReasoner.

Definition at line 50 of file MongologReasoner.h.

50 { knowledgeGraph_ = getTypedStorage<MongoKnowledgeGraph>(); }

◆ knowledgeGraph() [1/2]

const auto& knowrob::MongologReasoner::knowledgeGraph ( ) const
inline

Definition at line 35 of file MongologReasoner.h.

35 { return knowledgeGraph_; }

◆ knowledgeGraph() [2/2]

const auto& knowrob::MongologReasoner::knowledgeGraph ( ) const
inline

Definition at line 35 of file MongologReasoner.h.

35 { return knowledgeGraph_; }

◆ unload() [1/2]

void MongologReasoner::unload ( )
overridevirtual

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

Reimplemented from knowrob::Reasoner.

Definition at line 37 of file MongologReasoner.cpp.

37  {
38  static auto unload_f = "mongolog_reasoner_unload";
40  // also unload the PrologReasoner
42 }
#define PROLOG_ENGINE_EVAL(term)
Definition: PrologEngine.h:128
PrologTerm getReasonerQuery(const PrologTerm &goal)

◆ unload() [2/2]

void knowrob::MongologReasoner::unload ( )
overridevirtual

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

Reimplemented from knowrob::PrologReasoner.

Member Data Documentation

◆ knowledgeGraph_

std::shared_ptr< MongoKnowledgeGraph > knowrob::MongologReasoner::knowledgeGraph_
protected

Definition at line 41 of file MongologReasoner.h.


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