knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
ObserverJob.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_OBSERVER_JOB_H
7 #define KNOWROB_OBSERVER_JOB_H
8 
9 #include <memory>
10 #include "ObserverManager.h"
11 #include "knowrob/semweb/GraphBuiltin.h"
12 #include "knowrob/semweb/GraphUnion.h"
13 #include "knowrob/semweb/GraphSequence.h"
14 
15 namespace knowrob {
19  class ObserverJob {
20  public:
27  ObserverJob(const std::shared_ptr<ObserverManager> &manager,
28  const GraphQueryPtr &query,
29  const BindingsHandler &callback);
30 
32 
36  void stop();
37 
42  void processInsertion(const TripleContainerPtr &triples);
43 
48  void processRemoval(const TripleContainerPtr &triples);
49 
53  auto &manager() const { return manager_; }
54 
55  protected:
56  std::shared_ptr<ObserverManager> manager_;
59 
60  struct Node {
61  std::shared_ptr<GraphPattern> pattern;
62  std::vector<std::shared_ptr<GraphBuiltin>> builtins;
63  std::vector<std::shared_ptr<Node>> children;
64  std::vector<Node *> parents;
65  std::map<size_t, BindingsPtr> solutions;
66  };
67  std::vector<std::shared_ptr<Node>> nodes_;
68 
69  using NodeParents = std::vector<std::shared_ptr<Node>>;
71 
72  NodeParents createGraph(const std::shared_ptr<GraphTerm> &term, const NodeParents &parents);
73 
74  std::shared_ptr<ObserverJob::Node> createNode(const std::shared_ptr<GraphPattern> &pattern);
75 
76  void initializeNode(const std::shared_ptr<Node> &node);
77 
78  void initializeNode(const std::shared_ptr<Node> &node, const BindingsPtr &bindings);
79 
80  GraphQueryPtr makeQuery(const std::vector<Node *> &reverseSequence);
81 
82  GraphQueryPtr makeAtomicQuery(const std::shared_ptr<Node> &node, const BindingsPtr &bindings);
83 
84  bool matches(const Node &node, const Triple &triple);
85 
86  void remove(const std::shared_ptr<Node> &node, const Triple &triple);
87 
88  void insert(const std::shared_ptr<Node> &node, const Triple &triple);
89 
90  void doInsert(const std::shared_ptr<Node> &node, const BindingsPtr &newBindings);
91 
92  void doInsert(const std::shared_ptr<Node> &node,
93  const BindingsPtr &parentBindings,
94  const BindingsPtr &nodeBindings);
95 
96  BindingsPtr applyBuiltins(const std::shared_ptr<Node> &node, const BindingsPtr &bindings);
97  };
98 
99 } // knowrob
100 
101 #endif //KNOWROB_OBSERVER_JOB_H
auto & manager() const
Definition: ObserverJob.h:53
bool matches(const Node &node, const Triple &triple)
std::vector< std::shared_ptr< Node > > nodes_
Definition: ObserverJob.h:67
void doInsert(const std::shared_ptr< Node > &node, const BindingsPtr &newBindings)
BindingsPtr applyBuiltins(const std::shared_ptr< Node > &node, const BindingsPtr &bindings)
NodeParents createGraph(const std::shared_ptr< GraphTerm > &term, const NodeParents &parents)
void initializeNode(const std::shared_ptr< Node > &node)
void insert(const std::shared_ptr< Node > &node, const Triple &triple)
std::shared_ptr< ObserverJob::Node > createNode(const std::shared_ptr< GraphPattern > &pattern)
void remove(const std::shared_ptr< Node > &node, const Triple &triple)
void processRemoval(const TripleContainerPtr &triples)
void initializeNode(const std::shared_ptr< Node > &node, const BindingsPtr &bindings)
void doInsert(const std::shared_ptr< Node > &node, const BindingsPtr &parentBindings, const BindingsPtr &nodeBindings)
GraphQueryPtr query_
Definition: ObserverJob.h:57
BindingsHandler callback_
Definition: ObserverJob.h:58
ObserverJob(const std::shared_ptr< ObserverManager > &manager, const GraphQueryPtr &query, const BindingsHandler &callback)
void processInsertion(const TripleContainerPtr &triples)
std::vector< std::shared_ptr< Node > > NodeParents
Definition: ObserverJob.h:69
GraphQueryPtr makeAtomicQuery(const std::shared_ptr< Node > &node, const BindingsPtr &bindings)
std::shared_ptr< ObserverManager > manager_
Definition: ObserverJob.h:56
GraphQueryPtr makeQuery(const std::vector< Node * > &reverseSequence)
NodeParents terminalNodes_
Definition: ObserverJob.h:70
GraphTermRule & pattern()
Definition: graph.cpp:23
TermRule & term()
Definition: terms.cpp:136
std::shared_ptr< TripleContainer > TripleContainerPtr
std::shared_ptr< const Bindings > BindingsPtr
Definition: Bindings.h:151
std::function< void(const BindingsPtr &)> BindingsHandler
Definition: Bindings.h:152
std::shared_ptr< GraphQuery > GraphQueryPtr
Definition: GraphQuery.h:65
std::shared_ptr< GraphPattern > pattern
Definition: ObserverJob.h:61
std::vector< Node * > parents
Definition: ObserverJob.h:64
std::vector< std::shared_ptr< GraphBuiltin > > builtins
Definition: ObserverJob.h:62
std::vector< std::shared_ptr< Node > > children
Definition: ObserverJob.h:63
std::map< size_t, BindingsPtr > solutions
Definition: ObserverJob.h:65