6 #ifndef KNOWROB_FRAMED_TRIPLE_H
7 #define KNOWROB_FRAMED_TRIPLE_H
11 #include "knowrob/terms/XSDType.h"
12 #include "knowrob/Printable.h"
20 class Triple :
public Printable {
87 virtual std::string_view
subject()
const = 0;
157 virtual std::optional<std::string_view>
graph()
const = 0;
327 void write(std::ostream &os)
const override;
332 std::optional<double>
begin_;
333 std::optional<double>
end_;
338 return str.empty() || str[0] ==
'_';
346 template<
class StringType>
347 class TripleTemplate :
public Triple {
370 TripleTemplate(std::string_view subject_iri, std::string_view predicate_iri, std::string_view object_iri)
374 object_ = StringType(object_iri);
378 template<
typename ValT>
405 object_ = StringType(other.valueAsString());
409 object_ = StringType(other.valueAsString());
412 object_ = other.valueAsFloat();
415 object_ = other.valueAsDouble();
425 object_ = other.valueAsBoolean();
428 object_ = other.valueAsShort();
431 object_ = other.valueAsUnsignedLong();
434 object_ = other.valueAsUnsignedInt();
437 object_ = other.valueAsUnsignedShort();
539 std::optional<std::string_view>
graph()
const override {
541 else return std::nullopt;
547 else return std::nullopt;
564 std::optional<StringType>
graph_;
567 template<
typename ValT>
577 using TripleCopy = TripleTemplate<std::string>;
581 using TripleView = TripleTemplate<std::string_view>;
608 return ptr==other.ptr || (
ptr && other.ptr && *
ptr == *other.ptr);
612 return (
ptr && other.ptr) ? (*
ptr < *other.ptr) : (
ptr < other.ptr);
virtual std::string_view valueAsString() const =0
void setXSDValue(std::string_view v, XSDType type)
virtual short valueAsShort() const =0
virtual std::optional< std::string_view > perspective() const =0
std::string createStringValue() const
virtual void setDoubleValue(double v)=0
static bool isBlank(std::string_view str)
virtual void setFloatValue(float v)=0
virtual unsigned int valueAsUnsignedInt() const =0
virtual void setSubject(std::string_view subject)=0
virtual std::optional< std::string_view > graph() const =0
std::optional< double > end_
bool isXSDLiteral() const
virtual double valueAsDouble() const =0
virtual void setGraph(std::string_view graph)=0
virtual void setIntValue(int v)=0
std::optional< XSDType > xsdType_
virtual void setStringValue(std::string_view v)=0
virtual void setUnsignedLongValue(unsigned long v)=0
void setConfidence(double confidence)
virtual std::string_view subject() const =0
bool isSubjectIRI() const
std::optional< double > confidence_
virtual float valueAsFloat() const =0
virtual void setPerspective(std::string_view perspective)=0
bool operator==(const Triple &other) const
void setIsUncertain(bool isUncertain)
virtual void setLongValue(long v)=0
void setIsOccasional(bool isOccasional)
bool isSubjectBlank() const
std::optional< double > begin_
virtual std::string_view predicate() const =0
void setBegin(double begin)
virtual long valueAsLong() const =0
bool operator<(const Triple &other) const
virtual void setObjectIRI(std::string_view object)=0
virtual void setUnsignedIntValue(unsigned int v)=0
void write(std::ostream &os) const override
virtual unsigned short valueAsUnsignedShort() const =0
virtual void setObjectBlank(std::string_view str)=0
bool mergeFrame(const Triple &other)
virtual unsigned long valueAsUnsignedLong() const =0
virtual void setUnsignedShortValue(unsigned short v)=0
virtual void setSubjectBlank(std::string_view str)=0
virtual void setPredicate(std::string_view predicate)=0
virtual void setShortValue(short v)=0
bool isOccasional() const
bool isObjectBlank() const
virtual int valueAsInt() const =0
virtual bool valueAsBoolean() const =0
virtual void setBooleanValue(bool v)=0
virtual ~Triple()=default
float valueAsFloat() const override
void setStringValue(std::string_view v) override
void setObjectIRI(std::string_view object) override
void set(const ValT &value, XSDType type)
double valueAsDouble() const override
void setPerspective(std::string_view perspective) override
void setLongValue(long v) override
int valueAsInt() const override
std::optional< std::string_view > perspective() const override
void setBooleanValue(bool v) override
void setShortValue(short v) override
void setFloatValue(float v) override
void setUnsignedLongValue(unsigned long v) override
TripleTemplate(std::string_view subject_iri, std::string_view predicate_iri, std::string_view object_iri)
std::optional< std::string_view > graph() const override
TripleTemplate(std::string_view subject_iri, std::string_view predicate_iri)
void setUnsignedShortValue(unsigned short v) override
TripleTemplate(const Triple &other)
std::string_view predicate() const override
long valueAsLong() const override
short valueAsShort() const override
unsigned short valueAsUnsignedShort() const override
void setDoubleValue(double v) override
unsigned int valueAsUnsignedInt() const override
std::optional< StringType > graph_
void setIntValue(int v) override
unsigned long valueAsUnsignedLong() const override
void setUnsignedIntValue(unsigned int v) override
TripleTemplate(std::string_view subject, std::string_view predicate, const ValT &object, XSDType type)
void setPredicate(std::string_view predicate) override
std::variant< StringType, float, double, long, int, short, bool, unsigned long, unsigned int, unsigned short > TypedObject
std::string_view subject() const override
void setObjectBlank(std::string_view identifier) override
void setGraph(std::string_view graph) override
std::string_view valueAsString() const override
void setSubject(std::string_view subject) override
std::optional< StringType > perspective_
void setSubjectBlank(std::string_view identifier) override
bool valueAsBoolean() const override
TripleTemplate< std::string > TripleCopy
std::string_view xsdTypeToIRI(XSDType type)
XSDType
The XSDType enum Enumeration of the XSD types.
TripleTemplate< std::string_view > TripleView
bool operator==(const TriplePtr &other) const
Triple & operator*() const
TriplePtr(const TriplePtr &other)
bool operator<(const TriplePtr &other) const
Triple * operator->() const