knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
SWRLReasoner.cpp
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 #include "knowrob/reasoner/prolog/PrologTests.h"
7 #include "knowrob/reasoner/swrl/SWRLReasoner.h"
8 #include "knowrob/reasoner/ReasonerManager.h"
9 
10 using namespace knowrob;
11 
12 // make reasoner type accessible
14 
15 const std::string SWRLReasoner::SWRL_FORMAT = "pl-swrl";
16 
18  : PrologReasoner() {
20  (const DataSourcePtr &dataFile) { return loadSWRLFile(dataFile); });
21 }
22 
24  static auto unload_f = "swrl_reasoner_unload";
26  // also unload the PrologReasoner
28 }
29 
31  static auto consult_f = "swrl_file_load";
32  auto path = PrologEngine::getResourcePath(dataFile->uri());
33  KB_INFO("Loading SWRL file: {}", dataFile->uri());
34  return PROLOG_ENGINE_EVAL(getReasonerQuery(PrologTerm(consult_f, path.native())));
35 }
36 
38  KB_DEBUG("Initializing SWRL module.");
39  return consult(std::filesystem::path("reasoner") / "swrl" / "__init__.pl", nullptr, false);
40 }
41 
42 namespace knowrob::testing {
43  class SWRLTests : public PrologTests<knowrob::SWRLReasoner, knowrob::PrologBackend> {
44  protected:
45  static std::string getPath(const std::string &filename) {
46  return std::filesystem::path("reasoner") / "swrl" / filename;
47  }
48  };
49 }
50 using namespace knowrob::testing;
51 
52 TEST_F(SWRLTests, swrl) { runTests(getPath("swrl.plt")); }
TEST_F(SWRLTests, swrl)
#define KB_DEBUG
Definition: Logger.h:25
#define KB_INFO
Definition: Logger.h:26
#define PROLOG_ENGINE_EVAL(term)
Definition: PrologEngine.h:128
#define KNOWROB_BUILTIN_REASONER(Name, Type)
void addDataHandler(const std::string &format, const DataSourceLoader &fn)
static std::filesystem::path getResourcePath(const std::filesystem::path &filename)
bool consult(const std::filesystem::path &uri, const char *module={}, bool doTransformQuery=true)
PrologTerm getReasonerQuery(const PrologTerm &goal)
static const std::string SWRL_FORMAT
Definition: SWRLReasoner.h:16
void unload() override
bool loadSWRLFile(const DataSourcePtr &dataFile)
bool initializeDefaultPackages() override
TermRule & string()
Definition: terms.cpp:63
std::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:107