knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Predicate.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_PREDICATE_H_
7 #define KNOWROB_PREDICATE_H_
8 
9 #include <vector>
10 #include <memory>
11 #include <string>
12 #include "Formula.h"
13 #include "knowrob/terms/Term.h"
14 #include "knowrob/terms/Bindings.h"
15 #include "knowrob/terms/Atom.h"
16 #include "knowrob/terms/Function.h"
17 
18 namespace knowrob {
22  class Predicate : public Formula {
23  public:
28  explicit Predicate(std::string_view functor, const std::vector<TermPtr> &arguments = {});
29 
34  explicit Predicate(AtomPtr functor, const std::vector<TermPtr> &arguments = {});
35 
40  auto &functor() const { return functor_; }
41 
46  auto arity() const { return arguments().size(); }
47 
52  const std::vector<TermPtr> &arguments() const { return arguments_; }
53 
54  // Override Term
55  const std::set<std::string_view> &variables() { return variables_; }
56 
57  // Override Printable
58  void write(std::ostream &os) const override;
59 
60  // Override Term
61  size_t hash() const;
62 
63  static FunctionPtr toFunction(const std::shared_ptr<Predicate> &predicate);
64 
65  static std::shared_ptr<Predicate> fromFunction(const FunctionPtr &fn);
66 
67  protected:
68  const AtomPtr functor_;
69  const std::vector<TermPtr> arguments_;
70  const std::set<std::string_view> variables_;
71 
72  std::set<std::string_view> getVariables1() const;
73 
74  bool isEqual(const Formula &other) const override;
75  };
76 
77  using PredicatePtr = std::shared_ptr<Predicate>;
78 }
79 
80 #endif //KNOWROB_PREDICATE_H_
const AtomPtr functor_
Definition: Predicate.h:68
void write(std::ostream &os) const override
static FunctionPtr toFunction(const std::shared_ptr< Predicate > &predicate)
auto arity() const
Definition: Predicate.h:46
const std::set< std::string_view > & variables()
Definition: Predicate.h:55
bool isEqual(const Formula &other) const override
const std::set< std::string_view > variables_
Definition: Predicate.h:70
Predicate(AtomPtr functor, const std::vector< TermPtr > &arguments={})
const std::vector< TermPtr > & arguments() const
Definition: Predicate.h:52
size_t hash() const
auto & functor() const
Definition: Predicate.h:40
const std::vector< TermPtr > arguments_
Definition: Predicate.h:69
static std::shared_ptr< Predicate > fromFunction(const FunctionPtr &fn)
std::set< std::string_view > getVariables1() const
Predicate(std::string_view functor, const std::vector< TermPtr > &arguments={})
PredicateRule & predicate()
Definition: formula.cpp:221
std::shared_ptr< Predicate > PredicatePtr
Definition: Predicate.h:77
std::shared_ptr< Function > FunctionPtr
Definition: Function.h:73
std::shared_ptr< Atom > AtomPtr
Definition: Atom.h:69