knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Perspective.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/semweb/Perspective.h"
7 #include "knowrob/integration/python/utils.h"
8 #include "knowrob/knowrob.h"
9 
10 using namespace knowrob;
11 
12 std::map<std::string_view, std::shared_ptr<Perspective>> Perspective::perspectiveMap_ =
13  std::map<std::string_view, std::shared_ptr<Perspective>>();
14 
15 Perspective::Perspective(std::string_view iri)
16  : atom_(IRIAtom::Tabled(iri)) {}
17 
18 std::shared_ptr<Perspective> Perspective::getEgoPerspective() {
19  static std::shared_ptr<Perspective> egoPerspective;
20  if (egoPerspective == nullptr) {
21  egoPerspective = std::make_shared<Perspective>(GlobalSettings::egoIRI());
22  perspectiveMap_[egoPerspective->iri()] = egoPerspective;
23  }
24  return egoPerspective;
25 }
26 
27 bool Perspective::isEgoPerspective(std::string_view iri) {
28  return iri.empty() || iri == GlobalSettings::egoIRI()->stringForm();
29 }
30 
31 std::shared_ptr<Perspective> Perspective::get(std::string_view iri) {
32  auto it = perspectiveMap_.find(iri);
33  if (it == perspectiveMap_.end()) {
34  auto agent = std::make_shared<Perspective>(iri);
35  perspectiveMap_[iri] = agent;
36  return agent;
37  } else {
38  return it->second;
39  }
40 }
41 
42 namespace knowrob::py {
43  template<>
45  using namespace boost::python;
46  class_<Perspective, std::shared_ptr<Perspective>>("Perspective", no_init)
47  .def("iri", &Perspective::iri)
48  .def("atom", &Perspective::atom)
49  .def("getEgoPerspective", &Perspective::getEgoPerspective)
50  .def("isEgoPerspective", &Perspective::isEgoPerspective)
51  .def("get", &Perspective::get);
52  }
53 }
static IRIAtomPtr egoIRI()
Definition: knowrob.h:79
static std::shared_ptr< Perspective > getEgoPerspective()
Definition: Perspective.cpp:18
auto iri() const
Definition: Perspective.h:38
static std::shared_ptr< Perspective > get(std::string_view iri)
Definition: Perspective.cpp:31
auto atom() const
Definition: Perspective.h:43
Perspective(std::string_view iri)
Definition: Perspective.cpp:15
static std::map< std::string_view, std::shared_ptr< Perspective > > perspectiveMap_
Definition: Perspective.h:64
static bool isEgoPerspective(std::string_view iri)
Definition: Perspective.cpp:27
void createType< Perspective >()
Definition: Perspective.cpp:44
IRIAtomPtr iri(std::string_view ns, std::string_view name)
Definition: IRIAtom.cpp:62