knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
PrologReasoner.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_PROLOG_REASONER_H_
7 #define KNOWROB_PROLOG_REASONER_H_
8 
9 // STD
10 #include <string>
11 #include <list>
12 #include <filesystem>
13 #include <map>
14 #include <memory>
15 // gtest
16 #include <gtest/gtest.h>
17 // KnowRob
18 #include "knowrob/ThreadPool.h"
19 #include "knowrob/terms/Term.h"
20 #include "knowrob/integration/prolog/PrologEngine.h"
21 #include "knowrob/queries/AnswerYes.h"
22 #include "knowrob/integration/prolog/PrologBackend.h"
23 #include "knowrob/queries/AnswerNo.h"
24 #include "knowrob/reasoner/GoalDrivenReasoner.h"
25 
26 namespace knowrob {
30  class PrologReasoner : public GoalDrivenReasoner {
31  public:
33 
34  ~PrologReasoner() override;
35 
39  PrologReasoner(const PrologReasoner &) = delete;
40 
47  bool setReasonerSetting(const TermPtr &key, const TermPtr &valueString);
48 
58  bool consult(const std::filesystem::path &uri, const char *module = {}, bool doTransformQuery = true);
59 
63  bool load_rdf_xml(const std::filesystem::path &rdfFile);
64 
67  virtual std::string_view callFunctor();
68 
70 
71  static std::shared_ptr<NamedReasoner> getDefinedReasoner(
72  const term_t &t_reasonerManager, const term_t &t_reasonerModule);
73 
74  std::list<TermPtr> runTests(const std::string &target);
75 
76  // Override Reasoner
77  bool initializeReasoner(const PropertyTree &cfg) override;
78 
79  // Override Reasoner
80  bool evaluate(GoalPtr query) override;
81 
82  // Override Reasoner
83  void unload() override;
84 
85  protected:
86  static bool isKnowRobInitialized_;
87  std::shared_ptr<PrologBackend> knowledgeGraph_;
88 
89  virtual bool initializeGlobalPackages() { return true; }
90 
91  virtual bool initializeDefaultPackages() { return true; }
92 
93  virtual void initializeReasonerStorage() { knowledgeGraph_ = getTypedStorage<PrologBackend>(); }
94 
95  bool loadDataSourceWithUnknownFormat(const DataSourcePtr &dataFile) override {
96  return consult(dataFile->uri());
97  };
98 
99  AnswerYesPtr yes(const GoalPtr &query, const PrologTerm &rdfGoal, const PrologTerm &frameTerm);
100 
101  AnswerNoPtr no(const GoalPtr &query);
102 
103  static bool putQueryFrame(PrologTerm &frameTerm, const GraphSelector &frame);
104 
105  static std::shared_ptr<GraphSelector> createAnswerFrame(const PrologTerm &plTerm);
106 
108  };
109 }
110 
111 #endif //KNOWROB_PROLOG_REASONER_H_
bool consult(const std::filesystem::path &uri, const char *module={}, bool doTransformQuery=true)
virtual void initializeReasonerStorage()
bool loadDataSourceWithUnknownFormat(const DataSourcePtr &dataFile) override
PrologReasoner(const PrologReasoner &)=delete
void unload() override
bool initializeReasoner(const PropertyTree &cfg) override
virtual bool initializeGlobalPackages()
static bool isKnowRobInitialized_
PrologTerm transformGoal(const PrologTerm &goal)
bool consult(const std::filesystem::path &uri, const char *module={}, bool doTransformQuery=true)
bool load_rdf_xml(const std::filesystem::path &rdfFile)
bool setReasonerSetting(const TermPtr &key, const TermPtr &valueString)
AnswerNoPtr no(const GoalPtr &query)
static std::shared_ptr< NamedReasoner > getDefinedReasoner(const term_t &t_reasonerManager, const term_t &t_reasonerModule)
virtual bool initializeDefaultPackages()
AnswerYesPtr yes(const GoalPtr &query, const PrologTerm &rdfGoal, const PrologTerm &frameTerm)
std::list< TermPtr > runTests(const std::string &target)
static bool putQueryFrame(PrologTerm &frameTerm, const GraphSelector &frame)
PrologTerm getReasonerQuery(const PrologTerm &goal)
static std::shared_ptr< GraphSelector > createAnswerFrame(const PrologTerm &plTerm)
std::shared_ptr< PrologBackend > knowledgeGraph_
bool evaluate(GoalPtr query) override
virtual std::string_view callFunctor()
TermRule & string()
Definition: terms.cpp:63
std::shared_ptr< Term > TermPtr
Definition: Term.h:117
std::shared_ptr< const AnswerYes > AnswerYesPtr
Definition: AnswerYes.h:108
std::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:107
std::shared_ptr< Goal > GoalPtr
Definition: Goal.h:84
std::shared_ptr< const AnswerNo > AnswerNoPtr
Definition: AnswerNo.h:74