knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
TriplePattern.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_FRAMED_TRIPLE_PATTERN_H
7 #define KNOWROB_FRAMED_TRIPLE_PATTERN_H
8 
9 #include "knowrob/formulas/Predicate.h"
10 #include "knowrob/semweb/Triple.h"
11 #include "knowrob/semweb/TripleContainer.h"
12 #include "knowrob/formulas/FirstOrderLiteral.h"
13 #include "knowrob/queries/QueryContext.h"
14 #include "knowrob/terms/groundable.h"
15 #include "knowrob/terms/Numeric.h"
16 #include "knowrob/terms/IRIAtom.h"
17 #include "knowrob/terms/Blank.h"
18 
19 namespace knowrob {
23  enum class FilterType {
24  EQ = 0,
25  NEQ,
26  LT,
27  GT,
28  LEQ,
29  GEQ
30  };
31 
38 
43  class TriplePattern : public FirstOrderLiteral {
44  public:
50  explicit TriplePattern(const Triple &triple, bool isNegated = false);
51 
56  explicit TriplePattern(const PredicatePtr &predicate, bool isNegated = false);
57 
64  TriplePattern(const TermPtr &s, const TermPtr &p, const TermPtr &o, bool isNegated = false);
65 
70  void setTripleFrame(const GraphSelector &frame);
71 
76  void getTripleFrame(GraphSelector &frame) const;
77 
81  auto &subjectTerm() const { return subjectTerm_; }
82 
88 
92  auto &propertyTerm() const { return propertyTerm_; }
93 
97  auto &objectTerm() const { return objectTerm_; }
98 
104 
108  auto &objectVariable() const { return objectVariable_; }
109 
115 
119  auto &graphTerm() const { return graphTerm_; }
120 
126 
131  void setGraphName(const std::string_view &graphName) { graphTerm_ = getGraphTerm(graphName); }
132 
136  auto &perspectiveTerm() const { return perspectiveTerm_; }
137 
143 
147  auto &beginTerm() const { return beginTerm_; }
148 
154 
158  auto &endTerm() const { return endTerm_; }
159 
165 
169  auto &confidenceTerm() const { return confidenceTerm_; }
170 
176 
180  auto objectOperator() const { return objectOperator_; }
181 
187 
191  auto &isOccasionalTerm() const { return isOccasional_; }
192 
198 
202  auto &isUncertainTerm() const { return isUncertain_; }
203 
209 
213  bool isOptional() const { return isOptional_; }
214 
220 
224  uint32_t numVariables() const override;
225 
229  std::vector<VariablePtr> getVariables(bool includeObjectVar = true) const;
230 
235  bool filter(const Triple &triple) const;
236 
243  bool instantiateInto(Triple &triple,
244  const std::shared_ptr<const Bindings> &bindings = Bindings::emptyBindings()) const;
245 
246  static std::shared_ptr<Predicate> getRDFPredicate(const PredicatePtr &predicate);
247 
248  protected:
254  bool isOptional_;
255 
256  // below are treated as optional
264 
265  static std::shared_ptr<Atom> getGraphTerm(const std::string_view &graphName);
266 
267  static std::shared_ptr<Predicate> getRDFPredicate(const TermPtr &s, const TermPtr &p, const TermPtr &o);
268 
269  static std::shared_ptr<Predicate> getRDFPredicate(const Triple &data);
270  };
271 
275  using TriplePatternPtr = std::shared_ptr<TriplePattern>;
276 
283  TriplePatternPtr applyBindings(const TriplePatternPtr &pat, const Bindings &bindings);
284 
289  public:
291 
293 
295 
299  void push_back(const TriplePatternPtr &q);
300 
301  // Override TripleContainer
302  ConstGenerator cgenerator() const override;
303 
304  // Override MutableTripleContainer
306 
307  protected:
308  std::vector<TriplePtr *> data_;
309  std::vector<TriplePatternPtr> statements_;
310  };
311 } // knowrob
312 
313 #endif //KNOWROB_FRAMED_TRIPLE_PATTERN_H
static std::shared_ptr< const Bindings > emptyBindings()
Definition: Bindings.cpp:99
const auto & predicate() const
std::function< TriplePtr *()> MutableGenerator
std::function< const TriplePtr *()> ConstGenerator
ConstGenerator cgenerator() const override
std::vector< TriplePatternPtr > statements_
MutableGenerator generator() override
TriplePatternContainer(const TriplePatternContainer &other)=delete
void push_back(const TriplePatternPtr &q)
std::vector< TriplePtr * > data_
void setObjectTerm(const TermPtr &objectTerm)
auto objectOperator() const
groundable< Double > beginTerm_
void getTripleFrame(GraphSelector &frame) const
static std::shared_ptr< Predicate > getRDFPredicate(const Triple &data)
void setEndTerm(const groundable< Double > &endTerm)
void setTripleFrame(const GraphSelector &frame)
groundable< Double > endTerm_
VariablePtr objectVariable_
bool instantiateInto(Triple &triple, const std::shared_ptr< const Bindings > &bindings=Bindings::emptyBindings()) const
void setGraphTerm(const groundable< Atom > &graphTerm)
static std::shared_ptr< Atom > getGraphTerm(const std::string_view &graphName)
void setIsOptional(bool isOptional)
void setObjectVariable(const VariablePtr &objectVariable)
auto & propertyTerm() const
Definition: TriplePattern.h:92
void setConfidenceTerm(const groundable< Double > &confidenceTerm)
void setIsOccasionalTerm(const groundable< Numeric > &isOccasional)
void setBeginTerm(const groundable< Double > &beginTerm)
void setPerspectiveTerm(const groundable< Atom > &perspectiveTerm)
TriplePattern(const Triple &triple, bool isNegated=false)
void setSubjectTerm(const TermPtr &subjectTerm)
Definition: TriplePattern.h:87
uint32_t numVariables() const override
void setObjectOperator(FilterType objectOperator)
groundable< Atom > graphTerm_
auto & subjectTerm() const
Definition: TriplePattern.h:81
auto & objectVariable() const
void setGraphName(const std::string_view &graphName)
void setIsUncertainTerm(const groundable< Numeric > &isUncertain)
std::vector< VariablePtr > getVariables(bool includeObjectVar=true) const
static std::shared_ptr< Predicate > getRDFPredicate(const PredicatePtr &predicate)
auto & isOccasionalTerm() const
auto & isUncertainTerm() const
TriplePattern(const TermPtr &s, const TermPtr &p, const TermPtr &o, bool isNegated=false)
auto & beginTerm() const
static std::shared_ptr< Atom > getGraphTerm(const std::string_view &graphName)
groundable< Numeric > isOccasional_
auto & objectTerm() const
Definition: TriplePattern.h:97
groundable< Numeric > isUncertain_
bool filter(const Triple &triple) const
static std::shared_ptr< Predicate > getRDFPredicate(const TermPtr &s, const TermPtr &p, const TermPtr &o)
groundable< Atom > perspectiveTerm_
auto & endTerm() const
groundable< Double > confidenceTerm_
auto & graphTerm() const
auto & perspectiveTerm() const
TriplePattern(const PredicatePtr &predicate, bool isNegated=false)
auto & confidenceTerm() const
const IRIAtomPtr isUncertain
Definition: reification.h:18
const IRIAtomPtr isOccasional
Definition: reification.h:19
std::shared_ptr< TriplePattern > TriplePatternPtr
std::shared_ptr< Term > TermPtr
Definition: Term.h:117
FilterType inverseFilterType(FilterType op)
std::shared_ptr< Predicate > PredicatePtr
Definition: Predicate.h:77
std::shared_ptr< Variable > VariablePtr
Definition: Variable.h:60
FirstOrderLiteralPtr applyBindings(const FirstOrderLiteralPtr &lit, const Bindings &bindings)