knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
TriplePattern.cpp
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 #include "knowrob/semweb/TriplePattern.h"
7 #include "knowrob/Logger.h"
8 #include "knowrob/queries/QueryError.h"
9 #include "knowrob/terms/Atomic.h"
10 #include "knowrob/terms/Numeric.h"
11 #include "knowrob/terms/Atom.h"
12 #include "knowrob/terms/IRIAtom.h"
13 #include "knowrob/terms/Blank.h"
14 #include "knowrob/integration/python/utils.h"
15 #include "knowrob/semweb/rdf.h"
16 #include "knowrob/integration/python/converter/vector.h"
17 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
18 
19 using namespace knowrob;
20 
22  switch (op) {
23  case FilterType::EQ:
24  return FilterType::NEQ;
25  case FilterType::NEQ:
26  return FilterType::EQ;
27  case FilterType::LT:
28  return FilterType::GEQ;
29  case FilterType::GT:
30  return FilterType::LEQ;
31  case FilterType::LEQ:
32  return FilterType::GT;
33  case FilterType::GEQ:
34  return FilterType::LT;
35  }
36  return FilterType::EQ;
37 }
38 
39 TriplePattern::TriplePattern(const Triple &triple, bool isNegated)
40  : FirstOrderLiteral(getRDFPredicate(triple), isNegated),
41  subjectTerm_(predicate_->arguments()[0]),
42  propertyTerm_(predicate_->arguments()[1]),
43  objectTerm_(predicate_->arguments()[2]),
44  objectOperator_(FilterType::EQ),
45  isOptional_(false) {
46  if (triple.confidence().has_value()) {
47  confidenceTerm_ = std::make_shared<Double>(triple.confidence().value());
48  }
49  if (triple.begin().has_value()) {
50  beginTerm_ = std::make_shared<Double>(triple.begin().value());
51  }
52  if (triple.end().has_value()) {
53  endTerm_ = std::make_shared<Double>(triple.end().value());
54  }
55  if (triple.graph()) {
56  graphTerm_ = getGraphTerm(triple.graph().value());
57  }
58  if (triple.perspective()) {
59  perspectiveTerm_ = IRIAtom::Tabled(triple.perspective().value());
60  }
61  if (triple.isOccasional()) {
63  }
64  if (triple.isUncertain()) {
66  }
67 }
68 
69 TriplePattern::TriplePattern(const PredicatePtr &pred, bool isNegated)
70  : FirstOrderLiteral(getRDFPredicate(pred), isNegated),
71  subjectTerm_(predicate_->arguments()[0]),
72  propertyTerm_(predicate_->arguments()[1]),
73  objectTerm_(predicate_->arguments()[2]),
74  objectOperator_(FilterType::EQ),
75  isOptional_(false) {
76 }
77 
78 TriplePattern::TriplePattern(const TermPtr &s, const TermPtr &p, const TermPtr &o, bool isNegated)
79  : FirstOrderLiteral(getRDFPredicate(s, p, o), isNegated),
80  subjectTerm_(s),
81  propertyTerm_(p),
82  objectTerm_(o),
83  objectOperator_(FilterType::EQ),
84  isOptional_(false) {
85 }
86 
88  if (frame.confidence.has_value()) {
89  confidenceTerm_ = std::make_shared<Double>(frame.confidence.value());
90  }
91  if (frame.begin.has_value()) {
92  beginTerm_ = std::make_shared<Double>(frame.begin.value());
93  }
94  if (frame.end.has_value()) {
95  endTerm_ = std::make_shared<Double>(frame.end.value());
96  }
97  if (frame.graph) {
98  graphTerm_ = frame.graph;
99  }
100  if (frame.perspective) {
101  perspectiveTerm_ = Atom::Tabled(frame.perspective->iri());
102  }
103  if (frame.uncertain) {
105  }
106  if (frame.occasional) {
108  }
109 }
110 
112  if (beginTerm().has_grounding() && beginTerm().grounded()->isNumeric()) {
113  frame.begin = std::static_pointer_cast<Numeric>(beginTerm().grounded())->asDouble();
114  }
115  if (endTerm().has_grounding() && endTerm().grounded()->isNumeric()) {
116  frame.end = std::static_pointer_cast<Numeric>(endTerm().grounded())->asDouble();
117  }
118  if (confidenceTerm().has_grounding() && confidenceTerm().grounded()->isNumeric()) {
119  frame.confidence = std::static_pointer_cast<Numeric>(confidenceTerm().grounded())->asDouble();
120  }
121  if (isUncertainTerm().has_grounding() && isUncertainTerm().grounded()->isNumeric()) {
122  frame.uncertain = std::static_pointer_cast<Numeric>(isUncertainTerm().grounded())->asBoolean();
123  }
124  if (isOccasionalTerm().has_grounding() && isOccasionalTerm().grounded()->isNumeric()) {
125  frame.occasional = std::static_pointer_cast<Numeric>(isOccasionalTerm().grounded())->asBoolean();
126  }
127  if (graphTerm().has_grounding() && graphTerm().grounded()->isAtom()) {
128  frame.graph = std::static_pointer_cast<Atom>(graphTerm().grounded());
129  }
130  if (perspectiveTerm().has_grounding() && perspectiveTerm().grounded()->isAtomic()) {
131  frame.perspective = Perspective::get((perspectiveTerm().grounded())->stringForm());
132  }
133 }
134 
135 std::shared_ptr<Atom> TriplePattern::getGraphTerm(const std::string_view &graphName) {
136  static std::map<std::string, AtomPtr, std::less<>> graphTerms;
137  if (!graphName.empty()) {
138  auto it = graphTerms.find(graphName);
139  if (it == graphTerms.end()) {
140  auto graphTerm = Atom::Tabled(graphName.data());
141  graphTerms[graphName.data()] = graphTerm;
142  return graphTerm;
143  } else {
144  return it->second;
145  }
146  }
147  return {};
148 }
149 
150 std::shared_ptr<Predicate> TriplePattern::getRDFPredicate(const TermPtr &s, const TermPtr &p, const TermPtr &o) {
151  return std::make_shared<Predicate>("triple", std::vector<TermPtr>({s, p, o}));
152 }
153 
154 std::shared_ptr<Predicate> TriplePattern::getRDFPredicate(const PredicatePtr &predicate) {
155  if (predicate->arity() == 3 && predicate->functor()->stringForm() == "triple") {
156  return predicate;
157  } else if (predicate->arity() == 2) {
158  return getRDFPredicate(predicate->arguments()[0],
159  predicate->functor(),
160  predicate->arguments()[1]);
161  } else {
162  throw QueryError("RDF literal can only be constructed from 2-ary predicates but {} is not.", *predicate);
163  }
164 }
165 
166 std::shared_ptr<Predicate> TriplePattern::getRDFPredicate(const Triple &data) {
167  TermPtr s, p, o;
168  p = IRIAtom::Tabled(data.predicate());
169  if (data.isSubjectBlank()) {
170  s = Blank::Tabled(data.subject());
171  } else {
172  s = IRIAtom::Tabled(data.subject());
173  }
174  if (data.isObjectBlank()) {
175  o = Blank::Tabled(data.valueAsString());
176  } else {
177  o = Atomic::makeTripleValue(data);
178  }
179  return std::make_shared<Predicate>("triple", std::vector<TermPtr>({s, p, o}));
180 }
181 
182 std::vector<VariablePtr> TriplePattern::getVariables(bool includeObjectVar) const {
183  std::vector<VariablePtr> vars;
184  TermPtr o_var = (includeObjectVar ? objectVariable_ : nullptr);
185  for (auto &t: {
186  subjectTerm_,
188  objectTerm_,
189  o_var,
190  *graphTerm_,
192  *beginTerm_,
193  *endTerm_,
194  *isUncertain_,
195  *isOccasional_,
196  *confidenceTerm_}) {
197  if (t && t->termType() == TermType::VARIABLE) vars.push_back(std::static_pointer_cast<Variable>(t));
198  }
199  return vars;
200 }
201 
202 uint32_t TriplePattern::numVariables() const {
203  return getVariables(false).size();
204 }
205 
206 
207 static bool filterString(std::string_view value, const TriplePattern &query) {
208  auto &q_term = query.objectTerm();
209  if (!q_term->isAtomic()) return false;
210  auto q_atomic = std::static_pointer_cast<Atomic>(q_term);
211  switch (query.objectOperator()) {
212  case FilterType::EQ:
213  return value == q_atomic->stringForm();
214  case FilterType::NEQ:
215  return value != q_atomic->stringForm();
216  case FilterType::LEQ:
217  return value <= q_atomic->stringForm();
218  case FilterType::GEQ:
219  return value >= q_atomic->stringForm();
220  case FilterType::GT:
221  return value > q_atomic->stringForm();
222  case FilterType::LT:
223  return value < q_atomic->stringForm();
224  }
225  return false;
226 }
227 
228 template<typename NumType>
229 bool filterNumeric(const NumType &a, const NumType &b, FilterType op) {
230  switch (op) {
231  case FilterType::EQ:
232  return a == b;
233  case FilterType::NEQ:
234  return a != b;
235  case FilterType::LEQ:
236  return a <= b;
237  case FilterType::GEQ:
238  return a >= b;
239  case FilterType::GT:
240  return a > b;
241  case FilterType::LT:
242  return a < b;
243  }
244  return false;
245 }
246 
247 bool TriplePattern::filter(const Triple &triple) const {
248  if (triple.isObjectIRI() || triple.isObjectBlank()) {
249  return filterString(triple.valueAsString(), *this);
250  } else if (triple.xsdType()) {
251  if (triple.xsdType().value() == XSDType::STRING) {
252  return filterString(triple.valueAsString(), *this);
253  }
254  auto &q_term = objectTerm();
255  if (!q_term->isNumeric()) return false;
256  auto q_numeric = std::static_pointer_cast<Numeric>(q_term);
257  switch (triple.xsdType().value()) {
259  return filterNumeric(triple.valueAsBoolean(), q_numeric->asBoolean(), objectOperator());
261  return filterNumeric(triple.valueAsDouble(), q_numeric->asDouble(), objectOperator());
263  return filterNumeric(triple.valueAsFloat(), q_numeric->asFloat(), objectOperator());
266  return filterNumeric(triple.valueAsInt(), q_numeric->asInteger(), objectOperator());
268  return filterNumeric(triple.valueAsLong(), q_numeric->asLong(), objectOperator());
270  return filterNumeric(triple.valueAsShort(), q_numeric->asShort(), objectOperator());
272  return filterNumeric(triple.valueAsUnsignedLong(), q_numeric->asUnsignedLong(), objectOperator());
274  return filterNumeric(triple.valueAsUnsignedInt(), q_numeric->asUnsignedInteger(), objectOperator());
276  return filterNumeric(triple.valueAsUnsignedShort(), q_numeric->asUnsignedShort(), objectOperator());
279  break;
280  }
281  }
282  return false;
283 }
284 
285 bool
286 TriplePattern::instantiateInto(Triple &triple, const std::shared_ptr<const Bindings> &bindings) const {
287  // return a flag that indicates if s/p/o were assigned successfully.
288  bool hasMissingSPO = false;
289  // handle subject
290  if (subjectTerm_) {
291  auto &s = subjectTerm_->isVariable() ?
292  bindings->get(std::static_pointer_cast<Variable>(subjectTerm_)->name()) :
293  subjectTerm_;
294  if (!s) {
295  hasMissingSPO = true;
296  } else if (s->isBlank()) {
297  triple.setSubjectBlank(std::static_pointer_cast<Blank>(s)->stringForm());
298  } else if (s->termType() == TermType::ATOMIC) {
299  triple.setSubject(std::static_pointer_cast<Atomic>(s)->stringForm());
300  } else {
301  hasMissingSPO = true;
302  }
303  } else {
304  hasMissingSPO = true;
305  }
306  // handle property
307  if (propertyTerm_) {
308  auto &p = propertyTerm_->isVariable() ?
309  bindings->get(std::static_pointer_cast<Variable>(propertyTerm_)->name()) :
311  if (p && p->termType() == TermType::ATOMIC) {
312  triple.setPredicate(std::static_pointer_cast<Atomic>(p)->stringForm());
313  } else {
314  hasMissingSPO = true;
315  }
316  } else {
317  hasMissingSPO = true;
318  }
319  // handle object
320  if (objectTerm_ || objectVariable_) {
321  auto &o = (objectTerm_ && objectTerm_->isVariable()) ?
322  bindings->get(std::static_pointer_cast<Variable>(objectTerm_)->name()) :
323  (objectVariable_ && objectVariable_->isVariable()) ?
324  bindings->get(std::static_pointer_cast<Variable>(objectVariable_)->name()) :
325  objectTerm_;
326 
327  if (!o) {
328  hasMissingSPO = true;
329  } else if (o->isNumeric()) {
330  auto numeric = std::static_pointer_cast<Numeric>(o);
331  triple.setXSDValue(numeric->stringForm(), numeric->xsdType());
332  } else if (o->termType() == TermType::ATOMIC) {
333  auto atom = std::static_pointer_cast<Atomic>(o);
334  if (atom->isIRI()) {
335  triple.setObjectIRI(atom->stringForm());
336  } else if (atom->isBlank()) {
337  triple.setObjectBlank(atom->stringForm());
338  } else {
339  triple.setStringValue(atom->stringForm());
340  }
341  } else {
342  hasMissingSPO = true;
343  }
344  } else {
345  hasMissingSPO = true;
346  }
347  // handle optional properties
348  if (graphTerm_) {
349  auto &g = graphTerm_->isVariable() ?
350  bindings->get(std::static_pointer_cast<Variable>(*graphTerm_)->name()) :
351  *graphTerm_;
352  if (g && g->termType() == TermType::ATOMIC) {
353  triple.setGraph(std::static_pointer_cast<Atomic>(g)->stringForm());
354  }
355  }
356  if (perspectiveTerm_) {
357  auto &a = perspectiveTerm_->isVariable() ?
358  bindings->get(std::static_pointer_cast<Variable>(*perspectiveTerm_)->name()) :
360  if (a && a->termType() == TermType::ATOMIC) {
361  triple.setPerspective(std::static_pointer_cast<Atomic>(a)->stringForm());
362  }
363  }
364  if (confidenceTerm_) {
365  auto &c = confidenceTerm_->isVariable() ?
366  bindings->get(std::static_pointer_cast<Variable>(*confidenceTerm_)->name()) :
368  if (c && c->isNumeric()) {
369  triple.setConfidence(std::static_pointer_cast<Numeric>(c)->asDouble());
370  }
371  }
372  if (beginTerm_) {
373  auto &b = beginTerm_->isVariable() ?
374  bindings->get(std::static_pointer_cast<Variable>(*beginTerm_)->name()) :
375  *beginTerm_;
376  if (b && b->isNumeric()) {
377  triple.setBegin(std::static_pointer_cast<Numeric>(b)->asDouble());
378  }
379  }
380  if (endTerm_) {
381  auto &e = endTerm_->isVariable() ?
382  bindings->get(std::static_pointer_cast<Variable>(*endTerm_)->name()) :
383  *endTerm_;
384  if (e && e->isNumeric()) {
385  triple.setEnd(std::static_pointer_cast<Numeric>(e)->asDouble());
386  }
387  }
388  if (isOccasional_) {
389  auto &o = isOccasional_->isVariable() ?
390  bindings->get(std::static_pointer_cast<Variable>(*isOccasional_)->name()) :
391  *isOccasional_;
392  if (o && o->isNumeric()) {
393  triple.setIsOccasional(std::static_pointer_cast<Numeric>(o)->asBoolean());
394  }
395  }
396  if (isUncertain_) {
397  auto &u = isUncertain_->isVariable() ?
398  bindings->get(std::static_pointer_cast<Variable>(*isUncertain_)->name()) :
399  *isUncertain_;
400  if (u && u->isNumeric()) {
401  triple.setIsUncertain(std::static_pointer_cast<Numeric>(u)->asBoolean());
402  }
403  }
404 
405  return !hasMissingSPO;
406 }
407 
409  for (auto d: data_) {
410  delete d;
411  }
412 }
413 
415  statements_.emplace_back(q);
416  auto data = new TriplePtr;
417  data_.push_back(data);
418  data->ptr = new TripleView();
419  data->owned = true;
420  if (!q->instantiateInto(*data->ptr)) {
421  data_.pop_back();
422  }
423 }
424 
426  return [this, i = std::size_t(0)]() mutable -> const TriplePtr * {
427  if (i < data_.size()) return data_[i++];
428  return nullptr;
429  };
430 }
431 
433  return [this, i = std::size_t(0)]() mutable -> TriplePtr * {
434  if (i < data_.size()) return data_[i++];
435  return nullptr;
436  };
437 }
438 
439 namespace knowrob {
441  bool hasChanges = false;
442 
443  auto subject = applyBindings(pat->subjectTerm(), bindings);
444  if (subject != pat->subjectTerm()) hasChanges = true;
445 
446  auto property = applyBindings(pat->propertyTerm(), bindings);
447  if (property != pat->propertyTerm()) hasChanges = true;
448 
449  auto object = applyBindings(pat->objectTerm(), bindings);
450  if (object != pat->objectTerm()) hasChanges = true;
451  else if (pat->objectVariable()) {
452  auto actualObject = applyBindings(pat->objectVariable(), bindings);
453  if (actualObject && actualObject != pat->objectTerm()) {
454  object = actualObject;
455  hasChanges = true;
456  }
457  }
458 
459  auto graph = pat->graphTerm() ? applyBindings(*pat->graphTerm(), bindings) : nullptr;
460  if (graph && graph != *pat->graphTerm()) hasChanges = true;
461 
462  auto agent = pat->perspectiveTerm() ? applyBindings(*pat->perspectiveTerm(), bindings) : nullptr;
463  if (agent && agent != *pat->perspectiveTerm()) hasChanges = true;
464 
465  auto confidence = pat->confidenceTerm() ? applyBindings(*pat->confidenceTerm(), bindings) : nullptr;
466  if (confidence && confidence != *pat->confidenceTerm()) hasChanges = true;
467 
468  auto begin = pat->beginTerm() ? applyBindings(*pat->beginTerm(), bindings) : nullptr;
469  if (begin && begin != *pat->beginTerm()) hasChanges = true;
470 
471  auto end = pat->endTerm() ? applyBindings(*pat->endTerm(), bindings) : nullptr;
472  if (end && end != *pat->endTerm()) hasChanges = true;
473 
474  auto occasional = pat->isOccasionalTerm() ? applyBindings(*pat->isOccasionalTerm(), bindings) : nullptr;
475  if (occasional && occasional != *pat->isOccasionalTerm()) hasChanges = true;
476 
477  auto uncertain = pat->isUncertainTerm() ? applyBindings(*pat->isUncertainTerm(), bindings) : nullptr;
478  if (uncertain && uncertain != *pat->isUncertainTerm()) hasChanges = true;
479 
480  if (!hasChanges) return pat;
481 
482  auto patInstance = std::make_shared<TriplePattern>(
483  subject, property, object, pat->isNegated());
484  patInstance->setObjectOperator(pat->objectOperator());
485  if (graph) patInstance->setGraphTerm(groundable<Atom>::cast(graph));
486  if (agent) patInstance->setPerspectiveTerm(groundable<Atom>::cast(agent));
487  if (confidence) patInstance->setConfidenceTerm(groundable<Double>::cast(confidence));
488  if (begin) patInstance->setBeginTerm(groundable<Double>::cast(begin));
489  if (end) patInstance->setEndTerm(groundable<Double>::cast(end));
490  if (occasional) patInstance->setIsOccasionalTerm(groundable<Numeric>::cast(occasional));
491  if (uncertain) patInstance->setIsUncertainTerm(groundable<Numeric>::cast(uncertain));
492  return patInstance;
493  }
494 }
495 
496 namespace knowrob::py {
497  template<>
499  using namespace boost::python;
500  class_<TriplePattern, std::shared_ptr<TriplePattern>, bases<FirstOrderLiteral>>
501  ("TriplePattern", init<const Triple &, bool>())
502  .def(init<const Triple &>())
503  .def("subjectTerm", &TriplePattern::subjectTerm, return_value_policy<return_by_value>())
504  .def("propertyTerm", &TriplePattern::propertyTerm, return_value_policy<return_by_value>())
505  .def("objectTerm", &TriplePattern::objectTerm, return_value_policy<return_by_value>())
506  .def("graphTerm", &TriplePattern::graphTerm, return_value_policy<return_by_value>())
507  .def("perspectiveTerm", &TriplePattern::perspectiveTerm, return_value_policy<return_by_value>())
508  .def("beginTerm", &TriplePattern::beginTerm, return_value_policy<return_by_value>())
509  .def("endTerm", &TriplePattern::endTerm, return_value_policy<return_by_value>())
510  .def("confidenceTerm", &TriplePattern::confidenceTerm, return_value_policy<return_by_value>())
511  .def("objectOperator", &TriplePattern::objectOperator)
512  .def("isOccasionalTerm", &TriplePattern::isOccasionalTerm, return_value_policy<return_by_value>())
513  .def("isUncertainTerm", &TriplePattern::isUncertainTerm, return_value_policy<return_by_value>())
514  .def("setGraphName", &TriplePattern::setGraphName)
515  .def("setPerspectiveTerm", &TriplePattern::setPerspectiveTerm)
516  .def("setBeginTerm", &TriplePattern::setBeginTerm)
517  .def("setEndTerm", &TriplePattern::setEndTerm)
518  .def("setConfidenceTerm", &TriplePattern::setConfidenceTerm)
519  .def("setObjectOperator", &TriplePattern::setObjectOperator)
520  .def("setIsOccasionalTerm", &TriplePattern::setIsOccasionalTerm)
521  .def("setIsUncertainTerm", &TriplePattern::setIsUncertainTerm)
522  .def("filter", &TriplePattern::filter)
523  .def("instantiateInto", &TriplePattern::instantiateInto)
524  .def("getVariables", &TriplePattern::getVariables)
525  .def("numVariables", &TriplePattern::numVariables)
526  .def("getTripleFrame", &TriplePattern::getTripleFrame)
527  .def("setTripleFrame", &TriplePattern::setTripleFrame);
528 
529  // allow conversion between std::vector and python::list for TriplePattern objects.
530  typedef std::vector<std::shared_ptr<TriplePattern>> GoalList;
532  boost::python::class_<GoalList>("GoalList").def(boost::python::vector_indexing_suite<GoalList, true>());
533  }
534 }
bool filterNumeric(const NumType &a, const NumType &b, FilterType op)
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
Definition: Atom.cpp:40
static std::shared_ptr< Atomic > makeTripleValue(const Triple &triple)
Definition: Atomic.cpp:31
static std::shared_ptr< Blank > Tabled(std::string_view stringForm)
Definition: Blank.cpp:12
const auto & predicate() const
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
Definition: IRIAtom.cpp:25
std::function< TriplePtr *()> MutableGenerator
static std::shared_ptr< Numeric > trueAtom()
Definition: Numeric.cpp:15
static std::shared_ptr< Perspective > get(std::string_view iri)
Definition: Perspective.cpp:31
std::function< const TriplePtr *()> ConstGenerator
virtual std::string_view valueAsString() const =0
auto xsdType() const
Definition: Triple.h:64
virtual short valueAsShort() const =0
virtual std::optional< std::string_view > perspective() const =0
bool isUncertain() const
Definition: Triple.h:267
virtual unsigned int valueAsUnsignedInt() const =0
virtual void setSubject(std::string_view subject)=0
virtual std::optional< std::string_view > graph() const =0
virtual double valueAsDouble() const =0
virtual void setGraph(std::string_view graph)=0
auto end() const
Definition: Triple.h:277
virtual void setStringValue(std::string_view v)=0
void setConfidence(double confidence)
Definition: Triple.h:307
virtual std::string_view subject() const =0
virtual float valueAsFloat() const =0
auto confidence() const
Definition: Triple.h:282
virtual void setPerspective(std::string_view perspective)=0
void setIsUncertain(bool isUncertain)
Definition: Triple.h:292
auto begin() const
Definition: Triple.h:272
void setIsOccasional(bool isOccasional)
Definition: Triple.h:287
bool isSubjectBlank() const
Definition: Triple.h:44
virtual std::string_view predicate() const =0
void setBegin(double begin)
Definition: Triple.h:297
void setEnd(double end)
Definition: Triple.h:302
virtual long valueAsLong() const =0
virtual void setObjectIRI(std::string_view object)=0
bool isObjectIRI() const
Definition: Triple.h:54
virtual unsigned short valueAsUnsignedShort() const =0
virtual void setObjectBlank(std::string_view str)=0
virtual unsigned long valueAsUnsignedLong() const =0
virtual void setSubjectBlank(std::string_view str)=0
virtual void setPredicate(std::string_view predicate)=0
bool isOccasional() const
Definition: Triple.h:262
bool isObjectBlank() const
Definition: Triple.h:49
virtual int valueAsInt() const =0
virtual bool valueAsBoolean() const =0
void setXSDValue(std::string_view v, XSDType type)
Definition: Triple.cpp:32
MutableGenerator generator() override
std::vector< TriplePatternPtr > statements_
ConstGenerator cgenerator() const override
void push_back(const TriplePatternPtr &q)
std::vector< TriplePtr * > data_
auto objectOperator() const
groundable< Double > beginTerm_
void setEndTerm(const groundable< Double > &endTerm)
groundable< Double > endTerm_
VariablePtr objectVariable_
std::vector< VariablePtr > getVariables(bool includeObjectVar=true) const
static std::shared_ptr< Atom > getGraphTerm(const std::string_view &graphName)
auto & propertyTerm() const
Definition: TriplePattern.h:92
void setConfidenceTerm(const groundable< Double > &confidenceTerm)
void getTripleFrame(GraphSelector &frame) const
void setIsOccasionalTerm(const groundable< Numeric > &isOccasional)
void setBeginTerm(const groundable< Double > &beginTerm)
void setPerspectiveTerm(const groundable< Atom > &perspectiveTerm)
void setObjectOperator(FilterType objectOperator)
groundable< Atom > graphTerm_
bool filter(const Triple &triple) const
auto & subjectTerm() const
Definition: TriplePattern.h:81
bool instantiateInto(Triple &triple, const std::shared_ptr< const Bindings > &bindings=Bindings::emptyBindings()) const
void setGraphName(const std::string_view &graphName)
void setIsUncertainTerm(const groundable< Numeric > &isUncertain)
auto & isOccasionalTerm() const
auto & isUncertainTerm() const
auto & beginTerm() const
static std::shared_ptr< Predicate > getRDFPredicate(const PredicatePtr &predicate)
groundable< Numeric > isOccasional_
auto & objectTerm() const
Definition: TriplePattern.h:97
void setTripleFrame(const GraphSelector &frame)
groundable< Numeric > isUncertain_
uint32_t numVariables() const override
TriplePattern(const Triple &triple, bool isNegated=false)
groundable< Atom > perspectiveTerm_
auto & endTerm() const
groundable< Double > confidenceTerm_
auto & graphTerm() const
auto & perspectiveTerm() const
auto & confidenceTerm() const
PredicateRule & predicate()
Definition: formula.cpp:221
StringRule & atom()
Definition: strings.cpp:54
void createType< TriplePattern >()
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
TripleTemplate< std::string_view > TripleView
Definition: Triple.h:581
FirstOrderLiteralPtr applyBindings(const FirstOrderLiteralPtr &lit, const Bindings &bindings)
std::optional< double > confidence
Definition: GraphSelector.h:50
std::optional< double > end
Definition: GraphSelector.h:46
PerspectivePtr perspective
Definition: GraphSelector.h:30
std::optional< double > begin
Definition: GraphSelector.h:42