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

#include <ModalOperator.h>

Public Member Functions

 ModalOperator (ModalType modalType)
 
bool operator== (const ModalOperator &other) const
 
bool isModalNecessity () const
 
bool isModalPossibility () const
 
auto modalType () const
 
const char * symbol () const
 
void setParameter (std::string_view key, const TermPtr &value)
 
std::optional< TermPtrparameter (std::string_view key) const
 
std::optional< PerspectivePtrperspective () const
 
void setPerspective (const std::string_view &agent)
 
std::optional< double > confidence () const
 
void setConfidence (double confidence)
 
std::optional< double > begin () const
 
void setBegin (double begin)
 
std::optional< double > end () const
 
void setEnd (double end)
 
void setTimeInterval (const TimeInterval &timeInterval)
 
void write (std::ostream &os) const
 
 ModalOperator (ModalType modalType)
 
bool operator== (const ModalOperator &other) const
 
bool isModalNecessity () const
 
bool isModalPossibility () const
 
auto modalType () const
 
const char * symbol () const
 
void setParameter (std::string_view key, const TermPtr &value)
 
std::optional< TermPtrparameter (std::string_view key) const
 
std::optional< PerspectivePtrperspective () const
 
void setPerspective (const std::string_view &agent)
 
std::optional< double > confidence () const
 
void setConfidence (double confidence)
 
std::optional< double > begin () const
 
void setBegin (double begin)
 
std::optional< double > end () const
 
void setEnd (double end)
 
void setTimeInterval (const TimeInterval &timeInterval)
 
void write (std::ostream &os) const
 

Static Public Attributes

static constexpr const char * KEY_PERSPECTIVE = "agent"
 
static constexpr const char * KEY_CONFIDENCE = "confidence"
 
static constexpr const char * KEY_BEGIN = "begin"
 
static constexpr const char * KEY_END = "end"
 

Protected Attributes

const ModalType modalType_
 
std::map< std::string, TermPtrparameters_
 

Detailed Description

An operator of a modal language, e.g. "B" is often used for "belief" and "K" for "knowledge". Additional parameters can be added to the operator, e.g. "B[confidence=0.8]".

Definition at line 31 of file ModalOperator.h.

Constructor & Destructor Documentation

◆ ModalOperator() [1/2]

ModalOperator::ModalOperator ( ModalType  modalType)
explicit
Parameters
modalTypethe type of this operator.

Definition at line 13 of file ModalOperator.cpp.

15 }
auto modalType() const
Definition: ModalOperator.h:62
const ModalType modalType_

◆ ModalOperator() [2/2]

knowrob::ModalOperator::ModalOperator ( ModalType  modalType)
explicit
Parameters
modalTypethe type of this operator.

Member Function Documentation

◆ begin() [1/2]

std::optional< double > ModalOperator::begin ( ) const
Returns
the time interval begin parameter of this operator if any.

Definition at line 113 of file ModalOperator.cpp.

113  {
114  auto it = parameters_.find(KEY_BEGIN);
115  if (it != parameters_.end() && it->second->isNumeric()) {
116  return std::static_pointer_cast<Numeric>(it->second)->asDouble();
117  }
118  return std::nullopt;
119 }
std::map< std::string, TermPtr > parameters_
static constexpr const char * KEY_BEGIN
Definition: ModalOperator.h:35

◆ begin() [2/2]

std::optional<double> knowrob::ModalOperator::begin ( ) const
Returns
the time interval begin parameter of this operator if any.

◆ confidence() [1/2]

std::optional< double > ModalOperator::confidence ( ) const
Returns
the confidence parameter of this operator if any.

Definition at line 101 of file ModalOperator.cpp.

101  {
102  auto it = parameters_.find(KEY_CONFIDENCE);
103  if (it != parameters_.end() && it->second->isNumeric()) {
104  return std::static_pointer_cast<Numeric>(it->second)->asDouble();
105  }
106  return std::nullopt;
107 }
static constexpr const char * KEY_CONFIDENCE
Definition: ModalOperator.h:34

◆ confidence() [2/2]

std::optional<double> knowrob::ModalOperator::confidence ( ) const
Returns
the confidence parameter of this operator if any.

◆ end() [1/2]

std::optional< double > ModalOperator::end ( ) const
Returns
the time interval end parameter of this operator if any.

Definition at line 125 of file ModalOperator.cpp.

125  {
126  auto it = parameters_.find(KEY_END);
127  if (it != parameters_.end() && it->second->isNumeric()) {
128  return std::static_pointer_cast<Numeric>(it->second)->asDouble();
129  }
130  return std::nullopt;
131 }
static constexpr const char * KEY_END
Definition: ModalOperator.h:36

◆ end() [2/2]

std::optional<double> knowrob::ModalOperator::end ( ) const
Returns
the time interval end parameter of this operator if any.

◆ isModalNecessity() [1/2]

bool ModalOperator::isModalNecessity ( ) const
Returns
true if this operator is a necessity operator.

Definition at line 61 of file ModalOperator.cpp.

61  {
62  switch (modalType_) {
64  case ModalType::ALWAYS:
65  return true;
67  case ModalType::BELIEF:
68  return false;
69  }
70  return true;
71 }

◆ isModalNecessity() [2/2]

bool knowrob::ModalOperator::isModalNecessity ( ) const
Returns
true if this operator is a necessity operator.

◆ isModalPossibility() [1/2]

bool ModalOperator::isModalPossibility ( ) const
Returns
true if this operator is a possibility operator.

Definition at line 73 of file ModalOperator.cpp.

73  {
74  return !isModalNecessity();
75 }
bool isModalNecessity() const

◆ isModalPossibility() [2/2]

bool knowrob::ModalOperator::isModalPossibility ( ) const
Returns
true if this operator is a possibility operator.

◆ modalType() [1/2]

auto knowrob::ModalOperator::modalType ( ) const
inline
Returns
the type of this operator.

Definition at line 62 of file ModalOperator.h.

62 { return modalType_; }

◆ modalType() [2/2]

auto knowrob::ModalOperator::modalType ( ) const
inline
Returns
the type of this operator.

Definition at line 62 of file ModalOperator.h.

62 { return modalType_; }

◆ operator==() [1/2]

bool ModalOperator::operator== ( const ModalOperator other) const
Parameters
otheranother operator.
Returns
true if this and other are the same operators.

Definition at line 45 of file ModalOperator.cpp.

45  {
46  if (modalType_ != other.modalType_) {
47  return false;
48  }
49  if (parameters_.size() != other.parameters_.size()) {
50  return false;
51  }
52  for (auto &pair: parameters_) {
53  auto it = other.parameters_.find(pair.first);
54  if (it == other.parameters_.end() || *it->second != *pair.second) {
55  return false;
56  }
57  }
58  return true;
59 }

◆ operator==() [2/2]

bool knowrob::ModalOperator::operator== ( const ModalOperator other) const
Parameters
otheranother operator.
Returns
true if this and other are the same operators.

◆ parameter() [1/2]

std::optional< TermPtr > ModalOperator::parameter ( std::string_view  key) const
Parameters
keythe key of the parameter.
Returns
the value of the parameter if any or else null-opt.

Definition at line 81 of file ModalOperator.cpp.

81  {
82  auto it = parameters_.find(key.data());
83  if (it == parameters_.end()) {
84  return std::nullopt;
85  }
86  return it->second;
87 }

◆ parameter() [2/2]

std::optional<TermPtr> knowrob::ModalOperator::parameter ( std::string_view  key) const
Parameters
keythe key of the parameter.
Returns
the value of the parameter if any or else null-opt.

◆ perspective() [1/2]

std::optional< PerspectivePtr > ModalOperator::perspective ( ) const
Returns
the perspective parameter of this operator if any.

Definition at line 89 of file ModalOperator.cpp.

89  {
90  auto it = parameters_.find(KEY_PERSPECTIVE);
91  if (it != parameters_.end() && it->second->isAtom()) {
92  return Perspective::get(std::static_pointer_cast<Atomic>(it->second)->stringForm());
93  }
94  return std::nullopt;
95 }
static constexpr const char * KEY_PERSPECTIVE
Definition: ModalOperator.h:33
static std::shared_ptr< Perspective > get(std::string_view iri)
Definition: Perspective.cpp:31

◆ perspective() [2/2]

std::optional<PerspectivePtr> knowrob::ModalOperator::perspective ( ) const
Returns
the perspective parameter of this operator if any.

◆ setBegin() [1/2]

void ModalOperator::setBegin ( double  begin)
Parameters
beginthe time interval begin parameter of this operator.

Definition at line 121 of file ModalOperator.cpp.

121  {
122  parameters_[KEY_BEGIN] = std::make_shared<Double>(begin);
123 }
std::optional< double > begin() const

◆ setBegin() [2/2]

void knowrob::ModalOperator::setBegin ( double  begin)
Parameters
beginthe time interval begin parameter of this operator.

◆ setConfidence() [1/2]

void ModalOperator::setConfidence ( double  confidence)
Parameters
confidencethe confidence parameter of this operator.

Definition at line 109 of file ModalOperator.cpp.

109  {
110  parameters_[KEY_CONFIDENCE] = std::make_shared<Double>(confidence);
111 }
std::optional< double > confidence() const

◆ setConfidence() [2/2]

void knowrob::ModalOperator::setConfidence ( double  confidence)
Parameters
confidencethe confidence parameter of this operator.

◆ setEnd() [1/2]

void ModalOperator::setEnd ( double  end)
Parameters
endthe time interval end parameter of this operator.

Definition at line 133 of file ModalOperator.cpp.

133  {
134  parameters_[KEY_END] = std::make_shared<Double>(end);
135 }
std::optional< double > end() const

◆ setEnd() [2/2]

void knowrob::ModalOperator::setEnd ( double  end)
Parameters
endthe time interval end parameter of this operator.

◆ setParameter() [1/2]

void ModalOperator::setParameter ( std::string_view  key,
const TermPtr value 
)
Parameters
keythe key of the parameter.
valuethe value of the parameter.

Definition at line 77 of file ModalOperator.cpp.

77  {
78  parameters_[key.data()] = value;
79 }

◆ setParameter() [2/2]

void knowrob::ModalOperator::setParameter ( std::string_view  key,
const TermPtr value 
)
Parameters
keythe key of the parameter.
valuethe value of the parameter.

◆ setPerspective() [1/2]

void ModalOperator::setPerspective ( const std::string_view &  agent)
Parameters
agentthe perspective parameter of this operator.

Definition at line 97 of file ModalOperator.cpp.

97  {
99 }
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
Definition: Atom.cpp:40

◆ setPerspective() [2/2]

void knowrob::ModalOperator::setPerspective ( const std::string_view &  agent)
Parameters
agentthe perspective parameter of this operator.

◆ setTimeInterval() [1/2]

void ModalOperator::setTimeInterval ( const TimeInterval timeInterval)
Returns
the time interval parameter of this operator if any.

Definition at line 137 of file ModalOperator.cpp.

137  {
138  if (timeInterval.since()) {
139  setBegin(time::toSeconds(*timeInterval.since()));
140  }
141  if (timeInterval.until()) {
142  setEnd(time::toSeconds(*timeInterval.until()));
143  }
144 }
void setBegin(double begin)
void setEnd(double end)
const auto & since() const
Definition: TimeInterval.h:59
const auto & until() const
Definition: TimeInterval.h:64
double toSeconds(const TimePoint &timestamp)
Definition: TimePoint.cpp:23

◆ setTimeInterval() [2/2]

void knowrob::ModalOperator::setTimeInterval ( const TimeInterval timeInterval)
Returns
the time interval parameter of this operator if any.

◆ symbol() [1/2]

const char * ModalOperator::symbol ( ) const
Returns
the symbol of this modal operator.

Definition at line 17 of file ModalOperator.cpp.

17  {
18  switch (modalType_) {
20  return "K";
21  case ModalType::BELIEF:
22  return "B";
23  case ModalType::ALWAYS:
24  return "H";
26  return "P";
27  }
28  return "K";
29 }

◆ symbol() [2/2]

const char* knowrob::ModalOperator::symbol ( ) const
Returns
the symbol of this modal operator.

◆ write() [1/2]

void ModalOperator::write ( std::ostream &  os) const
Parameters
osthe output stream.

Definition at line 31 of file ModalOperator.cpp.

31  {
32  os << symbol();
33 
34  if (!parameters_.empty()) {
35  os << '[';
36  int paramIndex = 0;
37  for (auto &pair: parameters_) {
38  if (paramIndex++ > 0) os << ", ";
39  os << pair.first << '=' << *pair.second;
40  }
41  os << ']';
42  }
43 }
const char * symbol() const

◆ write() [2/2]

void knowrob::ModalOperator::write ( std::ostream &  os) const
Parameters
osthe output stream.

Member Data Documentation

◆ KEY_BEGIN

static constexpr const char * knowrob::ModalOperator::KEY_BEGIN = "begin"
staticconstexpr

Definition at line 35 of file ModalOperator.h.

◆ KEY_CONFIDENCE

static constexpr const char * knowrob::ModalOperator::KEY_CONFIDENCE = "confidence"
staticconstexpr

Definition at line 34 of file ModalOperator.h.

◆ KEY_END

static constexpr const char * knowrob::ModalOperator::KEY_END = "end"
staticconstexpr

Definition at line 36 of file ModalOperator.h.

◆ KEY_PERSPECTIVE

static constexpr const char * knowrob::ModalOperator::KEY_PERSPECTIVE = "agent"
staticconstexpr

Definition at line 33 of file ModalOperator.h.

◆ modalType_

const ModalType knowrob::ModalOperator::modalType_
protected

Definition at line 132 of file ModalOperator.h.

◆ parameters_

std::map< std::string, TermPtr > knowrob::ModalOperator::parameters_
protected

Definition at line 133 of file ModalOperator.h.


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