knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::Answer Class Reference

#include <Answer.h>

Inheritance diagram for knowrob::Answer:
Collaboration diagram for knowrob::Answer:

Public Member Functions

 Answer ()
 
 Answer (const Answer &other)
 
auto & frame () const
 
void setFrame (const std::shared_ptr< GraphSelector > &frame)
 
void applyFrame (const GraphSelector &frame)
 
bool isNegative () const
 
bool isPositive () const
 
bool isUncertain () const
 
bool isCertain () const
 
void setIsUncertain (bool val, std::optional< double > confidence)
 
bool isOccasionallyTrue () const
 
bool isAllwaysTrue () const
 
void setIsOccasionallyTrue (bool val)
 
void setReasonerTerm (const AtomPtr &reasonerTerm)
 
auto & reasonerTerm () const
 
size_t hashOfAnswer () const
 
std::string stringFormOfAnswer () const
 
std::string humanReadableForm () const
 
 Answer ()
 
 Answer (const Answer &other)
 
auto & frame () const
 
void setFrame (const std::shared_ptr< GraphSelector > &frame)
 
void applyFrame (const GraphSelector &frame)
 
bool isNegative () const
 
bool isPositive () const
 
bool isUncertain () const
 
bool isCertain () const
 
void setIsUncertain (bool val, std::optional< double > confidence)
 
bool isOccasionallyTrue () const
 
bool isAllwaysTrue () const
 
void setIsOccasionallyTrue (bool val)
 
void setReasonerTerm (const AtomPtr &reasonerTerm)
 
auto & reasonerTerm () const
 
size_t hashOfAnswer () const
 
std::string stringFormOfAnswer () const
 
std::string humanReadableForm () const
 
- Public Member Functions inherited from knowrob::Token
 Token (TokenType tokenType)
 
virtual ~Token ()=default
 
TokenType tokenType () const
 
size_t hash () const
 
std::string stringForm () const
 
bool isControlToken () const
 
bool isAnswerToken () const
 
bool indicatesEndOfEvaluation () const
 
void write (std::ostream &os) const override
 
 Token (TokenType tokenType)
 
virtual ~Token ()=default
 
TokenType tokenType () const
 
size_t hash () const
 
std::string stringForm () const
 
bool isControlToken () const
 
bool isAnswerToken () const
 
bool indicatesEndOfEvaluation () const
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Protected Member Functions

void setIsPositive (bool val)
 
void setIsNegative (bool val)
 
void setIsPositive (bool val)
 
void setIsNegative (bool val)
 

Protected Attributes

std::shared_ptr< GraphSelectorframe_
 
AtomPtr reasonerTerm_
 
bool isPositive_ = false
 
bool isNegative_ = false
 
- Protected Attributes inherited from knowrob::Token
TokenType tokenType_
 
bool isTerminalToken_ = false
 

Detailed Description

The answer to a (sub)-query. It can be positive, negative or neither.

Definition at line 17 of file Answer.h.

Constructor & Destructor Documentation

◆ Answer() [1/4]

knowrob::Answer::Answer ( )
inline

Definition at line 19 of file Answer.h.

21  frame_(std::make_shared<GraphSelector>()) {}
std::shared_ptr< GraphSelector > frame_
Definition: Answer.h:118
Token(TokenType tokenType)
Definition: Token.h:31

◆ Answer() [2/4]

knowrob::Answer::Answer ( const Answer other)
inline

Definition at line 23 of file Answer.h.

25  frame_(other.frame_),
26  reasonerTerm_(other.reasonerTerm_) {};
AtomPtr reasonerTerm_
Definition: Answer.h:119

◆ Answer() [3/4]

knowrob::Answer::Answer ( )
inline

Definition at line 19 of file Answer.h.

21  frame_(std::make_shared<GraphSelector>()) {}

◆ Answer() [4/4]

knowrob::Answer::Answer ( const Answer other)
inline

Definition at line 23 of file Answer.h.

25  frame_(other.frame_),
26  reasonerTerm_(other.reasonerTerm_) {};

Member Function Documentation

◆ applyFrame() [1/2]

void Answer::applyFrame ( const GraphSelector frame)

Apply a frame to this answer.

Parameters
framea graph selector.

Definition at line 25 of file Answer.cpp.

25  {
26  frame_->graph = frame.graph;
27  frame_->perspective = frame.perspective;
28  frame_->confidence = std::nullopt;
29  frame_->begin = frame.begin;
30  frame_->end = frame.end;
31  frame_->uncertain = frame.uncertain;
32  frame_->occasional = frame.occasional;
33 }
auto & frame() const
Definition: Answer.h:35

◆ applyFrame() [2/2]

void knowrob::Answer::applyFrame ( const GraphSelector frame)

Apply a frame to this answer.

Parameters
framea graph selector.

◆ frame() [1/2]

auto& knowrob::Answer::frame ( ) const
inline

The answer is framed in the context of a graph selector which determines the set of graphs in which the answer is valid. This can be used to e.g. address graphs that represent the world state from the perspective of a specific agent, or a specific point in time.

Returns
a graph selector.

Definition at line 35 of file Answer.h.

35 { return frame_; }

◆ frame() [2/2]

auto& knowrob::Answer::frame ( ) const
inline

The answer is framed in the context of a graph selector which determines the set of graphs in which the answer is valid. This can be used to e.g. address graphs that represent the world state from the perspective of a specific agent, or a specific point in time.

Returns
a graph selector.

Definition at line 35 of file Answer.h.

35 { return frame_; }

◆ hashOfAnswer() [1/2]

size_t Answer::hashOfAnswer ( ) const
Returns
the hash of this answer.

Definition at line 64 of file Answer.cpp.

64  {
65  size_t val = 0;
66  hashCombine(val, uint8_t(tokenType()));
67  if (isNegative()) {
68  hashCombine(val, 0);
69  } else if (isPositive()) {
70  hashCombine(val, 1);
71  } else {
72  hashCombine(val, 2);
73  }
74  if (reasonerTerm()) {
75  hashCombine(val, reasonerTerm()->hash());
76  } else {
77  hashCombine(val, 0);
78  }
79  if (frame()) {
80  hashCombine(val, frame()->hash());
81  } else {
82  hashCombine(val, 0);
83  }
84  if (isPositive()) {
85  auto &bindings = ((AnswerYes *) this)->substitution();
86  hashCombine(val, bindings->hash());
87  }
88  return val;
89 }
bool isPositive() const
Definition: Answer.h:57
auto & reasonerTerm() const
Definition: Answer.h:100
bool isNegative() const
Definition: Answer.h:52
TokenType tokenType() const
Definition: Token.h:38
size_t hash() const
Definition: Token.cpp:15
void hashCombine(std::size_t &seed, const std::size_t &v)
Definition: knowrob.cpp:39

◆ hashOfAnswer() [2/2]

size_t knowrob::Answer::hashOfAnswer ( ) const
Returns
the hash of this answer.

◆ humanReadableForm() [1/2]

std::string Answer::humanReadableForm ( ) const
Returns
a human readable string representation of this answer.

Definition at line 101 of file Answer.cpp.

101  {
102  if (isNegative()) {
103  return ((AnswerNo *) this)->humanReadableFormOfNo();
104  } else if (isPositive()) {
105  return ((AnswerYes *) this)->humanReadableFormOfYes();
106  } else {
107  return ((AnswerDontKnow *) this)->humanReadableFormOfDontKnow();
108  }
109 }

◆ humanReadableForm() [2/2]

std::string knowrob::Answer::humanReadableForm ( ) const
Returns
a human readable string representation of this answer.

◆ isAllwaysTrue() [1/2]

bool knowrob::Answer::isAllwaysTrue ( ) const
inline
Returns
true if truth of this answer is certain.

Definition at line 84 of file Answer.h.

84 { return !isOccasionallyTrue(); }
bool isOccasionallyTrue() const
Definition: Answer.cpp:45

◆ isAllwaysTrue() [2/2]

bool knowrob::Answer::isAllwaysTrue ( ) const
inline
Returns
true if truth of this answer is certain.

Definition at line 84 of file Answer.h.

84 { return !isOccasionallyTrue(); }

◆ isCertain() [1/2]

bool knowrob::Answer::isCertain ( ) const
inline
Returns
true if truth of this answer is certain.

Definition at line 67 of file Answer.h.

67 { return !isUncertain(); }
bool isUncertain() const
Definition: Answer.cpp:35

◆ isCertain() [2/2]

bool knowrob::Answer::isCertain ( ) const
inline
Returns
true if truth of this answer is certain.

Definition at line 67 of file Answer.h.

67 { return !isUncertain(); }

◆ isNegative() [1/2]

bool knowrob::Answer::isNegative ( ) const
inline
Returns
true if this answer is negative.

Definition at line 52 of file Answer.h.

52 { return isNegative_; }
bool isNegative_
Definition: Answer.h:121

◆ isNegative() [2/2]

bool knowrob::Answer::isNegative ( ) const
inline
Returns
true if this answer is negative.

Definition at line 52 of file Answer.h.

52 { return isNegative_; }

◆ isOccasionallyTrue() [1/2]

bool Answer::isOccasionallyTrue ( ) const
Returns
true if truth of this answer is uncertain.

Definition at line 45 of file Answer.cpp.

45  {
46  return frame_->occasional;
47 }

◆ isOccasionallyTrue() [2/2]

bool knowrob::Answer::isOccasionallyTrue ( ) const
Returns
true if truth of this answer is uncertain.

◆ isPositive() [1/2]

bool knowrob::Answer::isPositive ( ) const
inline
Returns
true if this answer is positive.

Definition at line 57 of file Answer.h.

57 { return isPositive_; }
bool isPositive_
Definition: Answer.h:120

◆ isPositive() [2/2]

bool knowrob::Answer::isPositive ( ) const
inline
Returns
true if this answer is positive.

Definition at line 57 of file Answer.h.

57 { return isPositive_; }

◆ isUncertain() [1/2]

bool Answer::isUncertain ( ) const
Returns
true if truth of this answer is uncertain.

Definition at line 35 of file Answer.cpp.

35  {
36  if (frame_->confidence.has_value()) {
37  if (frame_->confidence.value() < 1.0) return true;
38  }
39  if (frame_->uncertain) {
40  return true;
41  }
42  return false;
43 }

◆ isUncertain() [2/2]

bool knowrob::Answer::isUncertain ( ) const
Returns
true if truth of this answer is uncertain.

◆ reasonerTerm() [1/2]

auto& knowrob::Answer::reasonerTerm ( ) const
inline
Returns
the name of the reasoner that was used to generate this answer.

Definition at line 100 of file Answer.h.

100 { return reasonerTerm_; }

◆ reasonerTerm() [2/2]

auto& knowrob::Answer::reasonerTerm ( ) const
inline
Returns
the name of the reasoner that was used to generate this answer.

Definition at line 100 of file Answer.h.

100 { return reasonerTerm_; }

◆ setFrame() [1/2]

void Answer::setFrame ( const std::shared_ptr< GraphSelector > &  frame)

Assign a graph selector to this answer.

Parameters
framea graph selector.

Definition at line 17 of file Answer.cpp.

17  {
18  if (frame != nullptr) {
19  frame_ = frame;
20  } else {
21  throw std::invalid_argument("frame must not be null");
22  }
23 }

◆ setFrame() [2/2]

void knowrob::Answer::setFrame ( const std::shared_ptr< GraphSelector > &  frame)

Assign a graph selector to this answer.

Parameters
framea graph selector.

◆ setIsNegative() [1/2]

void knowrob::Answer::setIsNegative ( bool  val)
inlineprotected

Definition at line 125 of file Answer.h.

125 { isNegative_ = val; }

◆ setIsNegative() [2/2]

void knowrob::Answer::setIsNegative ( bool  val)
inlineprotected

Definition at line 125 of file Answer.h.

125 { isNegative_ = val; }

◆ setIsOccasionallyTrue() [1/2]

void Answer::setIsOccasionallyTrue ( bool  val)

Mark this answer as occasionally true.

Parameters
valtrue if the answer is occasionally true.

Definition at line 60 of file Answer.cpp.

60  {
61  frame_->occasional = val;
62 }

◆ setIsOccasionallyTrue() [2/2]

void knowrob::Answer::setIsOccasionallyTrue ( bool  val)

Mark this answer as occasionally true.

Parameters
valtrue if the answer is occasionally true.

◆ setIsPositive() [1/2]

void knowrob::Answer::setIsPositive ( bool  val)
inlineprotected

Definition at line 123 of file Answer.h.

123 { isPositive_ = val; }

◆ setIsPositive() [2/2]

void knowrob::Answer::setIsPositive ( bool  val)
inlineprotected

Definition at line 123 of file Answer.h.

123 { isPositive_ = val; }

◆ setIsUncertain() [1/2]

void Answer::setIsUncertain ( bool  val,
std::optional< double >  confidence 
)

Mark this answer as uncertain by modification of the associated frame.

Parameters
valtrue if the answer is uncertain.
confidencethe confidence value.

Definition at line 49 of file Answer.cpp.

49  {
50  frame_->uncertain = val;
51  if (val) {
52  if (confidence.has_value()) {
53  frame_->confidence = confidence;
54  }
55  } else {
56  frame_->confidence = 1.0;
57  }
58 }

◆ setIsUncertain() [2/2]

void knowrob::Answer::setIsUncertain ( bool  val,
std::optional< double >  confidence 
)

Mark this answer as uncertain by modification of the associated frame.

Parameters
valtrue if the answer is uncertain.
confidencethe confidence value.

◆ setReasonerTerm() [1/2]

void knowrob::Answer::setReasonerTerm ( const AtomPtr reasonerTerm)
inline
Returns
the name of the reasoner that was used to generate this answer.

Definition at line 95 of file Answer.h.

◆ setReasonerTerm() [2/2]

void knowrob::Answer::setReasonerTerm ( const AtomPtr reasonerTerm)
inline
Returns
the name of the reasoner that was used to generate this answer.

Definition at line 95 of file Answer.h.

◆ stringFormOfAnswer() [1/2]

std::string Answer::stringFormOfAnswer ( ) const
Returns
a string representation of this answer.

Definition at line 91 of file Answer.cpp.

91  {
92  if (isNegative()) {
93  return ((AnswerNo *) this)->stringFormOfNo();
94  } else if (isPositive()) {
95  return ((AnswerYes *) this)->stringFormOfYes();
96  } else {
97  return ((AnswerDontKnow *) this)->stringFormOfDontKnow();
98  }
99 }

◆ stringFormOfAnswer() [2/2]

std::string knowrob::Answer::stringFormOfAnswer ( ) const
Returns
a string representation of this answer.

Member Data Documentation

◆ frame_

std::shared_ptr< GraphSelector > knowrob::Answer::frame_
protected

Definition at line 118 of file Answer.h.

◆ isNegative_

bool knowrob::Answer::isNegative_ = false
protected

Definition at line 121 of file Answer.h.

◆ isPositive_

bool knowrob::Answer::isPositive_ = false
protected

Definition at line 120 of file Answer.h.

◆ reasonerTerm_

AtomPtr knowrob::Answer::reasonerTerm_
protected

Definition at line 119 of file Answer.h.


The documentation for this class was generated from the following files: