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

#include <AnswerNo.h>

Inheritance diagram for knowrob::AnswerNo:
Collaboration diagram for knowrob::AnswerNo:

Public Member Functions

 AnswerNo ()
 
 AnswerNo (const AnswerNo &other)
 
void addUngrounded (const std::shared_ptr< Predicate > &predicate, bool isNegated=false)
 
auto & positiveUngrounded () const
 
auto & negativeUngrounded () const
 
bool mergeWith (const AnswerNo &other)
 
std::string stringFormOfNo () const
 
std::string humanReadableFormOfNo () const
 
 AnswerNo ()
 
 AnswerNo (const AnswerNo &other)
 
void addUngrounded (const std::shared_ptr< Predicate > &predicate, bool isNegated=false)
 
auto & positiveUngrounded () const
 
auto & negativeUngrounded () const
 
bool mergeWith (const AnswerNo &other)
 
std::string stringFormOfNo () const
 
std::string humanReadableFormOfNo () const
 
- Public Member Functions inherited from knowrob::Answer
 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 Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from knowrob::Answer
void setIsPositive (bool val)
 
void setIsNegative (bool val)
 
void setIsPositive (bool val)
 
void setIsNegative (bool val)
 

Detailed Description

A negative answer indicates that a querying component has evidence for the input query being false for all instances of the query.

Definition at line 17 of file AnswerNo.h.

Constructor & Destructor Documentation

◆ AnswerNo() [1/4]

AnswerNo::AnswerNo ( )

Default constructor.

Definition at line 19 of file AnswerNo.cpp.

20  : Answer() {
21  setIsNegative(true);
22 }
void setIsNegative(bool val)
Definition: Answer.h:125

◆ AnswerNo() [2/4]

AnswerNo::AnswerNo ( const AnswerNo other)

Copy constructor.

Parameters
otheranother answer.

Definition at line 24 of file AnswerNo.cpp.

25  : Answer(other) {
26  setIsNegative(true);
27 }

◆ AnswerNo() [3/4]

knowrob::AnswerNo::AnswerNo ( )

Default constructor.

◆ AnswerNo() [4/4]

knowrob::AnswerNo::AnswerNo ( const AnswerNo other)

Copy constructor.

Parameters
otheranother answer.

Member Function Documentation

◆ addUngrounded() [1/2]

void AnswerNo::addUngrounded ( const std::shared_ptr< Predicate > &  predicate,
bool  isNegated = false 
)

Add a ungroundable literal to the answer.

Parameters
predicatea predicate.
isNegatedtrue if the negation of the predicate is ungroundable.

Definition at line 29 of file AnswerNo.cpp.

29  {
30  if (isNegated) {
32  } else {
34  }
35 }
AtomPtr reasonerTerm_
Definition: Answer.h:119
std::vector< FramedPredicate > positiveUngrounded_
Definition: AnswerNo.h:69
std::vector< FramedPredicate > negativeUngrounded_
Definition: AnswerNo.h:70
PredicateRule & predicate()
Definition: formula.cpp:221
GraphSelectorPtr DefaultGraphSelector()

◆ addUngrounded() [2/2]

void knowrob::AnswerNo::addUngrounded ( const std::shared_ptr< Predicate > &  predicate,
bool  isNegated = false 
)

Add a ungroundable literal to the answer.

Parameters
predicatea predicate.
isNegatedtrue if the negation of the predicate is ungroundable.

◆ humanReadableFormOfNo() [1/2]

std::string AnswerNo::humanReadableFormOfNo ( ) const
Returns
the human readable form of this answer.

Definition at line 82 of file AnswerNo.cpp.

82  {
83  static const std::string longMsg = "there was evidence supporting the query to be false";
84  return longMsg;
85 }
TermRule & string()
Definition: terms.cpp:63

◆ humanReadableFormOfNo() [2/2]

std::string knowrob::AnswerNo::humanReadableFormOfNo ( ) const
Returns
the human readable form of this answer.

◆ mergeWith() [1/2]

bool AnswerNo::mergeWith ( const AnswerNo other)

Merge this answer with another answer.

Parameters
otheranother answer.
Returns
true if the merge was successful.

Definition at line 37 of file AnswerNo.cpp.

37  {
38  reasonerTerm_ = {};
39  if (!frame_->mergeWith(*other.frame_)) {
40  // merging frames failed -> results cannot be combined
41  return false;
42  }
43  // insert groundings of other answer
45  other.positiveUngrounded_.begin(), other.positiveUngrounded_.end());
47  other.negativeUngrounded_.begin(), other.negativeUngrounded_.end());
48  return true;
49 }
std::shared_ptr< GraphSelector > frame_
Definition: Answer.h:118

◆ mergeWith() [2/2]

bool knowrob::AnswerNo::mergeWith ( const AnswerNo other)

Merge this answer with another answer.

Parameters
otheranother answer.
Returns
true if the merge was successful.

◆ negativeUngrounded() [1/2]

auto& knowrob::AnswerNo::negativeUngrounded ( ) const
inline

Part of the answer is that certain literals that appear negated in the query are not true. This is a list of such literals.

Returns
a list of negative groundings.

Definition at line 49 of file AnswerNo.h.

49 { return negativeUngrounded_; }

◆ negativeUngrounded() [2/2]

auto& knowrob::AnswerNo::negativeUngrounded ( ) const
inline

Part of the answer is that certain literals that appear negated in the query are not true. This is a list of such literals.

Returns
a list of negative groundings.

Definition at line 49 of file AnswerNo.h.

49 { return negativeUngrounded_; }

◆ positiveUngrounded() [1/2]

auto& knowrob::AnswerNo::positiveUngrounded ( ) const
inline

Part of the answer is that certain literals that appear positive in the query are true. This is a list of such literals.

Returns
a list of positive groundings.

Definition at line 42 of file AnswerNo.h.

42 { return positiveUngrounded_; }

◆ positiveUngrounded() [2/2]

auto& knowrob::AnswerNo::positiveUngrounded ( ) const
inline

Part of the answer is that certain literals that appear positive in the query are true. This is a list of such literals.

Returns
a list of positive groundings.

Definition at line 42 of file AnswerNo.h.

42 { return positiveUngrounded_; }

◆ stringFormOfNo() [1/2]

std::string AnswerNo::stringFormOfNo ( ) const
Returns
the string form of this answer.

Definition at line 51 of file AnswerNo.cpp.

51  {
52  std::stringstream os;
53  if (reasonerTerm_) {
54  os << "[" << *reasonerTerm_ << "] ";
55  }
56  if (isUncertain()) {
57  os << "probably ";
58  }
59  os << "no";
60  if (!positiveUngrounded_.empty() || !negativeUngrounded_.empty()) {
61  os << ", because:\n";
62  for (auto &x: positiveUngrounded_) {
63  os << '\t' << *x.graphSelector() << ' ' << '~' << *x.predicate();
64  if (x.reasonerTerm() && x.reasonerTerm() != reasonerTerm_) {
65  os << ' ' << '[' << *x.reasonerTerm() << "]";
66  }
67  os << '\n';
68  }
69  for (auto &x: negativeUngrounded_) {
70  os << '\t' << *x.graphSelector() << *x.predicate();
71  if (x.reasonerTerm() && x.reasonerTerm() != reasonerTerm_) {
72  os << ' ' << '[' << *x.reasonerTerm() << "]";
73  }
74  os << '\n';
75  }
76  } else {
77  os << '\n';
78  }
79  return os.str();
80 }
bool isUncertain() const
Definition: Answer.cpp:35

◆ stringFormOfNo() [2/2]

std::string knowrob::AnswerNo::stringFormOfNo ( ) const
Returns
the string form of this answer.

Member Data Documentation

◆ negativeUngrounded_

std::vector< FramedPredicate > knowrob::AnswerNo::negativeUngrounded_
protected

Definition at line 70 of file AnswerNo.h.

◆ positiveUngrounded_

std::vector< FramedPredicate > knowrob::AnswerNo::positiveUngrounded_
protected

Definition at line 69 of file AnswerNo.h.


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