knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
FirstOrderLiteral.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/FirstOrderLiteral.h"
7 #include "knowrob/integration/python/utils.h"
8 
9 using namespace knowrob;
10 
12  : predicate_(predicate),
13  isNegated_(isNegative) {}
14 
15 /*
16 FirstOrderLiteral::FirstOrderLiteral(const FirstOrderLiteral &other, const Substitution &sub)
17  : predicate_(std::static_pointer_cast<Predicate>(applyBindings(other.predicate_, sub))),
18  isNegated_(other.isNegated_) {}
19 */
20 
21 void FirstOrderLiteral::write(std::ostream &os) const {
22  if (isNegated()) {
23  os << "not(" << *predicate_ << ")";
24  } else {
25  os << *predicate_;
26  }
27 }
28 
29 namespace knowrob {
31  auto predicate = std::static_pointer_cast<Predicate>(applyBindings(lit->predicate(), bindings));
32  if (predicate != lit->predicate()) {
33  return std::make_shared<FirstOrderLiteral>(predicate, lit->isNegated());
34  }
35  else {
36  return lit;
37  }
38  }
39 }
40 
41 namespace knowrob::py {
42  template<>
44  using namespace boost::python;
45  class_<FirstOrderLiteral, std::shared_ptr<FirstOrderLiteral>>
46  ("FirstOrderLiteral", init<const PredicatePtr &, bool>())
47  .def("predicate", &FirstOrderLiteral::predicate, return_value_policy<copy_const_reference>())
48  .def("isNegated", &FirstOrderLiteral::isNegated)
49  .def("functor", &FirstOrderLiteral::functor, return_value_policy<copy_const_reference>())
50  .def("arity", &FirstOrderLiteral::arity)
51  .def("numVariables", &FirstOrderLiteral::numVariables);
52  }
53 }
void write(std::ostream &os) const override
FirstOrderLiteral(const PredicatePtr &predicate, bool isNegative)
virtual uint32_t numVariables() const
const auto & predicate() const
const PredicatePtr predicate_
PredicateRule & predicate()
Definition: formula.cpp:221
void createType< FirstOrderLiteral >()
std::shared_ptr< Predicate > PredicatePtr
Definition: Predicate.h:77
FirstOrderLiteralPtr applyBindings(const FirstOrderLiteralPtr &lit, const Bindings &bindings)
std::shared_ptr< FirstOrderLiteral > FirstOrderLiteralPtr