6 #include "knowrob/storage/SPARQLBackend.h"
11 return sparql(q(), callback);
15 std::shared_ptr<GraphPattern> negatedPattern;
25 auto pat = std::static_pointer_cast<GraphPattern>(q->term());
26 if (pat->value()->isNegated()) {
33 auto positivePat = std::make_shared<TriplePattern>(*negatedPattern->value());
34 positivePat->setIsNegated(
false);
35 auto positiveQuery = std::make_shared<GraphQuery>(
36 std::make_shared<GraphPattern>(positivePat),
38 bool hasSolution =
false;
51 static const char *sparqlString =
"SELECT ?resource (COUNT(?s) AS ?count) WHERE "\
52 "{ ?s rdf:type ?resource . } UNION { ?s ?resource ?o . } } "\
55 auto resource = bindings->getAtomic(
"resource");
56 auto count = bindings->getAtomic(
"count");
57 if (!resource || !
count || !
count->isNumeric()) {
58 KB_WARN(
"Failed to count triples!");
61 callback(resource->stringForm(), std::static_pointer_cast<Numeric>(
count)->asLong());
static std::shared_ptr< const Bindings > emptyBindings()
void count(const ResourceCounter &callback) const override
virtual bool sparql(std::string_view queryString, const BindingsHandler &callback) const =0
bool query(const SPARQLQuery &query, const BindingsHandler &callback) const
std::shared_ptr< const Bindings > BindingsPtr
std::function< void(std::string_view, uint64_t)> ResourceCounter
QueryContextPtr OneSolutionContext()
std::function< void(const BindingsPtr &)> BindingsHandler
std::shared_ptr< GraphQuery > GraphQueryPtr