knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
RedlandModel.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #include "knowrob/knowrob.h"
7 #include "knowrob/storage/redland/RedlandModel.h"
8 #include "knowrob/storage/StorageError.h"
9 #include "knowrob/storage/StorageManager.h"
10 #include "knowrob/semweb/OntologyParser.h"
11 #include "knowrob/semweb/xsd.h"
12 #include "knowrob/formulas/Bottom.h"
13 #include "knowrob/terms/IRIAtom.h"
14 #include "knowrob/terms/Numeric.h"
15 #include "knowrob/terms/String.h"
16 #include "knowrob/terms/Blank.h"
17 #include "knowrob/queries/AnswerYes.h"
18 
19 #define REDLAND_SETTING_HOST "host"
20 #define REDLAND_SETTING_PORT "port"
21 #define REDLAND_SETTING_USER "user"
22 #define REDLAND_SETTING_PASSWORD "password"
23 #define REDLAND_SETTING_DB "db"
24 #define REDLAND_SETTING_STORAGE "storage"
25 #define REDLAND_SETTING_ORIGIN "origin"
26 
27 using namespace knowrob;
28 
29 #define KNOWROB_RDF_NEW_URI(val) \
30  librdf_new_node_from_uri_string(world_, (const unsigned char*)(val).data())
31 #define KNOWROB_RDF_NEW_BLANK(val) \
32  librdf_new_node_from_blank_identifier(world_, (const unsigned char*)(val).data())
33 #define KNOWROB_RDF_NEW_LITERAL(val, xsdType) \
34  librdf_new_node_from_typed_literal(world_, (const unsigned char*)(val), nullptr, xsdType())
35 
40 
41 static inline const char *getStorageTypeString(RedlandStorageType storageType) {
42  switch (storageType) {
44  return "memory";
46  return "hashes";
48  return "mysql";
50  return "postgresql";
52  return "sqlite";
53  }
54  return "unknown";
55 }
56 
57 static int logRedlandMessage([[maybe_unused]] void *user_data, librdf_log_message *message) {
58  switch (message->level) {
59  case LIBRDF_LOG_DEBUG:
60  KB_INFO("[redland] {}", librdf_log_message_message(message));
61  break;
62  case LIBRDF_LOG_INFO:
63  KB_INFO("[redland] {}", librdf_log_message_message(message));
64  break;
65  case LIBRDF_LOG_WARN:
66  KB_WARN("[redland] {}", librdf_log_message_message(message));
67  break;
68  case LIBRDF_LOG_FATAL:
69  case LIBRDF_LOG_ERROR:
70  KB_ERROR("[redland] {}", librdf_log_message_message(message));
71  break;
72  default:
73  KB_WARN("[redland]: {}", librdf_log_message_message(message));
74  break;
75  }
76  return 1;
77 }
78 
81  ownedWorld_(nullptr),
82  world_(nullptr),
83  model_(nullptr),
84  storage_(nullptr),
85  storageType_(RedlandStorageType::MEMORY) {
86 }
87 
89  finalize();
90 }
91 
92 void RedlandModel::finalize() {
93  for (auto &pair: contextNodes_) {
94  librdf_free_node(pair.second);
95  }
96  contextNodes_.clear();
97 
98  for (auto &xsdURI: xsdURIs_) {
99  xsdURI.set(nullptr, "");
100  }
101 
102  if (model_) {
103  librdf_free_model(model_);
104  model_ = nullptr;
105  }
106  if (storage_) {
107  librdf_free_storage(storage_);
108  storage_ = nullptr;
109  }
110  if (ownedWorld_) {
111  librdf_free_world(ownedWorld_);
112  ownedWorld_ = nullptr;
113  world_ = nullptr;
114  }
115 }
116 
118  return model_ != nullptr;
119 }
120 
124 }
125 
126 #define REDLAND_REQUIRE_UNINITIALIZED(name, field, val) do {\
127  if(isInitialized()) { KB_WARN("attempted to change property {} after initialization.", name); } \
128  else { (field) = val; } } while(0)
129 
132 }
133 
135  REDLAND_REQUIRE_UNINITIALIZED("hash-type", hashType_, hashType);
136 }
137 
138 void RedlandModel::setHost(std::string_view host) {
139  REDLAND_REQUIRE_UNINITIALIZED("host", host_, host);
140 }
141 
142 void RedlandModel::setDatabase(std::string_view database) {
143  REDLAND_REQUIRE_UNINITIALIZED("database", database_, database);
144 }
145 
146 void RedlandModel::setUser(std::string_view user) {
147  REDLAND_REQUIRE_UNINITIALIZED("user", user_, user);
148 }
149 
150 void RedlandModel::setPassword(std::string_view password) {
151  REDLAND_REQUIRE_UNINITIALIZED("password", password_, password);
152 }
153 
154 void RedlandModel::setStorageDirectory(std::string_view dir) {
156 }
157 
158 void RedlandModel::setRaptorWorld(librdf_world *world) {
159  REDLAND_REQUIRE_UNINITIALIZED("raptor-world", world_, world);
160 }
161 
162 void RedlandModel::setHashesStorage(RedlandHashType hashType, std::string_view dir) {
164  setStorageHashType(hashType);
165  if (hashType == RedlandHashType::BDB) {
166  setStorageDirectory(dir);
167  }
168 }
169 
172 }
173 
175  if (isInitialized()) {
176  KB_WARN("RedlandModel already initialized.");
177  return false;
178  }
179 
180  // initialize the world if it hasn't been set before
181  if (!world_) {
182  ownedWorld_ = world_ = librdf_new_world();
183  if (!world_) {
184  throw StorageError("Failed to create Redland world.");
185  }
186  librdf_world_open(world_);
187  librdf_world_set_logger(world_, nullptr, logRedlandMessage);
188  }
189 
190  // initialize the storage
192  const char *storageOptions = storageOptions_.empty() ? nullptr : storageOptions_.c_str();
193  const char *storageType = getStorageTypeString(storageType_);
194  const char *storageName = origin_.has_value() ? origin_.value().c_str() : "knowrob";
195  KB_INFO("[redland] using storage of type \"{}\" with name \"{}\" and options \"{}\".",
196  storageType, storageName, storageOptions);
197  storage_ = librdf_new_storage(world_,
198  storageType,
199  storageName,
200  storageOptions);
201  if (!storage_) {
202  throw StorageError("Failed to create Redland storage for type \"{}\".", storageType);
203  }
204 
205  // initialize the model
206  static const char *modelOptions = nullptr;
207  model_ = librdf_new_model(world_, storage_, modelOptions);
208  if (!model_) {
209  librdf_free_storage(storage_);
210  storage_ = nullptr;
211  throw StorageError("Failed to create Redland model for storage type \"{}\".", storageType);
212  }
213 
214  // initialize URIs
215  for (int i = 0; i != static_cast<int>(XSDType::LAST); i++) {
217  }
218 
219  return true;
220 }
221 
223  if (isInitialized()) {
224  KB_WARN("RedlandModel already initialized.");
225  return false;
226  }
227  auto o_host = ptree->get_optional<std::string>(REDLAND_SETTING_HOST);
228  auto o_port = ptree->get_optional<std::string>(REDLAND_SETTING_PORT);
229  auto o_user = ptree->get_optional<std::string>(REDLAND_SETTING_USER);
230  auto o_password = ptree->get_optional<std::string>(REDLAND_SETTING_PASSWORD);
231  auto o_db = ptree->get_optional<std::string>(REDLAND_SETTING_DB);
232  auto o_origin = ptree->get_optional<std::string>(REDLAND_SETTING_ORIGIN);
233  auto o_storage = ptree->get_optional<std::string>(REDLAND_SETTING_STORAGE);
234 
235  if (o_host) host_ = o_host.value();
236  if (o_port) port_ = o_port.value();
237  if (o_user) user_ = o_user.value();
238  if (o_password) password_ = o_password.value();
239  if (o_db) database_ = o_db.value();
240  if (o_origin) origin_ = o_origin.value();
241  if (o_storage) {
243  if (o_storage.value() == "hashes") {
245  } else if (o_storage.value() == "mysql") {
247  } else if (o_storage.value() == "postgresql") {
249  } else if (o_storage.value() == "sqlite") {
251  } else {
252  KB_WARN("Unknown storage type \"{}\", falling back to memory.", o_storage.value());
253  }
254  }
255  // finally call initializeBackend()
256  return initializeBackend();
257 }
258 
260  using OptPair_o = std::pair<std::string, std::optional<std::string>>;
261  std::vector<std::pair<std::string, std::string>> opts;
262  for (auto &option: {
263  OptPair_o{"host", host_},
264  OptPair_o{"port", port_},
265  OptPair_o{"database", database_},
266  OptPair_o{"user", user_},
267  OptPair_o{"password", password_},
268  OptPair_o{"dir", storageDir_}}) {
269  if (option.second.has_value()) {
270  opts.emplace_back(option.first, option.second.value());
271  }
272  }
273  // "hash-type" is required by "hashes" storage type
274  if (hashType_.has_value()) {
275  switch (hashType_.value()) {
277  opts.emplace_back("hash-type", "memory");
278  break;
280  opts.emplace_back("hash-type", "bdb");
281  break;
282  }
283  }
284  // context support currently is required which limits the storage types we can use.
285  // but "memory" and "hashes" can do it.
286  opts.emplace_back("contexts", "yes");
287  std::stringstream ss;
288  for (std::size_t i = 0; i < opts.size(); i++) {
289  ss << opts[i].first << "='" << opts[i].second << '\'';
290  if (i < opts.size() - 1) {
291  ss << ",";
292  }
293  }
294  return ss.str();
295 }
296 
297 bool RedlandModel::load(const URI &uri, semweb::TripleFormat tripleFormat) {
298  static const char *modelName = nullptr;
299  auto rdf_uri = librdf_new_uri(
300  world_,
301  (const unsigned char *) uri().c_str());
302  int returnCode = librdf_model_load(
303  model_,
304  rdf_uri,
305  modelName,
306  tripleFormatMimeType(tripleFormat).data(),
307  nullptr);
308  librdf_free_uri(rdf_uri);
309  return returnCode == 0;
310 }
311 
312 static inline TermPtr termFromNode(librdf_node *node) {
313  if (!node) return nullptr;
314 
315  switch (librdf_node_get_type(node)) {
316  case LIBRDF_NODE_TYPE_RESOURCE: {
317  auto uri = librdf_node_get_uri(node);
318  if (uri) {
319  return IRIAtom::Tabled((const char *) librdf_uri_as_string(uri));
320  }
321  break;
322  }
323  case LIBRDF_NODE_TYPE_BLANK:
324  return Blank::Tabled((const char *) librdf_node_get_blank_identifier(node));
325  case LIBRDF_NODE_TYPE_LITERAL: {
326  auto literal_value = (const char *) librdf_node_get_literal_value(node);
327  auto datatype_uri = librdf_node_get_literal_value_datatype_uri(node);
328  TermPtr knowrobTerm;
329  if (datatype_uri) {
330  auto u_uri_str = librdf_uri_to_string(datatype_uri);
331  std::string_view uri_str((const char *) u_uri_str);
332  if (xsd::isDoubleType(uri_str)) {
333  knowrobTerm = std::make_shared<Double>(std::stod(literal_value));
334  } else if (xsd::isIntegerType(uri_str)) {
335  knowrobTerm = std::make_shared<Integer>(std::stoll(literal_value));
336  } else if (xsd::isBooleanType(uri_str)) {
337  knowrobTerm = std::make_shared<Integer>(std::string_view(literal_value) == "true");
338  }
339  free(u_uri_str);
340  }
341  if (!knowrobTerm) {
342  knowrobTerm = std::make_shared<String>(literal_value);
343  }
344  return knowrobTerm;
345  }
346  default:
347  break;
348  }
349  return nullptr;
350 }
351 
352 bool RedlandModel::insertOne(const Triple &knowrobTriple) {
353  auto raptorTriple = librdf_new_statement(world_);
354  // map the knowrob triple into a raptor triple
355  knowrobToRaptor(knowrobTriple, raptorTriple);
356  // add the triple together with a context node holding the origin literal
357  librdf_model_context_add_statement(model_, getContextNode(knowrobTriple), raptorTriple);
358  librdf_free_statement(raptorTriple);
359  return true;
360 }
361 
363  // insert all triples into an in-memory model.
364  // only after all triples are inserted, the model is transformed and then pushed to the next stage.
365  for (auto &knowrobTriple: *triples) {
366  auto raptorTriple = librdf_new_statement(world_);
367  // map the knowrob triple into a raptor triple
368  knowrobToRaptor(*knowrobTriple, raptorTriple);
369  librdf_model_context_add_statement(model_, getContextNode(*knowrobTriple), raptorTriple);
370  librdf_free_statement(raptorTriple);
371  }
372  return true;
373 }
374 
375 bool RedlandModel::removeOne(const Triple &knowrobTriple) {
376  auto raptorTriple = librdf_new_statement(world_);
377  // map the knowrob triple into a raptor triple
378  knowrobToRaptor(knowrobTriple, raptorTriple);
379  auto ret = librdf_model_context_remove_statement(model_, getContextNode(knowrobTriple), raptorTriple);
380  librdf_free_statement(raptorTriple);
381  return ret == 0;
382 }
383 
385  bool allRemoved = true;
386  for (auto &knowrobTriple: *triples) {
387  // map the knowrob triple into a raptor triple
388  auto raptorTriple = librdf_new_statement(world_);
389  knowrobToRaptor(*knowrobTriple, raptorTriple);
390  auto ret = librdf_model_context_remove_statement(model_, getContextNode(*knowrobTriple), raptorTriple);
391  if (ret != 0) {
392  allRemoved = false;
393  }
394  librdf_free_statement(raptorTriple);
395  }
396  return allRemoved;
397 }
398 
399 bool RedlandModel::removeAllWithOrigin(std::string_view origin) {
400  auto stream = librdf_model_find_statements_in_context(
401  model_, nullptr, getContextNode(origin));
402  if (!stream) return false;
403  // collect matching statements
404  std::vector<librdf_statement *> toRemove;
405  while (!librdf_stream_end(stream)) {
406  auto next = librdf_stream_get_object(stream);
407  toRemove.push_back(librdf_new_statement_from_statement(next));
408  librdf_stream_next(stream);
409  }
410  librdf_free_stream(stream);
411  // finally remove matching statements
412  for (auto statement: toRemove) {
413  librdf_model_remove_statement(model_, statement);
414  librdf_free_statement(statement);
415  }
416  return true;
417 }
418 
419 static void batch_(librdf_model *model, librdf_node *context, std::shared_ptr<RaptorContainer> &triples,
420  const TripleHandler &callback) {
421  auto stream = librdf_model_find_statements_in_context(
422  model, nullptr, context);
423 
424  while (!librdf_stream_end(stream)) {
425  auto statement = librdf_stream_get_object(stream);
426  triples->add(statement->subject, statement->predicate, statement->object, context);
427  if (triples->size() >= GlobalSettings::batchSize()) {
428  triples->shrink();
429  callback(triples);
430  triples->reset();
431  }
432  librdf_stream_next(stream);
433  }
434  librdf_free_stream(stream);
435 }
436 
437 void RedlandModel::batch(const TripleHandler &callback) const {
438  auto triples = std::make_shared<RaptorContainer>(GlobalSettings::batchSize());
439  auto contexts = librdf_model_get_contexts(model_);
440  while (!librdf_iterator_end(contexts)) {
441  batch_(model_, (librdf_node *) librdf_iterator_get_object(contexts), triples, callback);
442  librdf_iterator_next(contexts);
443  }
444  if (triples->size() > 0) {
445  triples->shrink();
446  callback(triples);
447  }
448  librdf_free_iterator(contexts);
449 }
450 
451 void RedlandModel::batchOrigin(std::string_view origin, const TripleHandler &callback) {
452  auto triples = std::make_shared<RaptorContainer>(GlobalSettings::batchSize());
453  batch_(model_, getContextNode(origin), triples, callback);
454  if (triples->size() > 0) {
455  triples->shrink();
456  callback(triples);
457  }
458 }
459 
460 bool RedlandModel::contains(const Triple &triple) {
461  auto raptorTriple = librdf_new_statement(world_);
462  knowrobToRaptor(triple, raptorTriple);
463  auto result = librdf_model_contains_statement(model_, raptorTriple);
464  librdf_free_statement(raptorTriple);
465  return result;
466 }
467 
468 void RedlandModel::match(const TriplePattern &query, const TripleVisitor &visitor) {
469  auto triples = std::make_shared<RaptorContainer>(1);
470  auto rdf_query = librdf_new_statement(world_);
471  knowrobToRaptor(query, rdf_query);
472 
473  auto stream = librdf_model_find_statements(model_, rdf_query);
474  while (!librdf_stream_end(stream)) {
475  auto rdf_statement = librdf_stream_get_object(stream);
476  triples->add(rdf_statement->subject, rdf_statement->predicate, rdf_statement->object);
477  auto &triple = *triples->begin();
478 
479  if (query.objectOperator() != FilterType::EQ) {
480  if (query.filter(*triple)) visitor(triple);
481  } else {
482  visitor(triple);
483  }
484  triples->reset();
485  librdf_stream_next(stream);
486  }
487  librdf_free_stream(stream);
488 }
489 
490 bool RedlandModel::sparql(std::string_view queryString, const BindingsHandler &callback) const {
491  auto queryObj = librdf_new_query(
492  world_,
493  QUERY_LANGUAGE_SPARQL.data(),
494  nullptr,
495  (unsigned char *) queryString.data(),
496  nullptr);
497  if (!queryObj) {
498  KB_WARN("Failed to create query `{}` for model \"{}\".", queryString, storageName_);
499  return false;
500  }
501  auto results = librdf_query_execute(queryObj, model_);
502  if (!results) {
503  KB_WARN("Failed to execute query `{}` for model \"{}\".", queryString, storageName_);
504  librdf_free_query(queryObj);
505  return false;
506  }
507  while (!librdf_query_results_finished(results)) {
508  auto bindings = std::make_shared<Bindings>();
509 
510  // read bindings
511  int bindings_count = librdf_query_results_get_bindings_count(results);
512  for (int i = 0; i < bindings_count; ++i) {
513  auto name = std::string_view(librdf_query_results_get_binding_name(results, i));
514  if (name.empty() || name[0] == '_') {
515  // skip variables that start with '_'.
516  // afaik, there is no way to prevent these from being returned when "*" is
517  // used in select pattern.
518  continue;
519  }
520 
521  auto node = librdf_query_results_get_binding_value(results, i);
522  if (!node) {
523  // this indicates that a variable appears in select pattern, but it was not grounded
524  // in the query. this is not an error, but rather means the grounding was OPTIONAL.
525  // we can just skip this variable.
526  continue;
527  }
528 
529  auto knowrobTerm = termFromNode(node);
530  if (knowrobTerm) {
531  bindings->set(std::make_shared<Variable>(name), knowrobTerm);
532  } else {
533  KB_WARN("Failed to process binding for variable \"{}\".", name);
534  }
535  librdf_free_node(node);
536  }
537  callback(bindings);
538  librdf_query_results_next(results);
539  }
540  librdf_free_query_results(results);
541  librdf_free_query(queryObj);
542  return true;
543 }
544 
545 librdf_node *RedlandModel::getContextNode(std::string_view origin) {
546  auto it = contextNodes_.find(origin);
547  if (it != contextNodes_.end()) {
548  return it->second;
549  }
550  auto contextNode = librdf_new_node_from_uri_string(
551  world_,
552  (const unsigned char *) origin.data());
553  contextNodes_[std::string(origin)] = contextNode;
554  return contextNode;
555 }
556 
557 librdf_node *RedlandModel::getContextNode(const Triple &triple) {
558  return getContextNode(
559  triple.graph() ? triple.graph().value() :
560  origin_.has_value() ? origin_.value() :
562 }
563 
565  return xsdURIs_[static_cast<int>(xsdType)];
566 }
567 
569  if (!term || !term->isAtomic()) {
570  return nullptr;
571  }
572  auto atomic = std::static_pointer_cast<Atomic>(term);
573  if (term->isIRI()) {
574  return KNOWROB_RDF_NEW_URI(atomic->stringForm());
575  } else if (term->isBlank()) {
576  return KNOWROB_RDF_NEW_BLANK(atomic->stringForm());
577  } else if (term->isString()) {
578  return KNOWROB_RDF_NEW_LITERAL(atomic->stringForm().data(), xsdURI(XSDType::STRING));
579  } else if (term->isNumeric()) {
580  auto numeric = std::static_pointer_cast<Numeric>(atomic);
581  return KNOWROB_RDF_NEW_LITERAL(atomic->stringForm().data(), xsdURI(numeric->xsdType()));
582  }
583  KB_WARN("Failed to convert term {} to raptor term.", *term);
584  return nullptr;
585 }
586 
587 void RedlandModel::knowrobToRaptor(const TriplePattern &pat, raptor_statement *raptorTriple) {
588  raptor_term *subject, *predicate, *object;
589  if (pat.subjectTerm()) {
590  subject = knowrobToRaptor(pat.subjectTerm());
591  librdf_statement_set_subject(raptorTriple, subject);
592  }
593  if (pat.propertyTerm()) {
595  librdf_statement_set_predicate(raptorTriple, predicate);
596  }
597  if (pat.objectTerm() && pat.objectOperator() == FilterType::EQ) {
598  object = knowrobToRaptor(pat.objectTerm());
599  librdf_statement_set_object(raptorTriple, object);
600  }
601 }
602 
603 void RedlandModel::knowrobToRaptor(const Triple &triple, raptor_statement *raptorTriple) {
604  raptor_term *subject, *predicate, *object;
606  if (triple.isSubjectBlank()) {
607  subject = KNOWROB_RDF_NEW_BLANK(triple.subject());
608  } else {
609  subject = KNOWROB_RDF_NEW_URI(triple.subject());
610  }
611  if (triple.isObjectBlank()) {
612  object = KNOWROB_RDF_NEW_BLANK(triple.valueAsString());
613  } else if (triple.isObjectIRI()) {
614  object = KNOWROB_RDF_NEW_URI(triple.valueAsString());
615  } else if (triple.xsdType()) {
616  switch (triple.xsdType().value()) {
617  case XSDType::STRING:
618  object = KNOWROB_RDF_NEW_LITERAL(triple.valueAsString().data(), xsdURI(triple.xsdType().value()));
619  break;
620  default:
621  object = KNOWROB_RDF_NEW_LITERAL(triple.createStringValue().c_str(), xsdURI(triple.xsdType().value()));
622  break;
623  }
624  } else {
626  }
627  librdf_statement_set_subject(raptorTriple, subject);
628  librdf_statement_set_predicate(raptorTriple, predicate);
629  librdf_statement_set_object(raptorTriple, object);
630 }
#define REDLAND_SETTING_DB
#define KNOWROB_RDF_NEW_BLANK(val)
#define REDLAND_SETTING_USER
#define REDLAND_SETTING_PORT
#define REDLAND_SETTING_ORIGIN
#define REDLAND_REQUIRE_UNINITIALIZED(name, field, val)
#define REDLAND_SETTING_PASSWORD
#define KNOWROB_RDF_NEW_LITERAL(val, xsdType)
#define REDLAND_SETTING_HOST
#define KNOWROB_RDF_NEW_URI(val)
#define REDLAND_SETTING_STORAGE
#define KB_INFO
Definition: Logger.h:26
#define KB_ERROR
Definition: Logger.h:28
#define KB_WARN
Definition: Logger.h:27
#define KNOWROB_BUILTIN_STORAGE(Name, Type)
static std::shared_ptr< Blank > Tabled(std::string_view stringForm)
Definition: Blank.cpp:12
static uint32_t batchSize()
Definition: knowrob.h:68
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
Definition: IRIAtom.cpp:25
static constexpr std::string_view ORIGIN_USER
auto storageType() const
Definition: RedlandModel.h:126
void setHashesStorage(RedlandHashType hashType, std::string_view dir=".")
bool sparql(std::string_view queryString, const BindingsHandler &callback) const override
RedlandURI & xsdURI(XSDType xsdType)
bool insertAll(const TripleContainerPtr &triples) override
std::optional< std::string > port_
Definition: RedlandModel.h:202
librdf_world * world_
Definition: RedlandModel.h:186
librdf_world * ownedWorld_
Definition: RedlandModel.h:185
bool contains(const Triple &triple) override
void setDatabase(std::string_view database)
bool insertOne(const Triple &triple) override
librdf_model * model_
Definition: RedlandModel.h:187
std::map< std::string, librdf_node *, std::less<> > contextNodes_
Definition: RedlandModel.h:196
std::optional< std::string > storageDir_
Definition: RedlandModel.h:206
librdf_storage * storage_
Definition: RedlandModel.h:188
RedlandURI xsdURIs_[static_cast< int >(XSDType::LAST)]
Definition: RedlandModel.h:192
bool isInitialized() const
bool isPersistent() const override
void setPassword(std::string_view password)
std::optional< std::string > host_
Definition: RedlandModel.h:201
void batchOrigin(std::string_view origin, const TripleHandler &callback) override
void setUser(std::string_view user)
std::optional< std::string > password_
Definition: RedlandModel.h:205
void batch(const TripleHandler &callback) const override
std::string getStorageOptions() const
std::optional< std::string > origin_
Definition: RedlandModel.h:200
void setRaptorWorld(librdf_world *world)
bool removeAllWithOrigin(std::string_view origin) override
void match(const TriplePattern &query, const TripleVisitor &visitor) override
bool load(const URI &uri, semweb::TripleFormat tripleFormat)
void setStorageHashType(RedlandHashType hashType)
std::optional< std::string > database_
Definition: RedlandModel.h:203
void setHost(std::string_view host)
std::string storageOptions_
Definition: RedlandModel.h:209
RedlandStorageType storageType_
Definition: RedlandModel.h:208
void knowrobToRaptor(const Triple &triple, raptor_statement *raptorTriple)
bool removeAll(const TripleContainerPtr &triples) override
std::optional< std::string > user_
Definition: RedlandModel.h:204
static constexpr std::string_view QUERY_LANGUAGE_SPARQL
Definition: RedlandModel.h:54
librdf_node * getContextNode(std::string_view origin)
std::optional< RedlandHashType > hashType_
Definition: RedlandModel.h:207
void setStorageType(RedlandStorageType storageType)
bool removeOne(const Triple &triple) override
void setStorageDirectory(std::string_view dir=".")
std::string storageName_
Definition: RedlandModel.h:198
void set(librdf_world *world, std::string_view uri)
Definition: RedlandURI.h:34
bool query(const SPARQLQuery &query, const BindingsHandler &callback) const
virtual std::string_view valueAsString() const =0
auto xsdType() const
Definition: Triple.h:64
virtual std::optional< std::string_view > graph() const =0
virtual std::string_view subject() const =0
bool isSubjectBlank() const
Definition: Triple.h:44
virtual std::string_view predicate() const =0
std::string createStringValue() const
Definition: Triple.cpp:71
bool isObjectIRI() const
Definition: Triple.h:54
bool isObjectBlank() const
Definition: Triple.h:49
auto objectOperator() const
auto & propertyTerm() const
Definition: TriplePattern.h:92
auto & subjectTerm() const
Definition: TriplePattern.h:81
auto & objectTerm() const
Definition: TriplePattern.h:97
PredicateRule & predicate()
Definition: formula.cpp:221
TermRule & option()
Definition: terms.cpp:110
TermRule & string()
Definition: terms.cpp:63
TermRule & atomic()
Definition: terms.cpp:79
TermRule & term()
Definition: terms.cpp:136
std::string_view tripleFormatMimeType(TripleFormat format)
bool isDoubleType(std::string_view iri)
Definition: xsd.cpp:89
bool isBooleanType(std::string_view iri)
Definition: xsd.cpp:94
bool isIntegerType(std::string_view iri)
Definition: xsd.cpp:84
std::function< void(const TriplePtr &)> TripleVisitor
std::shared_ptr< TripleContainer > TripleContainerPtr
std::string_view xsdTypeToIRI(XSDType type)
Definition: XSDAtomic.cpp:70
RedlandStorageType
Definition: RedlandModel.h:23
std::shared_ptr< Term > TermPtr
Definition: Term.h:117
std::function< void(const BindingsPtr &)> BindingsHandler
Definition: Bindings.h:152
std::function< void(const TripleContainerPtr &)> TripleHandler
XSDType
The XSDType enum Enumeration of the XSD types.
Definition: XSDType.h:16