knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Formula.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/formulas/Formula.h>
7 #include "knowrob/formulas/Top.h"
8 #include "knowrob/formulas/Bottom.h"
9 #include "knowrob/integration/python/utils.h"
10 #include "knowrob/formulas/CompoundFormula.h"
11 #include "knowrob/formulas/Negation.h"
12 #include "knowrob/formulas/Implication.h"
13 #include "knowrob/formulas/Disjunction.h"
14 #include "knowrob/formulas/ModalFormula.h"
15 #include "knowrob/formulas/FirstOrderLiteral.h"
16 #include "knowrob/formulas/PredicateIndicator.h"
17 #include "knowrob/formulas/Conjunction.h"
18 #include "knowrob/knowrob.h"
19 
20 using namespace knowrob;
21 
23  : type_(type) {}
24 
25 bool Formula::operator==(const Formula &other) const {
26  // note: isEqual can safely perform static cast as type id's do match
27  return typeid(*this) == typeid(other) && isEqual(other);
28 }
29 
30 bool Formula::isAtomic() const {
31  return type() == FormulaType::PREDICATE;
32 }
33 
34 bool Formula::isBottom() const {
35  return (this == Bottom::get().get());
36 }
37 
38 bool Formula::isTop() const {
39  return (this == Top::get().get());
40 }
41 
43  return typeid(*this) == typeid(other) && isEqual(other);
44 }
45 
46 namespace knowrob::py {
47  template<>
49  using namespace boost::python;
50  enum_<FormulaType>("FormulaType")
51  .value("PREDICATE", FormulaType::PREDICATE)
52  .value("CONJUNCTION", FormulaType::CONJUNCTION)
53  .value("DISJUNCTION", FormulaType::DISJUNCTION)
54  .value("NEGATION", FormulaType::NEGATION)
55  .value("IMPLICATION", FormulaType::IMPLICATION)
56  .value("MODAL", FormulaType::MODAL)
57  .export_values();
58  class_<Formula, std::shared_ptr<Formula>, boost::noncopyable>
59  ("Formula", no_init)
60  .def("type", &Formula::type)
61  .def("__eq__", &Formula::operator==)
62  .def("__repr__", &Formula::format)
63  .def("isGround", &Formula::isGround)
64  .def("isAtomic", &Formula::isAtomic)
65  .def("isTop", &Formula::isTop)
66  .def("isBottom", &Formula::isBottom);
67 
79  }
80 }
static const std::shared_ptr< Bottom > & get()
Definition: Bottom.cpp:12
Formula(const FormulaType &type)
Definition: Formula.cpp:22
FormulaType type() const
Definition: Formula.h:52
bool isBottom() const
Definition: Formula.cpp:34
virtual bool isEqual(const Formula &other) const =0
bool isTop() const
Definition: Formula.cpp:38
bool isGround() const
Definition: Formula.h:64
bool isAtomic() const
Definition: Formula.cpp:30
bool operator==(const Formula &other) const
Definition: Formula.cpp:25
bool operator==(const FormulaLabel &other)
Definition: Formula.cpp:42
virtual bool isEqual(const FormulaLabel &other) const =0
virtual std::string format() const
Definition: Printable.h:32
static const std::shared_ptr< Top > & get()
Definition: Top.cpp:11
void createType< PredicateIndicator >()
void createType< Bottom >()
Definition: Bottom.cpp:31
void createType< FirstOrderLiteral >()
void createType< CompoundFormula >()
void createType< Predicate >()
Definition: Predicate.cpp:95
void createType< Negation >()
Definition: Negation.cpp:39
void createType< Top >()
Definition: Top.cpp:30
void createType< Implication >()
Definition: Implication.cpp:23
void createType< Disjunction >()
Definition: Disjunction.cpp:82
void createType< ModalFormula >()
void createType< Formula >()
Definition: Formula.cpp:48
void createType< Conjunction >()
Definition: Conjunction.cpp:61
const IRIAtomPtr type
Definition: rdf.h:15
FormulaType
Definition: Formula.h:17