1 #ifndef HAVE_RDF_MODEL_H
2 #define HAVE_RDF_MODEL_H 1
7 #include <boost/multiprecision/cpp_int.hpp>
8 #include <boost/multiprecision/cpp_dec_float.hpp>
10 using boost::multiprecision::cpp_int;
11 using boost::multiprecision::cpp_dec_float_50;
22 enum ValueTypes { TYPE_URI, TYPE_BNODE, TYPE_PLAIN_LITERAL, TYPE_LANGUAGE_LITERAL, TYPE_TYPED_LITERAL };
29 friend bool operator==(
const Value& l,
const Value& r);
30 friend bool operator!=(
const Value& l,
const Value& r);
31 friend std::ostream& operator<<(std::ostream&,
Value&);
32 friend std::ostream& operator<<(std::ostream&,
Value*);
40 virtual std::ostream& print(std::ostream& os)
const = 0;
54 virtual const ValueTypes
getType()
const = 0;
80 std::size_t split()
const;
85 bool equals(
const Value& other)
const;
87 std::ostream& print(std::ostream& os)
const { os <<
"URI("<<uri<<
")";
return os; } ;
91 URI(
const std::string& uri) : uri(uri) {};
92 URI(
const char* uri) : uri(uri) {};
93 URI(
const URI& uri) : uri(uri.uri) {};
112 inline const ValueTypes
getType()
const {
return TYPE_URI; };
115 inline bool operator==(
const std::string& s)
const {
return uri == s; };
116 inline bool operator==(
const char* s)
const {
return uri == s; };
117 inline bool operator!=(
const std::string& s)
const {
return uri != s; };
118 inline bool operator!=(
const char* s)
const {
return uri != s; };
133 bool equals(
const Value& other)
const;
135 std::ostream& print(std::ostream& os)
const { os <<
"BNode("<<
id<<
")";
return os; } ;
145 BNode(
const std::string&
id) : id(id) {};
146 BNode(
const char*
id) : id(id) {};
153 inline const std::string&
getID()
const {
return id; };
161 inline const ValueTypes
getType()
const {
return TYPE_BNODE; };
163 inline bool operator==(
const std::string& s)
const {
return id == s; };
164 inline bool operator==(
const char* s)
const {
return id == s; };
165 inline bool operator!=(
const std::string& s)
const {
return id != s; };
166 inline bool operator!=(
const char* s)
const {
return id != s; };
181 virtual std::ostream& print(std::ostream& os)
const { os <<
"Literal("<<label<<
")";
return os; };
184 Literal(
const std::string& label) : label(label) {};
185 Literal(
const char* label) : label(label) {};
186 Literal(int8_t i) : label(std::to_string((
int)i)) {};
187 Literal(int16_t i) : label(std::to_string((
int)i)) {};
188 Literal(int32_t i) : label(std::to_string((
long int)i)) {};
189 Literal(int64_t i) : label(std::to_string((
long long)i)) {};
190 Literal(
double d) : label(std::to_string(d)) {};
191 Literal(
float d) : label(std::to_string(d)) {};
192 Literal(
bool b) : label(b ?
"true" :
"false") {};
245 inline const std::string&
getLabel()
const {
return label; };
253 inline const ValueTypes
getType()
const {
return TYPE_PLAIN_LITERAL; };
257 inline bool operator==(
const std::string& s)
const {
return label == s; };
259 inline bool operator!=(
const std::string& s)
const {
return label != s; };
264 inline operator int()
const {
return intValue(); }
265 inline operator long int()
const {
return longValue(); }
266 inline operator long long int()
const {
return longValue(); }
267 inline operator float()
const {
return floatValue(); }
268 inline operator double()
const {
return doubleValue(); }
269 inline operator const char*()
const {
return label.c_str(); }
283 bool equals(
const Value& other)
const;
285 std::ostream& print(std::ostream& os)
const { os <<
"LanguageLiteral("<<label<<
","<<lang<<
")";
return os; } ;
288 LanguageLiteral(
const std::string& label,
const std::string& language) :
Literal(label), lang(language) {};
296 inline const ValueTypes
getType()
const {
return TYPE_LANGUAGE_LITERAL; };
311 bool equals(
const Value& other)
const;
313 std::ostream& print(std::ostream& os)
const { os <<
"DatatypeLiteral("<<label<<
","<<datatype.
stringValue()<<
")";
return os; } ;
318 DatatypeLiteral(int8_t i) :
Literal(std::to_string((
int)i)), datatype(
"http://www.w3.org/2001/XMLSchema#byte") {};
319 DatatypeLiteral(int16_t i) :
Literal(std::to_string((
int)i)), datatype(
"http://www.w3.org/2001/XMLSchema#short") {};
320 DatatypeLiteral(int32_t i) :
Literal(std::to_string((
long int)i)), datatype(
"http://www.w3.org/2001/XMLSchema#int") {};
321 DatatypeLiteral(int64_t i) :
Literal(std::to_string((
long long)i)), datatype(
"http://www.w3.org/2001/XMLSchema#long") {};
322 DatatypeLiteral(
double d) :
Literal(std::to_string(d)), datatype(
"http://www.w3.org/2001/XMLSchema#double") {};
323 DatatypeLiteral(
float d) :
Literal(std::to_string(d)), datatype(
"http://www.w3.org/2001/XMLSchema#float") {};
324 DatatypeLiteral(
bool b) :
Literal(b ?
"true" :
"false"), datatype(
"http://www.w3.org/2001/XMLSchema#boolean") {};
332 inline const ValueTypes
getType()
const {
return TYPE_TYPED_LITERAL; };
369 inline bool operator==(
const std::string& l,
const URI& r) {
373 inline bool operator!=(
const std::string& l,
const URI& r) {
377 inline bool operator==(
const std::string& l,
const BNode& r) {
381 inline bool operator!=(
const std::string& l,
const BNode& r) {
385 inline bool operator==(
const std::string& l,
const Literal& r) {
389 inline bool operator!=(
const std::string& l,
const Literal& r) {
415 inline bool operator==(
const Value& l,
const Value& r) {
419 inline bool operator!=(
const Value& l,
const Value& r) {
424 inline std::ostream& operator<<(std::ostream& os, Value& v) {
428 inline std::ostream& operator<<(std::ostream& os, Value* v) {
const ValueTypes getType() const
Return type information (to avoid dynamic casts if possible)
Definition: rdf_model.hpp:332
BNode(const std::string &id)
Create a new BNode with the given ID.
Definition: rdf_model.hpp:145
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Definition: http_client.cpp:23
The supertype of all RDF resources (URIs and blank nodes).
Definition: rdf_model.hpp:60
cpp_int integerValue() const
Returns the integer value of this literal.
Definition: rdf_model.cpp:108
float floatValue() const
Returns the float value of this literal.
Definition: rdf_model.cpp:101
Representation of an RDF triple, consisting of subject, predicate and object.
Definition: rdf_model.hpp:339
The supertype of all RDF model objects (URIs, blank nodes and literals).
Definition: rdf_model.hpp:27
virtual bool equals(const Value &other) const
Internal polymorphic implementation of equals.
Definition: rdf_model.cpp:64
virtual const std::string & stringValue() const =0
Returns the String-value of a Value object.
const URI & getPredicate() const
Gets the predicate of this statement.
Definition: rdf_model.hpp:357
A literal with a language tag.
Definition: rdf_model.hpp:276
int32_t intValue() const
Returns the 32 bit int value of this literal.
Definition: rdf_model.cpp:115
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
RDF blank node, represented with an internal string identifier.
Definition: rdf_model.hpp:125
const std::string & getLabel() const
Gets the label of this literal.
Definition: rdf_model.hpp:245
const URI & getDatatype() const
Gets the datatype for this literal.
Definition: rdf_model.hpp:329
virtual bool equals(const Value &other) const =0
Internal polymorphic implementation of equals and print.
const std::string & stringValue() const
Returns the String-value of a Value object.
Definition: rdf_model.hpp:250
cpp_dec_float_50 decimalValue() const
Returns the decimal value of this literal.
Definition: rdf_model.cpp:87
bool booleanValue() const
Returns the boolean value of this literal.
Definition: rdf_model.cpp:72
int64_t longValue() const
Returns the 64 bit long value of this literal.
Definition: rdf_model.cpp:122
const std::string & getID() const
retrieves this blank node's identifier.
Definition: rdf_model.hpp:153
const Resource & getSubject() const
Gets the subject of this statement.
Definition: rdf_model.hpp:352
const Value & getObject() const
Gets the object of this statement.
Definition: rdf_model.hpp:363
const ValueTypes getType() const
Return type information (to avoid dynamic casts if possible)
Definition: rdf_model.hpp:253
const std::string & getLanguage() const
Gets the language tag for this literal, normalized to lower case.
Definition: rdf_model.hpp:294
An RDF literal consisting of a label (the value) and optionally a language tag or a datatype (but not...
Definition: rdf_model.hpp:172
A URI.
Definition: rdf_model.hpp:74
const ValueTypes getType() const
Return type information (to avoid dynamic casts if possible)
Definition: rdf_model.hpp:161
const ValueTypes getType() const
Return type information (to avoid dynamic casts if possible)
Definition: rdf_model.hpp:112
A literal with a datatype.
Definition: rdf_model.hpp:304
const ValueTypes getType() const
Return type information (to avoid dynamic casts if possible)
Definition: rdf_model.hpp:296
const std::string & stringValue() const
Returns the String-value of a Value object.
Definition: rdf_model.hpp:109
BNode()
Create a new BNode with a random ID.
Definition: rdf_model.hpp:140
std::string getNamespace() const
Gets the namespace of this URI.
Definition: rdf_model.hpp:103
virtual const ValueTypes getType() const =0
Return type information (to avoid dynamic casts if possible)
int8_t byteValue() const
Returns the byte value of this literal.
Definition: rdf_model.cpp:79
int16_t shortValue() const
Returns the 16 bit short value of this literal.
Definition: rdf_model.cpp:129
std::string getLocalName() const
Gets the local name of this URI.
Definition: rdf_model.hpp:98
double doubleValue() const
Returns the double value of this literal.
Definition: rdf_model.cpp:94
const std::string & stringValue() const
Returns the String-value of a Value object.
Definition: rdf_model.hpp:159