knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Answer.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_ANSWER_H_
7 #define KNOWROB_ANSWER_H_
8 
9 #include "Token.h"
10 #include "Query.h"
11 #include "knowrob/terms/Atom.h"
12 
13 namespace knowrob {
17  class Answer : public Token {
18  public:
21  frame_(std::make_shared<GraphSelector>()) {}
22 
23  Answer(const Answer &other)
25  frame_(other.frame_),
26  reasonerTerm_(other.reasonerTerm_) {};
27 
35  auto &frame() const { return frame_; }
36 
41  void setFrame(const std::shared_ptr<GraphSelector> &frame);
42 
48 
52  bool isNegative() const { return isNegative_; }
53 
57  bool isPositive() const { return isPositive_; }
58 
62  bool isUncertain() const;
63 
67  bool isCertain() const { return !isUncertain(); }
68 
74  void setIsUncertain(bool val, std::optional<double> confidence);
75 
79  bool isOccasionallyTrue() const;
80 
84  bool isAllwaysTrue() const { return !isOccasionallyTrue(); }
85 
90  void setIsOccasionallyTrue(bool val);
91 
96 
100  auto &reasonerTerm() const { return reasonerTerm_; }
101 
105  size_t hashOfAnswer() const;
106 
111 
116 
117  protected:
118  std::shared_ptr<GraphSelector> frame_;
120  bool isPositive_ = false;
121  bool isNegative_ = false;
122 
123  void setIsPositive(bool val) { isPositive_ = val; }
124 
125  void setIsNegative(bool val) { isNegative_ = val; }
126  };
127 
128  // alias
129  using AnswerPtr = std::shared_ptr<const Answer>;
130 
138  AnswerPtr mergeAnswers(const AnswerPtr &a, const AnswerPtr &b, bool ignoreInconsistencies);
139 
143  struct AnswerComparator {
144  bool operator()(const AnswerPtr &v0, const AnswerPtr &v1) const;
145  };
146 
150  using AnswerSet = std::set<AnswerPtr, AnswerComparator>;
151  using AnswerHandler = std::function<void(const AnswerPtr &)>;
152 }
153 
154 #endif //KNOWROB_ANSWER_H_
void setIsOccasionallyTrue(bool val)
std::string humanReadableForm() const
void applyFrame(const GraphSelector &frame)
bool isPositive() const
Definition: Answer.h:57
bool isUncertain() const
size_t hashOfAnswer() const
Answer(const Answer &other)
Definition: Answer.h:23
bool isOccasionallyTrue() const
Definition: Answer.cpp:45
auto & reasonerTerm() const
Definition: Answer.h:100
AtomPtr reasonerTerm_
Definition: Answer.h:119
void setIsPositive(bool val)
Definition: Answer.h:123
bool isCertain() const
Definition: Answer.h:67
bool isAllwaysTrue() const
Definition: Answer.h:84
bool isOccasionallyTrue() const
bool isUncertain() const
Definition: Answer.cpp:35
void setFrame(const std::shared_ptr< GraphSelector > &frame)
void setIsNegative(bool val)
Definition: Answer.h:125
bool isNegative_
Definition: Answer.h:121
auto & frame() const
Definition: Answer.h:35
std::shared_ptr< GraphSelector > frame_
Definition: Answer.h:118
bool isPositive_
Definition: Answer.h:120
void setReasonerTerm(const AtomPtr &reasonerTerm)
Definition: Answer.h:95
void setIsUncertain(bool val, std::optional< double > confidence)
std::string stringFormOfAnswer() const
bool isNegative() const
Definition: Answer.h:52
FunctionRule & function()
Definition: terms.cpp:140
TermRule & string()
Definition: terms.cpp:63
std::function< void(const AnswerPtr &)> AnswerHandler
Definition: Answer.h:151
AnswerPtr mergeAnswers(const AnswerPtr &a, const AnswerPtr &b, bool ignoreInconsistencies)
Definition: Answer.cpp:112
std::set< AnswerPtr, AnswerComparator > AnswerSet
Definition: Answer.h:150
std::shared_ptr< Atom > AtomPtr
Definition: Atom.h:69
std::shared_ptr< const Answer > AnswerPtr
Definition: Answer.h:129
TokenType
Definition: Token.h:19
bool operator()(const AnswerPtr &v0, const AnswerPtr &v1) const