knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
QueryableStorage.h
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 #ifndef KNOWROB_QUERYABLE_STORAGE_H
7 #define KNOWROB_QUERYABLE_STORAGE_H
8 
9 #include "knowrob/queries/TokenBuffer.h"
10 #include "Storage.h"
11 #include "knowrob/queries/Answer.h"
12 #include "knowrob/semweb/GraphPathQuery.h"
13 #include "knowrob/queries/AnswerYes.h"
14 #include "knowrob/queries/AnswerNo.h"
15 #include "knowrob/semweb/GraphConnective.h"
16 #include "knowrob/semweb/GraphQueryExpansion.h"
17 #include "VersionedOrigin.h"
18 
19 namespace knowrob {
20  using ResourceCounter = std::function<void(std::string_view, uint64_t)>;
21 
25  class QueryableStorage : public Storage {
26  public:
27  static AtomPtr versionProperty;
28 
30 
31  ~QueryableStorage() override = default;
32 
36  virtual bool isPersistent() const = 0;
37 
43  virtual void foreach(const TripleVisitor &visitor) const;
44 
50  virtual void batch(const TripleHandler &callback) const = 0;
51 
58  virtual void batchOrigin(std::string_view origin, const TripleHandler &callback) = 0;
59 
64  virtual bool contains(const Triple &triple);
65 
70  virtual void match(const TriplePattern &query, const TripleVisitor &visitor);
71 
77  virtual void query(const GraphQueryPtr &query, const BindingsHandler &callback) = 0;
78 
82  virtual void count(const ResourceCounter &callback) const = 0;
83 
87  std::vector<VersionedOriginPtr> getOrigins();
88 
93  std::optional<std::string> getVersionOfOrigin(std::string_view origin);
94 
100  void setVersionOfOrigin(std::string_view origin, std::string_view version);
101 
106 
113 
121  static std::shared_ptr<AnswerYes> yes(const GraphPathQueryPtr &original,
122  const GraphQueryExpansionPtr &expansion,
123  const BindingsPtr &bindings);
124 
130  static std::shared_ptr<AnswerNo> no(const GraphPathQueryPtr &q);
131  };
132 
133  using QueryableBackendPtr = std::shared_ptr<QueryableStorage>;
134 }
135 
136 #endif //KNOWROB_QUERYABLE_STORAGE_H
std::optional< std::string > getVersionOfOrigin(std::string_view origin)
virtual bool isPersistent() const =0
GraphQueryExpansionPtr expand(const GraphQueryPtr &q)
virtual void count(const ResourceCounter &callback) const =0
~QueryableStorage() override=default
static std::shared_ptr< AnswerYes > yes(const GraphPathQueryPtr &original, const GraphQueryExpansionPtr &expansion, const BindingsPtr &bindings)
virtual void batch(const TripleHandler &callback) const =0
virtual void batchOrigin(std::string_view origin, const TripleHandler &callback)=0
QueryableStorage(StorageFeatures features=StorageFeature::NothingSpecial)
virtual void match(const TriplePattern &query, const TripleVisitor &visitor)
void setVersionOfOrigin(std::string_view origin, std::string_view version)
static AtomPtr versionProperty
virtual bool contains(const Triple &triple)
virtual void query(const GraphQueryPtr &query, const BindingsHandler &callback)=0
std::vector< VersionedOriginPtr > getOrigins()
static std::shared_ptr< AnswerNo > no(const GraphPathQueryPtr &q)
FunctionRule & function()
Definition: terms.cpp:140
std::function< void(const TriplePtr &)> TripleVisitor
StorageFeature
Definition: Storage.h:24
std::shared_ptr< GraphQueryExpansion > GraphQueryExpansionPtr
std::shared_ptr< const Bindings > BindingsPtr
Definition: Bindings.h:151
std::function< void(std::string_view, uint64_t)> ResourceCounter
std::function< void(const BindingsPtr &)> BindingsHandler
Definition: Bindings.h:152
std::shared_ptr< Atom > AtomPtr
Definition: Atom.h:69
std::function< void(const TripleContainerPtr &)> TripleHandler
std::shared_ptr< GraphQuery > GraphQueryPtr
Definition: GraphQuery.h:65
std::shared_ptr< QueryableStorage > QueryableBackendPtr
std::shared_ptr< GraphPathQuery > GraphPathQueryPtr