63 uint32_t arrIndex = 0;
64 auto counterPtr = &arrIndex;
66 bson_t *tripleDoc = bson_new();
67 BSON_APPEND_UTF8(tripleDoc,
"s", tripleData.
subject().data());
68 BSON_APPEND_UTF8(tripleDoc,
"p", tripleData.
predicate().data());
73 BSON_APPEND_UTF8(tripleDoc,
"o", objectIRI.data());
75 BSON_APPEND_ARRAY_BEGIN(tripleDoc,
"o*", &parentsArray);
76 auto parentsPtr = &parentsArray;
77 if (vocabulary->isDefinedProperty(objectIRI)) {
78 vocabulary->getDefinedProperty(objectIRI)->forallParents(
79 [parentsPtr, counterPtr](
const auto &parent) {
80 auto counterKey = std::to_string((*counterPtr)++);
81 BSON_APPEND_UTF8(parentsPtr, counterKey.c_str(), parent.iri().data());
83 }
else if (vocabulary->isDefinedClass(objectIRI)) {
85 vocabulary->getDefinedClass(objectIRI)->forallParents(
86 [parentsPtr, counterPtr](
const auto &parent) {
87 auto counterKey = std::to_string((*counterPtr)++);
88 BSON_APPEND_UTF8(parentsPtr, counterKey.c_str(), parent.iri().data());
91 BSON_APPEND_UTF8(&parentsArray,
"0", objectIRI.data());
93 bson_append_array_end(tripleDoc, &parentsArray);
95 appendXSDLiteral(tripleDoc, tripleData);
99 BSON_APPEND_UTF8(tripleDoc,
"o", tripleData.
valueAsString().data());
101 appendXSDLiteral(tripleDoc, tripleData);
104 BSON_APPEND_ARRAY_BEGIN(tripleDoc,
"p*", &parentsArray);
105 auto parentsPtr = &parentsArray;
106 vocabulary->defineProperty(tripleData.
predicate())->forallParents(
107 [parentsPtr, counterPtr](
const auto &parent) {
108 auto counterKey = std::to_string((*counterPtr)++);
109 BSON_APPEND_UTF8(parentsPtr, counterKey.c_str(), parent.iri().data());
111 bson_append_array_end(tripleDoc, &parentsArray);
114 if (tripleData.
graph()) {
115 BSON_APPEND_UTF8(tripleDoc,
"graph", tripleData.
graph().value().data());
117 BSON_APPEND_UTF8(tripleDoc,
"graph", fallbackOrigin.c_str());
121 BSON_APPEND_UTF8(tripleDoc,
"agent", tripleData.
perspective().value().data());
125 BSON_APPEND_DOUBLE(tripleDoc,
"confidence", tripleData.
confidence().value());
132 BSON_APPEND_BOOL(tripleDoc,
"uncertain",
true);
137 BSON_APPEND_BOOL(tripleDoc,
"occasional",
true);
140 if (tripleData.
begin().has_value() || tripleData.
end().has_value()) {
141 bson_t scopeDoc, timeDoc;
142 BSON_APPEND_DOCUMENT_BEGIN(tripleDoc,
"scope", &scopeDoc);
143 BSON_APPEND_DOCUMENT_BEGIN(&scopeDoc,
"time", &timeDoc);
144 if (tripleData.
begin().has_value()) BSON_APPEND_DOUBLE(&timeDoc,
"since", tripleData.
begin().value());
145 if (tripleData.
end().has_value()) BSON_APPEND_DOUBLE(&timeDoc,
"until", tripleData.
end().value());
146 bson_append_document_end(&scopeDoc, &timeDoc);
147 bson_append_document_end(tripleDoc, &scopeDoc);
virtual std::string_view valueAsString() const =0
virtual std::optional< std::string_view > perspective() const =0
virtual std::optional< std::string_view > graph() const =0
virtual std::string_view subject() const =0
virtual std::string_view predicate() const =0
bool isOccasional() const
bool isObjectBlank() const