6 #include "knowrob/storage/StorageManager.h"
7 #include "knowrob/integration/prolog/PrologBackend.h"
8 #include "knowrob/integration/prolog/PrologEngine.h"
9 #include "knowrob/integration/prolog/PrologTerm.h"
10 #include "knowrob/knowrob.h"
20 static const auto rdf_quad =
"rdf";
21 static const auto rdf_assert =
"rdf_assert";
22 static const auto rdf_retractall =
"rdf_retractall";
23 static const auto rdf_transaction =
"rdf_transaction";
36 PrologTerm(
"/",
"rdf", std::make_shared<Integer>(4)),
37 PrologTerm(
"/",
"rdf_assert", std::make_shared<Integer>(4)),
38 PrologTerm(
"/",
"rdf_retractall", std::make_shared<Integer>(4)),
39 PrologTerm(
"/",
"rdf_transaction", std::make_shared<Integer>(1)),
40 PrologTerm(
"/",
"rdf_has", std::make_shared<Integer>(3))
46 PrologTerm(
"/",
"sw_literal_compare", std::make_shared<Integer>(3)),
47 PrologTerm(
"/",
"sw_literal_max", std::make_shared<Integer>(3)),
48 PrologTerm(
"/",
"sw_literal_min", std::make_shared<Integer>(3)),
49 PrologTerm(
"/",
"sw_resource_frequency", std::make_shared<Integer>(2)),
50 PrologTerm(
"/",
"sw_class_frequency", std::make_shared<Integer>(2)),
51 PrologTerm(
"/",
"sw_property_frequency", std::make_shared<Integer>(2))
93 for (
const auto &triple: *triples) {
94 transactionGoal = (transactionGoal &
PrologTerm(*triple, rdf_functor));
96 return PrologTerm(rdf_transaction, transactionGoal);
111 static auto var_s = std::make_shared<Variable>(
"s");
112 static auto var_p = std::make_shared<Variable>(
"p");
113 static auto var_o = std::make_shared<Variable>(
"o");
123 auto val_s = bindings->getAtomic(var_s->name());
124 auto val_p = bindings->getAtomic(var_p->name());
125 auto val_o = bindings->getAtomic(var_o->name());
126 if(!val_s || !val_p || !val_o) {
127 KB_WARN(
"Failed to retrieve triple from Prolog: missing grounding.");
132 triple_ptr.
ptr =
new TripleCopy(val_s->stringForm(), val_p->stringForm());
133 if (val_o->isNumeric() || val_o->isString()) {
134 auto xsd_o = std::static_pointer_cast<XSDAtomic>(val_o);
135 triple_ptr.ptr->setXSDValue(xsd_o->stringForm(), xsd_o->xsdType());
136 }
else if (val_o->isIRI()) {
137 triple_ptr.ptr->setObjectIRI(val_o->stringForm());
138 }
else if (val_o->isBlank()) {
139 triple_ptr.ptr->setObjectBlank(val_o->stringForm());
142 triple_ptr.ptr->setGraph(origin.grounded()->stringForm());
144 auto val_g = bindings->getAtomic(origin.variable()->name());
146 triple_ptr.ptr->setGraph(val_g->stringForm());
149 triple_ptr.owned =
true;
151 triples->add(triple_ptr);
159 if (triples->size() > 0) {
166 batch_(callback, origin_g);
180 static const auto freq_f =
"sw_resource_frequency";
181 static auto var_res = std::make_shared<Variable>(
"resource");
182 static auto var_freq = std::make_shared<Variable>(
"frequency");
185 auto val_res = bindings->getAtomic(var_res->name());
186 auto val_freq = bindings->getAtomic(var_freq->name());
187 if (val_res && val_freq && val_freq->isNumeric()) {
188 callback(val_res->stringForm(), std::static_pointer_cast<Numeric>(val_freq)->asInteger());
#define PROLOG_ENGINE_EVAL(term)
#define PROLOG_ENGINE_QUERY(term, callback)
#define KNOWROB_BUILTIN_STORAGE(Name, Type)
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
static uint32_t batchSize()
bool removeOne(const Triple &triple) override
void query(const GraphQueryPtr &query, const BindingsHandler &callback) override
static PrologTerm transaction(std::string_view rdf_functor, const TripleContainerPtr &triples)
bool insertAll(const TripleContainerPtr &triples) override
void batchOrigin(std::string_view origin, const TripleHandler &callback) override
bool insertOne(const Triple &triple) override
bool isPersistent() const override
void count(const ResourceCounter &callback) const override
bool removeAllWithOrigin(std::string_view origin) override
static void initializeProlog()
bool has_grounding() const
std::shared_ptr< TripleContainer > TripleContainerPtr
std::shared_ptr< const Bindings > BindingsPtr
std::function< void(std::string_view, uint64_t)> ResourceCounter
std::function< void(const BindingsPtr &)> BindingsHandler
std::function< void(const TripleContainerPtr &)> TripleHandler
std::shared_ptr< GraphQuery > GraphQueryPtr