knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
SPARQLService.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/semweb/SPARQLService.h"
7 #include "knowrob/storage/StorageError.h"
8 
9 using namespace knowrob;
10 
12  : SPARQLService::SPARQLService(uri, semweb::tripleFormatToString(format)) {
13 }
14 
15 SPARQLService::SPARQLService(const URI &uri, std::string_view format)
16  : OntologySource(uri, format) {
17  // create a Redland model for the SPARQL endpoint
18  // Note that the model has interfaces for insert and remove triples, these won't
19  // interact with the SPARQL endpoint, but with the local storage of the model.
22  if (!model_.initializeBackend()) {
23  throw StorageError("Failed to initialize Redland backend for SPARQL endpoint at \"{}\".", uri());
24  }
25  // set up the model to interface with the SPARQL endpoint
27  throw StorageError("Failed to load URI of SPARQL endpoint at \"{}\".", uri());
28  }
29 }
30 
31 bool SPARQLService::load(const TripleHandler &callback) {
32  // iterate over all triples in the SPARQL endpoint
33  model_.batch(callback);
34  return true;
35 }
const auto & format() const
Definition: DataSource.h:49
const auto & uri() const
Definition: DataSource.h:39
void setOrigin(std::string_view origin)
Definition: RedlandModel.h:121
void batch(const TripleHandler &callback) const override
bool load(const URI &uri, semweb::TripleFormat tripleFormat)
void setStorageType(RedlandStorageType storageType)
bool load(const TripleHandler &callback) override
SPARQLService(const URI &uri, semweb::TripleFormat format)
std::string_view tripleFormatToString(TripleFormat format)
TripleFormat tripleFormatFromString(std::string_view format)
std::function< void(const TripleContainerPtr &)> TripleHandler