knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::Triple Class Referenceabstract

#include <Triple.h>

Inheritance diagram for knowrob::Triple:
Collaboration diagram for knowrob::Triple:

Public Member Functions

 Triple ()
 
 Triple (XSDType xsdType)
 
virtual ~Triple ()=default
 
bool mergeFrame (const Triple &other)
 
bool isXSDLiteral () const
 
bool isSubjectBlank () const
 
bool isObjectBlank () const
 
bool isObjectIRI () const
 
bool isSubjectIRI () const
 
auto xsdType () const
 
auto xsdTypeIRI () const
 
void setXSDValue (std::string_view v, XSDType type)
 
std::string createStringValue () const
 
virtual std::string_view subject () const =0
 
virtual std::string_view predicate () const =0
 
virtual std::string_view valueAsString () const =0
 
virtual float valueAsFloat () const =0
 
virtual double valueAsDouble () const =0
 
virtual long valueAsLong () const =0
 
virtual int valueAsInt () const =0
 
virtual bool valueAsBoolean () const =0
 
virtual short valueAsShort () const =0
 
virtual unsigned long valueAsUnsignedLong () const =0
 
virtual unsigned int valueAsUnsignedInt () const =0
 
virtual unsigned short valueAsUnsignedShort () const =0
 
virtual std::optional< std::string_view > graph () const =0
 
virtual std::optional< std::string_view > perspective () const =0
 
virtual void setSubject (std::string_view subject)=0
 
virtual void setPredicate (std::string_view predicate)=0
 
virtual void setObjectIRI (std::string_view object)=0
 
virtual void setSubjectBlank (std::string_view str)=0
 
virtual void setObjectBlank (std::string_view str)=0
 
virtual void setStringValue (std::string_view v)=0
 
virtual void setDoubleValue (double v)=0
 
virtual void setFloatValue (float v)=0
 
virtual void setIntValue (int v)=0
 
virtual void setBooleanValue (bool v)=0
 
virtual void setLongValue (long v)=0
 
virtual void setShortValue (short v)=0
 
virtual void setUnsignedIntValue (unsigned int v)=0
 
virtual void setUnsignedLongValue (unsigned long v)=0
 
virtual void setUnsignedShortValue (unsigned short v)=0
 
virtual void setGraph (std::string_view graph)=0
 
virtual void setPerspective (std::string_view perspective)=0
 
bool isOccasional () const
 
bool isUncertain () const
 
auto begin () const
 
auto end () const
 
auto confidence () const
 
void setIsOccasional (bool isOccasional)
 
void setIsUncertain (bool isUncertain)
 
void setBegin (double begin)
 
void setEnd (double end)
 
void setConfidence (double confidence)
 
virtual void reset ()=0
 
bool operator== (const Triple &other) const
 
bool operator< (const Triple &other) const
 
void write (std::ostream &os) const override
 
 Triple ()
 
 Triple (XSDType xsdType)
 
virtual ~Triple ()=default
 
bool mergeFrame (const Triple &other)
 
bool isXSDLiteral () const
 
bool isSubjectBlank () const
 
bool isObjectBlank () const
 
bool isObjectIRI () const
 
bool isSubjectIRI () const
 
auto xsdType () const
 
auto xsdTypeIRI () const
 
void setXSDValue (std::string_view v, XSDType type)
 
std::string createStringValue () const
 
virtual std::string_view subject () const =0
 
virtual std::string_view predicate () const =0
 
virtual std::string_view valueAsString () const =0
 
virtual float valueAsFloat () const =0
 
virtual double valueAsDouble () const =0
 
virtual long valueAsLong () const =0
 
virtual int valueAsInt () const =0
 
virtual bool valueAsBoolean () const =0
 
virtual short valueAsShort () const =0
 
virtual unsigned long valueAsUnsignedLong () const =0
 
virtual unsigned int valueAsUnsignedInt () const =0
 
virtual unsigned short valueAsUnsignedShort () const =0
 
virtual std::optional< std::string_view > graph () const =0
 
virtual std::optional< std::string_view > perspective () const =0
 
virtual void setSubject (std::string_view subject)=0
 
virtual void setPredicate (std::string_view predicate)=0
 
virtual void setObjectIRI (std::string_view object)=0
 
virtual void setSubjectBlank (std::string_view str)=0
 
virtual void setObjectBlank (std::string_view str)=0
 
virtual void setStringValue (std::string_view v)=0
 
virtual void setDoubleValue (double v)=0
 
virtual void setFloatValue (float v)=0
 
virtual void setIntValue (int v)=0
 
virtual void setBooleanValue (bool v)=0
 
virtual void setLongValue (long v)=0
 
virtual void setShortValue (short v)=0
 
virtual void setUnsignedIntValue (unsigned int v)=0
 
virtual void setUnsignedLongValue (unsigned long v)=0
 
virtual void setUnsignedShortValue (unsigned short v)=0
 
virtual void setGraph (std::string_view graph)=0
 
virtual void setPerspective (std::string_view perspective)=0
 
bool isOccasional () const
 
bool isUncertain () const
 
auto begin () const
 
auto end () const
 
auto confidence () const
 
void setIsOccasional (bool isOccasional)
 
void setIsUncertain (bool isUncertain)
 
void setBegin (double begin)
 
void setEnd (double end)
 
void setConfidence (double confidence)
 
virtual void reset ()=0
 
bool operator== (const Triple &other) const
 
bool operator< (const Triple &other) 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
 

Static Protected Member Functions

static bool isBlank (std::string_view str)
 
static bool isBlank (std::string_view str)
 

Protected Attributes

bool isOccasional_
 
bool isUncertain_
 
std::optional< double > begin_
 
std::optional< double > end_
 
std::optional< double > confidence_
 
std::optional< XSDTypexsdType_
 

Detailed Description

A triple with additional information about its origin, epistemic and temporal context. This is an abstract class to support both std::string and std::string_view for triple data, however, at the cost of having some virtual methods.

Definition at line 20 of file Triple.h.

Constructor & Destructor Documentation

◆ Triple() [1/4]

knowrob::Triple::Triple ( )
inlineexplicit

Definition at line 22 of file Triple.h.

23  : isOccasional_(false), isUncertain_(false), xsdType_(std::nullopt) {}
bool isOccasional_
Definition: Triple.h:330
bool isUncertain_
Definition: Triple.h:331
std::optional< XSDType > xsdType_
Definition: Triple.h:335

◆ Triple() [2/4]

knowrob::Triple::Triple ( XSDType  xsdType)
inlineexplicit

Definition at line 25 of file Triple.h.

26  : isOccasional_(false), isUncertain_(false), xsdType_(xsdType) {}
auto xsdType() const
Definition: Triple.h:64

◆ ~Triple() [1/2]

virtual knowrob::Triple::~Triple ( )
virtualdefault

◆ Triple() [3/4]

knowrob::Triple::Triple ( )
inlineexplicit

Definition at line 22 of file Triple.h.

23  : isOccasional_(false), isUncertain_(false), xsdType_(std::nullopt) {}

◆ Triple() [4/4]

knowrob::Triple::Triple ( XSDType  xsdType)
inlineexplicit

Definition at line 25 of file Triple.h.

26  : isOccasional_(false), isUncertain_(false), xsdType_(xsdType) {}

◆ ~Triple() [2/2]

virtual knowrob::Triple::~Triple ( )
virtualdefault

Member Function Documentation

◆ begin() [1/2]

auto knowrob::Triple::begin ( ) const
inline
Returns
the begin of the triple.

Definition at line 272 of file Triple.h.

272 { return begin_; }
std::optional< double > begin_
Definition: Triple.h:332

◆ begin() [2/2]

auto knowrob::Triple::begin ( ) const
inline
Returns
the begin of the triple.

Definition at line 272 of file Triple.h.

272 { return begin_; }

◆ confidence() [1/2]

auto knowrob::Triple::confidence ( ) const
inline
Returns
the confidence of the triple.

Definition at line 282 of file Triple.h.

282 { return confidence_; }
std::optional< double > confidence_
Definition: Triple.h:334

◆ confidence() [2/2]

auto knowrob::Triple::confidence ( ) const
inline
Returns
the confidence of the triple.

Definition at line 282 of file Triple.h.

282 { return confidence_; }

◆ createStringValue() [1/2]

std::string Triple::createStringValue ( ) const

Construct string form of the object of the triple.

Returns
the string form of the object.

Definition at line 71 of file Triple.cpp.

71  {
72  static const auto a_true = "true";
73  static const auto a_false = "false";
74 
75  if (isObjectIRI() || isObjectBlank()) {
76  return std::string(valueAsString());
77  }
78 
79  if (xsdType()) {
80  switch (xsdType().value()) {
81  case XSDType::DOUBLE: {
82  std::ostringstream os;
83  os << std::fixed << valueAsDouble();
84  return os.str();
85  }
86  case XSDType::FLOAT: {
87  std::ostringstream os;
88  os << std::fixed << valueAsFloat();
89  return os.str();
90  }
92  case XSDType::INTEGER:
93  return std::to_string(valueAsInt());
94  case XSDType::LONG:
95  return std::to_string(valueAsLong());
96  case XSDType::SHORT:
97  return std::to_string(valueAsShort());
99  return std::to_string(valueAsUnsignedLong());
101  return std::to_string(valueAsUnsignedInt());
103  return std::to_string(valueAsUnsignedShort());
104  case XSDType::BOOLEAN:
105  return valueAsBoolean() ? a_true : a_false;
106  case XSDType::STRING:
107  return std::string(valueAsString());
108  case XSDType::LAST:
109  break;
110  }
111  }
112 
113  return "null";
114 }
virtual std::string_view valueAsString() const =0
virtual short valueAsShort() const =0
virtual unsigned int valueAsUnsignedInt() const =0
virtual double valueAsDouble() const =0
virtual float valueAsFloat() const =0
virtual long valueAsLong() const =0
bool isObjectIRI() const
Definition: Triple.h:54
virtual unsigned short valueAsUnsignedShort() const =0
virtual unsigned long valueAsUnsignedLong() const =0
bool isObjectBlank() const
Definition: Triple.h:49
virtual int valueAsInt() const =0
virtual bool valueAsBoolean() const =0
TermRule & string()
Definition: terms.cpp:63

◆ createStringValue() [2/2]

std::string knowrob::Triple::createStringValue ( ) const

Construct string form of the object of the triple.

Returns
the string form of the object.

◆ end() [1/2]

auto knowrob::Triple::end ( ) const
inline
Returns
the end of the triple.

Definition at line 277 of file Triple.h.

277 { return end_; }
std::optional< double > end_
Definition: Triple.h:333

◆ end() [2/2]

auto knowrob::Triple::end ( ) const
inline
Returns
the end of the triple.

Definition at line 277 of file Triple.h.

277 { return end_; }

◆ graph() [1/2]

virtual std::optional<std::string_view> knowrob::Triple::graph ( ) const
pure virtual
Returns
the graph of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ graph() [2/2]

virtual std::optional<std::string_view> knowrob::Triple::graph ( ) const
pure virtual
Returns
the graph of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ isBlank() [1/2]

static bool knowrob::Triple::isBlank ( std::string_view  str)
inlinestaticprotected

Definition at line 337 of file Triple.h.

337  {
338  return str.empty() || str[0] == '_';
339  }

◆ isBlank() [2/2]

static bool knowrob::Triple::isBlank ( std::string_view  str)
inlinestaticprotected

Definition at line 337 of file Triple.h.

337  {
338  return str.empty() || str[0] == '_';
339  }

◆ isObjectBlank() [1/2]

bool knowrob::Triple::isObjectBlank ( ) const
inline
Returns
true if the object of the triple is a blank node.

Definition at line 49 of file Triple.h.

49 { return !isXSDLiteral() && isBlank(valueAsString()); }
static bool isBlank(std::string_view str)
Definition: Triple.h:337
bool isXSDLiteral() const
Definition: Triple.h:39

◆ isObjectBlank() [2/2]

bool knowrob::Triple::isObjectBlank ( ) const
inline
Returns
true if the object of the triple is a blank node.

Definition at line 49 of file Triple.h.

49 { return !isXSDLiteral() && isBlank(valueAsString()); }

◆ isObjectIRI() [1/2]

bool knowrob::Triple::isObjectIRI ( ) const
inline
Returns
true if the object of the triple is a IRI.

Definition at line 54 of file Triple.h.

54 { return !isXSDLiteral() && !isBlank(valueAsString()); }

◆ isObjectIRI() [2/2]

bool knowrob::Triple::isObjectIRI ( ) const
inline
Returns
true if the object of the triple is a IRI.

Definition at line 54 of file Triple.h.

54 { return !isXSDLiteral() && !isBlank(valueAsString()); }

◆ isOccasional() [1/2]

bool knowrob::Triple::isOccasional ( ) const
inline
Returns
true if the triple is occasionally true.

Definition at line 262 of file Triple.h.

262 { return isOccasional_; }

◆ isOccasional() [2/2]

bool knowrob::Triple::isOccasional ( ) const
inline
Returns
true if the triple is occasionally true.

Definition at line 262 of file Triple.h.

262 { return isOccasional_; }

◆ isSubjectBlank() [1/2]

bool knowrob::Triple::isSubjectBlank ( ) const
inline
Returns
true if the subject of the triple is a blank node.

Definition at line 44 of file Triple.h.

44 { return isBlank(subject()); }
virtual std::string_view subject() const =0

◆ isSubjectBlank() [2/2]

bool knowrob::Triple::isSubjectBlank ( ) const
inline
Returns
true if the subject of the triple is a blank node.

Definition at line 44 of file Triple.h.

44 { return isBlank(subject()); }

◆ isSubjectIRI() [1/2]

bool knowrob::Triple::isSubjectIRI ( ) const
inline
Returns
true if the subject of the triple is a IRI.

Definition at line 59 of file Triple.h.

59 { return !isSubjectBlank(); }
bool isSubjectBlank() const
Definition: Triple.h:44

◆ isSubjectIRI() [2/2]

bool knowrob::Triple::isSubjectIRI ( ) const
inline
Returns
true if the subject of the triple is a IRI.

Definition at line 59 of file Triple.h.

59 { return !isSubjectBlank(); }

◆ isUncertain() [1/2]

bool knowrob::Triple::isUncertain ( ) const
inline
Returns
true if the triple is uncertain.

Definition at line 267 of file Triple.h.

267 { return isUncertain_; }

◆ isUncertain() [2/2]

bool knowrob::Triple::isUncertain ( ) const
inline
Returns
true if the triple is uncertain.

Definition at line 267 of file Triple.h.

267 { return isUncertain_; }

◆ isXSDLiteral() [1/2]

bool knowrob::Triple::isXSDLiteral ( ) const
inline
Returns
true if the object of the triple is a XSD literal.

Definition at line 39 of file Triple.h.

39 { return xsdType_.has_value(); }

◆ isXSDLiteral() [2/2]

bool knowrob::Triple::isXSDLiteral ( ) const
inline
Returns
true if the object of the triple is a XSD literal.

Definition at line 39 of file Triple.h.

39 { return xsdType_.has_value(); }

◆ mergeFrame() [1/2]

bool Triple::mergeFrame ( const Triple other)

Merge the frame of the triple with another triple.

Parameters
otheranother triple.

Definition at line 274 of file Triple.cpp.

274  {
275  bool sameBegin = begin() == other.begin();
276  bool sameEnd = end() == other.end();
277  bool sameTime = sameBegin && sameEnd;
278 
279  if (sameTime) {
280  // occasional can switch to always if both triples have the same time
282  // same for uncertain vs. certain
283  setIsUncertain(isUncertain() && other.isUncertain());
284  // plus we can take the max confidence
285  if (other.confidence().has_value() && confidence().has_value()) {
286  setConfidence(std::max(confidence().value(), other.confidence().value()));
287  } else if (!other.confidence().has_value()) {
288  confidence_ = std::nullopt;
289  }
290  } else {
291  // either both triples must be occasional or neither
292  if (isOccasional() != other.isOccasional()) return false;
293  // same for uncertain vs. certain
294  if (isUncertain() != other.isUncertain()) return false;
295  // also confidence must match in order to merge different time frames
296  if (confidence() != other.confidence()) return false;
297  // finally we can merge time frame
298  if (isOccasional()) {
299  if (begin() && other.begin()) {
300  setBegin(std::max(begin().value(), other.begin().value()));
301  } else if (other.begin()) {
302  setBegin(other.begin().value());
303  }
304  if (end() && other.end()) {
305  setEnd(std::min(end().value(), other.end().value()));
306  } else if (other.end()) {
307  setEnd(other.end().value());
308  }
309  } else {
310  if (begin() && other.begin()) {
311  setBegin(std::min(begin().value(), other.begin().value()));
312  } else if (!other.begin().has_value()) {
313  begin_ = std::nullopt;
314  }
315  if (end() && other.end()) {
316  setEnd(std::max(end().value(), other.end().value()));
317  } else if (!other.end().has_value()) {
318  end_ = std::nullopt;
319  }
320  }
321  }
322  return true;
323 }
bool isUncertain() const
Definition: Triple.h:267
auto end() const
Definition: Triple.h:277
void setConfidence(double confidence)
Definition: Triple.h:307
auto confidence() const
Definition: Triple.h:282
void setIsUncertain(bool isUncertain)
Definition: Triple.h:292
auto begin() const
Definition: Triple.h:272
void setIsOccasional(bool isOccasional)
Definition: Triple.h:287
void setBegin(double begin)
Definition: Triple.h:297
void setEnd(double end)
Definition: Triple.h:302
bool isOccasional() const
Definition: Triple.h:262

◆ mergeFrame() [2/2]

bool knowrob::Triple::mergeFrame ( const Triple other)

Merge the frame of the triple with another triple.

Parameters
otheranother triple.

◆ operator<() [1/2]

bool Triple::operator< ( const Triple other) const
Parameters
otheranother triple.
Returns
true if this triple is less than the other triple.

Definition at line 116 of file Triple.cpp.

116  {
117  if (graph() != other.graph()) {
118  return graph() < other.graph();
119  }
120  if (perspective() != other.perspective()) {
121  return perspective() < other.perspective();
122  }
123  if (subject() != other.subject()) {
124  return subject() < other.subject();
125  }
126  if (predicate() != other.predicate()) {
127  return predicate() < other.predicate();
128  }
129  if (xsdType() != other.xsdType()) {
130  return xsdType() < other.xsdType();
131  }
132  if (xsdType()) {
133  switch (xsdType().value()) {
134  case XSDType::STRING:
135  if (valueAsString() != other.valueAsString()) {
136  return valueAsString() < other.valueAsString();
137  } else {
138  break;
139  }
140  case XSDType::DOUBLE:
141  if (valueAsDouble() != other.valueAsDouble()) {
142  return valueAsDouble() < other.valueAsDouble();
143  } else {
144  break;
145  }
146  case XSDType::FLOAT:
147  if (valueAsFloat() != other.valueAsFloat()) {
148  return valueAsFloat() < other.valueAsFloat();
149  } else {
150  break;
151  }
153  case XSDType::INTEGER:
154  if (valueAsInt() != other.valueAsInt()) {
155  return valueAsInt() < other.valueAsInt();
156  } else {
157  break;
158  }
159  case XSDType::BOOLEAN:
160  if (valueAsBoolean() != other.valueAsBoolean()) {
161  return valueAsBoolean() < other.valueAsBoolean();
162  } else {
163  break;
164  }
165  case XSDType::LONG:
166  if (valueAsLong() != other.valueAsLong()) {
167  return valueAsLong() < other.valueAsLong();
168  } else {
169  break;
170  }
171  case XSDType::SHORT:
172  if (valueAsShort() != other.valueAsShort()) {
173  return valueAsShort() < other.valueAsShort();
174  } else {
175  break;
176  }
178  if (valueAsUnsignedLong() != other.valueAsUnsignedLong()) {
179  return valueAsUnsignedLong() < other.valueAsUnsignedLong();
180  } else {
181  break;
182  }
184  if (valueAsUnsignedInt() != other.valueAsUnsignedInt()) {
185  return valueAsUnsignedInt() < other.valueAsUnsignedInt();
186  } else {
187  break;
188  }
190  if (valueAsUnsignedShort() != other.valueAsUnsignedShort()) {
191  return valueAsUnsignedShort() < other.valueAsUnsignedShort();
192  } else {
193  break;
194  }
195  case XSDType::LAST:
196  KB_ERROR("Invalid XSD type");
197  break;
198  }
199  } else if (valueAsString() != other.valueAsString()) {
200  return valueAsString() < other.valueAsString();
201  }
202  if (isUncertain() != other.isUncertain()) {
203  return isUncertain() < other.isUncertain();
204  }
205  if (isOccasional() != other.isOccasional()) {
206  return isOccasional() < other.isOccasional();
207  }
208  if (begin() != other.begin()) {
209  return begin() < other.begin();
210  }
211  if (end() != other.end()) {
212  return end() < other.end();
213  }
214  if (confidence() != other.confidence()) {
215  return confidence() < other.confidence();
216  }
217  return false;
218 }
#define KB_ERROR
Definition: Logger.h:28
virtual std::optional< std::string_view > perspective() const =0
virtual std::optional< std::string_view > graph() const =0
virtual std::string_view predicate() const =0

◆ operator<() [2/2]

bool knowrob::Triple::operator< ( const Triple other) const
Parameters
otheranother triple.
Returns
true if this triple is less than the other triple.

◆ operator==() [1/2]

bool Triple::operator== ( const Triple other) const
Parameters
otheranother triple.
Returns
true if the two triples are equal.

Definition at line 220 of file Triple.cpp.

220  {
221  if (subject() != other.subject()) return false;
222  if (predicate() != other.predicate()) return false;
223  if (graph(), other.graph()) return false;
224  if (perspective(), other.perspective()) return false;
225  if (isUncertain() != other.isUncertain()) return false;
226  if (isOccasional() != other.isOccasional()) return false;
227  if (begin() != other.begin()) return false;
228  if (end() != other.end()) return false;
229  if (confidence() != other.confidence()) return false;
230  if (xsdType() != other.xsdType()) return false;
231  if (xsdType()) {
232  switch (xsdType().value()) {
233  case XSDType::STRING:
234  if (valueAsString() != other.valueAsString()) return false;
235  break;
236  case XSDType::DOUBLE:
237  if (valueAsDouble() != other.valueAsDouble()) return false;
238  break;
239  case XSDType::FLOAT:
240  if (valueAsFloat() != other.valueAsFloat()) return false;
241  break;
242  case XSDType::BOOLEAN:
243  if (valueAsBoolean() != other.valueAsBoolean()) return false;
244  break;
246  case XSDType::INTEGER:
247  if (valueAsInt() != other.valueAsInt()) return false;
248  break;
249  case XSDType::LONG:
250  if (valueAsLong() != other.valueAsLong()) return false;
251  break;
252  case XSDType::SHORT:
253  if (valueAsShort() != other.valueAsShort()) return false;
254  break;
256  if (valueAsUnsignedLong() != other.valueAsUnsignedLong()) return false;
257  break;
259  if (valueAsUnsignedInt() != other.valueAsUnsignedInt()) return false;
260  break;
262  if (valueAsUnsignedShort() != other.valueAsUnsignedShort()) return false;
263  break;
264  case XSDType::LAST:
265  KB_ERROR("Invalid XSD type");
266  break;
267  }
268  } else if (valueAsString() != other.valueAsString()) {
269  return false;
270  }
271  return true;
272 }

◆ operator==() [2/2]

bool knowrob::Triple::operator== ( const Triple other) const
Parameters
otheranother triple.
Returns
true if the two triples are equal.

◆ perspective() [1/2]

virtual std::optional<std::string_view> knowrob::Triple::perspective ( ) const
pure virtual
Returns
the perspective of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ perspective() [2/2]

virtual std::optional<std::string_view> knowrob::Triple::perspective ( ) const
pure virtual
Returns
the perspective of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ predicate() [1/2]

virtual std::string_view knowrob::Triple::predicate ( ) const
pure virtual
Returns
the predicate of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ predicate() [2/2]

virtual std::string_view knowrob::Triple::predicate ( ) const
pure virtual
Returns
the predicate of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ reset() [1/2]

virtual void knowrob::Triple::reset ( )
pure virtual

Reset the triple to its initial state.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ reset() [2/2]

virtual void knowrob::Triple::reset ( )
pure virtual

Reset the triple to its initial state.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setBegin() [1/2]

void knowrob::Triple::setBegin ( double  begin)
inline
Parameters
beginthe begin of the triple.

Definition at line 297 of file Triple.h.

297 { begin_ = begin; }

◆ setBegin() [2/2]

void knowrob::Triple::setBegin ( double  begin)
inline
Parameters
beginthe begin of the triple.

Definition at line 297 of file Triple.h.

297 { begin_ = begin; }

◆ setBooleanValue() [1/2]

virtual void knowrob::Triple::setBooleanValue ( bool  v)
pure virtual

Assign a boolean value to the object of the triple.

Parameters
vthe boolean value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setBooleanValue() [2/2]

virtual void knowrob::Triple::setBooleanValue ( bool  v)
pure virtual

Assign a boolean value to the object of the triple.

Parameters
vthe boolean value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setConfidence() [1/2]

void knowrob::Triple::setConfidence ( double  confidence)
inline
Parameters
confidencethe confidence of the triple.

Definition at line 307 of file Triple.h.

307 { confidence_ = confidence; }

◆ setConfidence() [2/2]

void knowrob::Triple::setConfidence ( double  confidence)
inline
Parameters
confidencethe confidence of the triple.

Definition at line 307 of file Triple.h.

307 { confidence_ = confidence; }

◆ setDoubleValue() [1/2]

virtual void knowrob::Triple::setDoubleValue ( double  v)
pure virtual

Assign a double value to the object of the triple.

Parameters
vthe double value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setDoubleValue() [2/2]

virtual void knowrob::Triple::setDoubleValue ( double  v)
pure virtual

Assign a double value to the object of the triple.

Parameters
vthe double value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setEnd() [1/2]

void knowrob::Triple::setEnd ( double  end)
inline
Parameters
endthe end of the triple.

Definition at line 302 of file Triple.h.

302 { end_ = end; }

◆ setEnd() [2/2]

void knowrob::Triple::setEnd ( double  end)
inline
Parameters
endthe end of the triple.

Definition at line 302 of file Triple.h.

302 { end_ = end; }

◆ setFloatValue() [1/2]

virtual void knowrob::Triple::setFloatValue ( float  v)
pure virtual

Assign a float value to the object of the triple.

Parameters
vthe float value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setFloatValue() [2/2]

virtual void knowrob::Triple::setFloatValue ( float  v)
pure virtual

Assign a float value to the object of the triple.

Parameters
vthe float value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setGraph() [1/2]

virtual void knowrob::Triple::setGraph ( std::string_view  graph)
pure virtual
Parameters
graphthe graph of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setGraph() [2/2]

virtual void knowrob::Triple::setGraph ( std::string_view  graph)
pure virtual
Parameters
graphthe graph of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setIntValue() [1/2]

virtual void knowrob::Triple::setIntValue ( int  v)
pure virtual

Assign a int value to the object of the triple.

Parameters
vthe int value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setIntValue() [2/2]

virtual void knowrob::Triple::setIntValue ( int  v)
pure virtual

Assign a int value to the object of the triple.

Parameters
vthe int value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setIsOccasional() [1/2]

void knowrob::Triple::setIsOccasional ( bool  isOccasional)
inline
Parameters
isOccasionaltrue if the triple is occasionally true.

Definition at line 287 of file Triple.h.

◆ setIsOccasional() [2/2]

void knowrob::Triple::setIsOccasional ( bool  isOccasional)
inline
Parameters
isOccasionaltrue if the triple is occasionally true.

Definition at line 287 of file Triple.h.

◆ setIsUncertain() [1/2]

void knowrob::Triple::setIsUncertain ( bool  isUncertain)
inline
Parameters
isUncertaintrue if the triple is uncertain.

Definition at line 292 of file Triple.h.

◆ setIsUncertain() [2/2]

void knowrob::Triple::setIsUncertain ( bool  isUncertain)
inline
Parameters
isUncertaintrue if the triple is uncertain.

Definition at line 292 of file Triple.h.

◆ setLongValue() [1/2]

virtual void knowrob::Triple::setLongValue ( long  v)
pure virtual

Assign a long value to the object of the triple.

Parameters
vthe long value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setLongValue() [2/2]

virtual void knowrob::Triple::setLongValue ( long  v)
pure virtual

Assign a long value to the object of the triple.

Parameters
vthe long value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setObjectBlank() [1/2]

virtual void knowrob::Triple::setObjectBlank ( std::string_view  str)
pure virtual
Parameters
stra blank node identifier for the object of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setObjectBlank() [2/2]

virtual void knowrob::Triple::setObjectBlank ( std::string_view  str)
pure virtual
Parameters
stra blank node identifier for the object of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setObjectIRI() [1/2]

virtual void knowrob::Triple::setObjectIRI ( std::string_view  object)
pure virtual
Parameters
objectthe object of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setObjectIRI() [2/2]

virtual void knowrob::Triple::setObjectIRI ( std::string_view  object)
pure virtual
Parameters
objectthe object of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setPerspective() [1/2]

virtual void knowrob::Triple::setPerspective ( std::string_view  perspective)
pure virtual
Parameters
perspectivethe perspective of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setPerspective() [2/2]

virtual void knowrob::Triple::setPerspective ( std::string_view  perspective)
pure virtual
Parameters
perspectivethe perspective of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setPredicate() [1/2]

virtual void knowrob::Triple::setPredicate ( std::string_view  predicate)
pure virtual
Parameters
predicatethe predicate of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setPredicate() [2/2]

virtual void knowrob::Triple::setPredicate ( std::string_view  predicate)
pure virtual
Parameters
predicatethe predicate of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setShortValue() [1/2]

virtual void knowrob::Triple::setShortValue ( short  v)
pure virtual

Assign a short value to the object of the triple.

Parameters
vthe short value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setShortValue() [2/2]

virtual void knowrob::Triple::setShortValue ( short  v)
pure virtual

Assign a short value to the object of the triple.

Parameters
vthe short value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setStringValue() [1/2]

virtual void knowrob::Triple::setStringValue ( std::string_view  v)
pure virtual

Assign a string value to the object of the triple.

Parameters
vthe string value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setStringValue() [2/2]

virtual void knowrob::Triple::setStringValue ( std::string_view  v)
pure virtual

Assign a string value to the object of the triple.

Parameters
vthe string value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setSubject() [1/2]

virtual void knowrob::Triple::setSubject ( std::string_view  subject)
pure virtual
Parameters
subjectthe subject of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setSubject() [2/2]

virtual void knowrob::Triple::setSubject ( std::string_view  subject)
pure virtual
Parameters
subjectthe subject of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setSubjectBlank() [1/2]

virtual void knowrob::Triple::setSubjectBlank ( std::string_view  str)
pure virtual
Parameters
stra blank node identifier for the subject of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setSubjectBlank() [2/2]

virtual void knowrob::Triple::setSubjectBlank ( std::string_view  str)
pure virtual
Parameters
stra blank node identifier for the subject of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setUnsignedIntValue() [1/2]

virtual void knowrob::Triple::setUnsignedIntValue ( unsigned int  v)
pure virtual

Assign a unsigned int value to the object of the triple.

Parameters
vthe unsigned int value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setUnsignedIntValue() [2/2]

virtual void knowrob::Triple::setUnsignedIntValue ( unsigned int  v)
pure virtual

Assign a unsigned int value to the object of the triple.

Parameters
vthe unsigned int value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setUnsignedLongValue() [1/2]

virtual void knowrob::Triple::setUnsignedLongValue ( unsigned long  v)
pure virtual

Assign a unsigned long value to the object of the triple.

Parameters
vthe unsigned long value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setUnsignedLongValue() [2/2]

virtual void knowrob::Triple::setUnsignedLongValue ( unsigned long  v)
pure virtual

Assign a unsigned long value to the object of the triple.

Parameters
vthe unsigned long value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setUnsignedShortValue() [1/2]

virtual void knowrob::Triple::setUnsignedShortValue ( unsigned short  v)
pure virtual

Assign a unsigned short value to the object of the triple.

Parameters
vthe unsigned short value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setUnsignedShortValue() [2/2]

virtual void knowrob::Triple::setUnsignedShortValue ( unsigned short  v)
pure virtual

Assign a unsigned short value to the object of the triple.

Parameters
vthe unsigned short value to assign.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ setXSDValue() [1/2]

void Triple::setXSDValue ( std::string_view  v,
XSDType  type 
)

Assign a XSD value to the object of the triple.

Parameters
vthe string form of a XSD value.
typethe XSD type of the value.

Definition at line 32 of file Triple.cpp.

32  {
33  switch (type) {
34  case XSDType::STRING:
35  setStringValue(v);
36  break;
37  case XSDType::DOUBLE:
38  setDoubleValue(xsdConvFixed<double>(v));
39  break;
40  case XSDType::FLOAT:
41  setDoubleValue(xsdConvFixed<float>(v));
42  break;
44  case XSDType::INTEGER:
45  setIntValue(xsdConv<int>(v));
46  break;
47  case XSDType::LONG:
48  setLongValue(xsdConv<long>(v));
49  break;
50  case XSDType::SHORT:
51  setShortValue(xsdConv<short>(v));
52  break;
54  setUnsignedLongValue(xsdConv<unsigned long>(v));
55  break;
57  setUnsignedIntValue(xsdConv<unsigned int>(v));
58  break;
60  setUnsignedShortValue(xsdConv<unsigned short>(v));
61  break;
62  case XSDType::BOOLEAN:
64  break;
65  case XSDType::LAST:
66  KB_ERROR("Invalid XSD type");
67  break;
68  }
69 }
bool xsdConvBool(std::string_view str)
Definition: Triple.cpp:26
virtual void setDoubleValue(double v)=0
virtual void setIntValue(int v)=0
virtual void setStringValue(std::string_view v)=0
virtual void setUnsignedLongValue(unsigned long v)=0
virtual void setLongValue(long v)=0
virtual void setUnsignedIntValue(unsigned int v)=0
virtual void setUnsignedShortValue(unsigned short v)=0
virtual void setShortValue(short v)=0
virtual void setBooleanValue(bool v)=0
const IRIAtomPtr type
Definition: rdf.h:15

◆ setXSDValue() [2/2]

void knowrob::Triple::setXSDValue ( std::string_view  v,
XSDType  type 
)

Assign a XSD value to the object of the triple.

Parameters
vthe string form of a XSD value.
typethe XSD type of the value.

◆ subject() [1/2]

virtual std::string_view knowrob::Triple::subject ( ) const
pure virtual
Returns
the subject of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ subject() [2/2]

virtual std::string_view knowrob::Triple::subject ( ) const
pure virtual
Returns
the subject of the triple.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsBoolean() [1/2]

virtual bool knowrob::Triple::valueAsBoolean ( ) const
pure virtual

Read the object part of the triple as a boolean.

Returns
the object as a boolean.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsBoolean() [2/2]

virtual bool knowrob::Triple::valueAsBoolean ( ) const
pure virtual

Read the object part of the triple as a boolean.

Returns
the object as a boolean.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsDouble() [1/2]

virtual double knowrob::Triple::valueAsDouble ( ) const
pure virtual

Read the object part of the triple as a double.

Returns
the object as a double.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsDouble() [2/2]

virtual double knowrob::Triple::valueAsDouble ( ) const
pure virtual

Read the object part of the triple as a double.

Returns
the object as a double.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsFloat() [1/2]

virtual float knowrob::Triple::valueAsFloat ( ) const
pure virtual

Read the object part of the triple as a float.

Returns
the object as a float.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsFloat() [2/2]

virtual float knowrob::Triple::valueAsFloat ( ) const
pure virtual

Read the object part of the triple as a float.

Returns
the object as a float.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsInt() [1/2]

virtual int knowrob::Triple::valueAsInt ( ) const
pure virtual

Read the object part of the triple as a int.

Returns
the object as a int.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsInt() [2/2]

virtual int knowrob::Triple::valueAsInt ( ) const
pure virtual

Read the object part of the triple as a int.

Returns
the object as a int.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsLong() [1/2]

virtual long knowrob::Triple::valueAsLong ( ) const
pure virtual

Read the object part of the triple as a long.

Returns
the object as a long.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsLong() [2/2]

virtual long knowrob::Triple::valueAsLong ( ) const
pure virtual

Read the object part of the triple as a long.

Returns
the object as a long.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsShort() [1/2]

virtual short knowrob::Triple::valueAsShort ( ) const
pure virtual

Read the object part of the triple as a short.

Returns
the object as a short.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsShort() [2/2]

virtual short knowrob::Triple::valueAsShort ( ) const
pure virtual

Read the object part of the triple as a short.

Returns
the object as a short.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsString() [1/2]

virtual std::string_view knowrob::Triple::valueAsString ( ) const
pure virtual

Read the object part of the triple as a string.

Returns
the object as a double.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsString() [2/2]

virtual std::string_view knowrob::Triple::valueAsString ( ) const
pure virtual

Read the object part of the triple as a string.

Returns
the object as a double.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsUnsignedInt() [1/2]

virtual unsigned int knowrob::Triple::valueAsUnsignedInt ( ) const
pure virtual

Read the object part of the triple as a unsigned int.

Returns
the object as a unsigned int.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsUnsignedInt() [2/2]

virtual unsigned int knowrob::Triple::valueAsUnsignedInt ( ) const
pure virtual

Read the object part of the triple as a unsigned int.

Returns
the object as a unsigned int.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsUnsignedLong() [1/2]

virtual unsigned long knowrob::Triple::valueAsUnsignedLong ( ) const
pure virtual

Read the object part of the triple as a unsigned long.

Returns
the object as a unsigned long.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsUnsignedLong() [2/2]

virtual unsigned long knowrob::Triple::valueAsUnsignedLong ( ) const
pure virtual

Read the object part of the triple as a unsigned long.

Returns
the object as a unsigned long.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsUnsignedShort() [1/2]

virtual unsigned short knowrob::Triple::valueAsUnsignedShort ( ) const
pure virtual

Read the object part of the triple as a unsigned short.

Returns
the object as a unsigned short.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ valueAsUnsignedShort() [2/2]

virtual unsigned short knowrob::Triple::valueAsUnsignedShort ( ) const
pure virtual

Read the object part of the triple as a unsigned short.

Returns
the object as a unsigned short.

Implemented in knowrob::TripleTemplate< StringType >, and knowrob::TripleTemplate< StringType >.

◆ write() [1/2]

void Triple::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 325 of file Triple.cpp.

325  {
326  os << '(';
327  os << subject() << ',' << ' ';
328  os << predicate() << ',' << ' ';
329  if (isObjectIRI() || isObjectBlank()) {
330  os << valueAsString();
331  } else {
332  os << createStringValue();
333  }
334  if (graph()) {
335  os << ',' << " g=" << graph().value();
336  }
337  if (perspective()) {
338  os << ',' << " p=" << perspective().value();
339  }
340  if (isOccasional()) {
341  os << ',' << " o";
342  }
343  if (isUncertain()) {
344  os << ',' << " u";
345  }
346  if (begin()) {
347  os << ',' << " b=" << begin().value();
348  }
349  if (end()) {
350  os << ',' << " e=" << end().value();
351  }
352  os << ')';
353 }
std::string createStringValue() const
Definition: Triple.cpp:71

◆ write() [2/2]

void knowrob::Triple::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

◆ xsdType() [1/2]

auto knowrob::Triple::xsdType ( ) const
inline
Returns
the object type of the triple.

Definition at line 64 of file Triple.h.

64 { return xsdType_; }

◆ xsdType() [2/2]

auto knowrob::Triple::xsdType ( ) const
inline
Returns
the object type of the triple.

Definition at line 64 of file Triple.h.

64 { return xsdType_; }

◆ xsdTypeIRI() [1/2]

auto knowrob::Triple::xsdTypeIRI ( ) const
inline
Returns
the IRI of the XSD type of the object of the triple.

Definition at line 69 of file Triple.h.

std::string_view xsdTypeToIRI(XSDType type)
Definition: XSDAtomic.cpp:70

◆ xsdTypeIRI() [2/2]

auto knowrob::Triple::xsdTypeIRI ( ) const
inline
Returns
the IRI of the XSD type of the object of the triple.

Definition at line 69 of file Triple.h.

Member Data Documentation

◆ begin_

std::optional< double > knowrob::Triple::begin_
protected

Definition at line 332 of file Triple.h.

◆ confidence_

std::optional< double > knowrob::Triple::confidence_
protected

Definition at line 334 of file Triple.h.

◆ end_

std::optional< double > knowrob::Triple::end_
protected

Definition at line 333 of file Triple.h.

◆ isOccasional_

bool knowrob::Triple::isOccasional_
protected

Definition at line 330 of file Triple.h.

◆ isUncertain_

bool knowrob::Triple::isUncertain_
protected

Definition at line 331 of file Triple.h.

◆ xsdType_

std::optional< XSDType > knowrob::Triple::xsdType_
protected

Definition at line 335 of file Triple.h.


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