knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::TriplePattern Class Reference

#include <TriplePattern.h>

Inheritance diagram for knowrob::TriplePattern:
Collaboration diagram for knowrob::TriplePattern:

Public Member Functions

 TriplePattern (const Triple &triple, bool isNegated=false)
 
 TriplePattern (const PredicatePtr &predicate, bool isNegated=false)
 
 TriplePattern (const TermPtr &s, const TermPtr &p, const TermPtr &o, bool isNegated=false)
 
void setTripleFrame (const GraphSelector &frame)
 
void getTripleFrame (GraphSelector &frame) const
 
auto & subjectTerm () const
 
void setSubjectTerm (const TermPtr &subjectTerm)
 
auto & propertyTerm () const
 
auto & objectTerm () const
 
void setObjectTerm (const TermPtr &objectTerm)
 
auto & objectVariable () const
 
void setObjectVariable (const VariablePtr &objectVariable)
 
auto & graphTerm () const
 
void setGraphTerm (const groundable< Atom > &graphTerm)
 
void setGraphName (const std::string_view &graphName)
 
auto & perspectiveTerm () const
 
void setPerspectiveTerm (const groundable< Atom > &perspectiveTerm)
 
auto & beginTerm () const
 
void setBeginTerm (const groundable< Double > &beginTerm)
 
auto & endTerm () const
 
void setEndTerm (const groundable< Double > &endTerm)
 
auto & confidenceTerm () const
 
void setConfidenceTerm (const groundable< Double > &confidenceTerm)
 
auto objectOperator () const
 
void setObjectOperator (FilterType objectOperator)
 
auto & isOccasionalTerm () const
 
void setIsOccasionalTerm (const groundable< Numeric > &isOccasional)
 
auto & isUncertainTerm () const
 
void setIsUncertainTerm (const groundable< Numeric > &isUncertain)
 
bool isOptional () const
 
void setIsOptional (bool isOptional)
 
uint32_t numVariables () const override
 
std::vector< VariablePtrgetVariables (bool includeObjectVar=true) const
 
bool filter (const Triple &triple) const
 
bool instantiateInto (Triple &triple, const std::shared_ptr< const Bindings > &bindings=Bindings::emptyBindings()) const
 
 TriplePattern (const Triple &triple, bool isNegated=false)
 
 TriplePattern (const PredicatePtr &predicate, bool isNegated=false)
 
 TriplePattern (const TermPtr &s, const TermPtr &p, const TermPtr &o, bool isNegated=false)
 
void setTripleFrame (const GraphSelector &frame)
 
void getTripleFrame (GraphSelector &frame) const
 
auto & subjectTerm () const
 
void setSubjectTerm (const TermPtr &subjectTerm)
 
auto & propertyTerm () const
 
auto & objectTerm () const
 
void setObjectTerm (const TermPtr &objectTerm)
 
auto & objectVariable () const
 
void setObjectVariable (const VariablePtr &objectVariable)
 
auto & graphTerm () const
 
void setGraphTerm (const groundable< Atom > &graphTerm)
 
void setGraphName (const std::string_view &graphName)
 
auto & perspectiveTerm () const
 
void setPerspectiveTerm (const groundable< Atom > &perspectiveTerm)
 
auto & beginTerm () const
 
void setBeginTerm (const groundable< Double > &beginTerm)
 
auto & endTerm () const
 
void setEndTerm (const groundable< Double > &endTerm)
 
auto & confidenceTerm () const
 
void setConfidenceTerm (const groundable< Double > &confidenceTerm)
 
auto objectOperator () const
 
void setObjectOperator (FilterType objectOperator)
 
auto & isOccasionalTerm () const
 
void setIsOccasionalTerm (const groundable< Numeric > &isOccasional)
 
auto & isUncertainTerm () const
 
void setIsUncertainTerm (const groundable< Numeric > &isUncertain)
 
bool isOptional () const
 
void setIsOptional (bool isOptional)
 
uint32_t numVariables () const override
 
std::vector< VariablePtrgetVariables (bool includeObjectVar=true) const
 
bool filter (const Triple &triple) const
 
bool instantiateInto (Triple &triple, const std::shared_ptr< const Bindings > &bindings=Bindings::emptyBindings()) const
 
- Public Member Functions inherited from knowrob::FirstOrderLiteral
 FirstOrderLiteral (const PredicatePtr &predicate, bool isNegative)
 
const auto & predicate () const
 
auto isNegated () const
 
void setIsNegated (bool isNegated)
 
auto & functor () const
 
auto arity () const
 
void write (std::ostream &os) const override
 
 FirstOrderLiteral (const PredicatePtr &predicate, bool isNegative)
 
const auto & predicate () const
 
auto isNegated () const
 
void setIsNegated (bool isNegated)
 
auto & functor () const
 
auto arity () const
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Static Public Member Functions

static std::shared_ptr< PredicategetRDFPredicate (const PredicatePtr &predicate)
 
static std::shared_ptr< PredicategetRDFPredicate (const PredicatePtr &predicate)
 

Static Protected Member Functions

static std::shared_ptr< AtomgetGraphTerm (const std::string_view &graphName)
 
static std::shared_ptr< PredicategetRDFPredicate (const TermPtr &s, const TermPtr &p, const TermPtr &o)
 
static std::shared_ptr< PredicategetRDFPredicate (const Triple &data)
 
static std::shared_ptr< AtomgetGraphTerm (const std::string_view &graphName)
 
static std::shared_ptr< PredicategetRDFPredicate (const TermPtr &s, const TermPtr &p, const TermPtr &o)
 
static std::shared_ptr< PredicategetRDFPredicate (const Triple &data)
 

Protected Attributes

TermPtr subjectTerm_
 
TermPtr propertyTerm_
 
TermPtr objectTerm_
 
VariablePtr objectVariable_
 
FilterType objectOperator_
 
bool isOptional_
 
groundable< AtomgraphTerm_
 
groundable< AtomperspectiveTerm_
 
groundable< DoublebeginTerm_
 
groundable< DoubleendTerm_
 
groundable< DoubleconfidenceTerm_
 
groundable< NumericisOccasional_
 
groundable< NumericisUncertain_
 
- Protected Attributes inherited from knowrob::FirstOrderLiteral
const PredicatePtr predicate_
 
bool isNegated_
 

Detailed Description

A triple expression where subject, predicate and object are represented as a term, and an additional unary operator can be applied to the object.

Definition at line 43 of file TriplePattern.h.

Constructor & Destructor Documentation

◆ TriplePattern() [1/6]

TriplePattern::TriplePattern ( const Triple triple,
bool  isNegated = false 
)
explicit

Copy char data of StatementData object into Term data structures.

Parameters
triplea triple.
isNegateda value of true refers to the statement being false.

Definition at line 39 of file TriplePattern.cpp.

41  subjectTerm_(predicate_->arguments()[0]),
42  propertyTerm_(predicate_->arguments()[1]),
43  objectTerm_(predicate_->arguments()[2]),
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 }
FirstOrderLiteral(const PredicatePtr &predicate, bool isNegative)
const PredicatePtr predicate_
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
Definition: IRIAtom.cpp:25
static std::shared_ptr< Numeric > trueAtom()
Definition: Numeric.cpp:15
virtual std::optional< std::string_view > perspective() const =0
bool isUncertain() const
Definition: Triple.h:267
virtual std::optional< std::string_view > graph() const =0
auto end() const
Definition: Triple.h:277
auto confidence() const
Definition: Triple.h:282
auto begin() const
Definition: Triple.h:272
bool isOccasional() const
Definition: Triple.h:262
groundable< Double > beginTerm_
groundable< Double > endTerm_
static std::shared_ptr< Atom > getGraphTerm(const std::string_view &graphName)
groundable< Atom > graphTerm_
static std::shared_ptr< Predicate > getRDFPredicate(const PredicatePtr &predicate)
groundable< Numeric > isOccasional_
groundable< Numeric > isUncertain_
groundable< Atom > perspectiveTerm_
groundable< Double > confidenceTerm_

◆ TriplePattern() [2/6]

TriplePattern::TriplePattern ( const PredicatePtr predicate,
bool  isNegated = false 
)
explicit
Parameters
predicatea predicate with two arguments.
isNegateda value of true refers to the statement being false.

Definition at line 69 of file TriplePattern.cpp.

71  subjectTerm_(predicate_->arguments()[0]),
72  propertyTerm_(predicate_->arguments()[1]),
73  objectTerm_(predicate_->arguments()[2]),
75  isOptional_(false) {
76 }

◆ TriplePattern() [3/6]

TriplePattern::TriplePattern ( const TermPtr s,
const TermPtr p,
const TermPtr o,
bool  isNegated = false 
)
Parameters
sthe subject term.
pthe property term.
othe object term.
isNegateda value of true refers to the statement being false.

Definition at line 78 of file TriplePattern.cpp.

80  subjectTerm_(s),
81  propertyTerm_(p),
82  objectTerm_(o),
84  isOptional_(false) {
85 }

◆ TriplePattern() [4/6]

knowrob::TriplePattern::TriplePattern ( const Triple triple,
bool  isNegated = false 
)
explicit

Copy char data of StatementData object into Term data structures.

Parameters
triplea triple.
isNegateda value of true refers to the statement being false.

◆ TriplePattern() [5/6]

knowrob::TriplePattern::TriplePattern ( const PredicatePtr predicate,
bool  isNegated = false 
)
explicit
Parameters
predicatea predicate with two arguments.
isNegateda value of true refers to the statement being false.

◆ TriplePattern() [6/6]

knowrob::TriplePattern::TriplePattern ( const TermPtr s,
const TermPtr p,
const TermPtr o,
bool  isNegated = false 
)
Parameters
sthe subject term.
pthe property term.
othe object term.
isNegateda value of true refers to the statement being false.

Member Function Documentation

◆ beginTerm() [1/2]

auto& knowrob::TriplePattern::beginTerm ( ) const
inline
Returns
the begin term of this expression.

Definition at line 147 of file TriplePattern.h.

147 { return beginTerm_; }

◆ beginTerm() [2/2]

auto& knowrob::TriplePattern::beginTerm ( ) const
inline
Returns
the begin term of this expression.

Definition at line 147 of file TriplePattern.h.

147 { return beginTerm_; }

◆ confidenceTerm() [1/2]

auto& knowrob::TriplePattern::confidenceTerm ( ) const
inline
Returns
the confidence term of this expression.

Definition at line 169 of file TriplePattern.h.

169 { return confidenceTerm_; }

◆ confidenceTerm() [2/2]

auto& knowrob::TriplePattern::confidenceTerm ( ) const
inline
Returns
the confidence term of this expression.

Definition at line 169 of file TriplePattern.h.

169 { return confidenceTerm_; }

◆ endTerm() [1/2]

auto& knowrob::TriplePattern::endTerm ( ) const
inline
Returns
the end term of this expression.

Definition at line 158 of file TriplePattern.h.

158 { return endTerm_; }

◆ endTerm() [2/2]

auto& knowrob::TriplePattern::endTerm ( ) const
inline
Returns
the end term of this expression.

Definition at line 158 of file TriplePattern.h.

158 { return endTerm_; }

◆ filter() [1/2]

bool TriplePattern::filter ( const Triple triple) const
Parameters
triplea triple query.
Returns
true if the triple matches this pattern.

Definition at line 247 of file TriplePattern.cpp.

247  {
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 }
bool filterNumeric(const NumType &a, const NumType &b, FilterType op)
virtual std::string_view valueAsString() const =0
auto xsdType() const
Definition: Triple.h:64
virtual short valueAsShort() const =0
virtual unsigned int valueAsUnsignedInt() const =0
virtual double valueAsDouble() const =0
virtual float valueAsFloat() const =0
virtual long valueAsLong() const =0
bool isObjectIRI() const
Definition: Triple.h:54
virtual unsigned short valueAsUnsignedShort() const =0
virtual unsigned long valueAsUnsignedLong() const =0
bool isObjectBlank() const
Definition: Triple.h:49
virtual int valueAsInt() const =0
virtual bool valueAsBoolean() const =0
auto objectOperator() const
auto & objectTerm() const
Definition: TriplePattern.h:97

◆ filter() [2/2]

bool knowrob::TriplePattern::filter ( const Triple triple) const
Parameters
triplea triple query.
Returns
true if the triple matches this pattern.

◆ getGraphTerm() [1/2]

std::shared_ptr< Atom > TriplePattern::getGraphTerm ( const std::string_view &  graphName)
staticprotected

Definition at line 135 of file TriplePattern.cpp.

135  {
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 }
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
Definition: Atom.cpp:40
auto & graphTerm() const

◆ getGraphTerm() [2/2]

static std::shared_ptr<Atom> knowrob::TriplePattern::getGraphTerm ( const std::string_view &  graphName)
staticprotected

◆ getRDFPredicate() [1/6]

std::shared_ptr< Predicate > TriplePattern::getRDFPredicate ( const PredicatePtr predicate)
static

Definition at line 154 of file TriplePattern.cpp.

154  {
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 }
const auto & predicate() const

◆ getRDFPredicate() [2/6]

static std::shared_ptr<Predicate> knowrob::TriplePattern::getRDFPredicate ( const PredicatePtr predicate)
static

◆ getRDFPredicate() [3/6]

std::shared_ptr< Predicate > TriplePattern::getRDFPredicate ( const TermPtr s,
const TermPtr p,
const TermPtr o 
)
staticprotected

Definition at line 150 of file TriplePattern.cpp.

150  {
151  return std::make_shared<Predicate>("triple", std::vector<TermPtr>({s, p, o}));
152 }

◆ getRDFPredicate() [4/6]

static std::shared_ptr<Predicate> knowrob::TriplePattern::getRDFPredicate ( const TermPtr s,
const TermPtr p,
const TermPtr o 
)
staticprotected

◆ getRDFPredicate() [5/6]

std::shared_ptr< Predicate > TriplePattern::getRDFPredicate ( const Triple data)
staticprotected

Definition at line 166 of file TriplePattern.cpp.

166  {
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 }
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
virtual std::string_view subject() const =0
bool isSubjectBlank() const
Definition: Triple.h:44
virtual std::string_view predicate() const =0
std::shared_ptr< Term > TermPtr
Definition: Term.h:117

◆ getRDFPredicate() [6/6]

static std::shared_ptr<Predicate> knowrob::TriplePattern::getRDFPredicate ( const Triple data)
staticprotected

◆ getTripleFrame() [1/2]

void TriplePattern::getTripleFrame ( GraphSelector frame) const

Apply this pattern to a frame.

Parameters
framea triple frame.

Definition at line 111 of file TriplePattern.cpp.

111  {
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 }
static std::shared_ptr< Perspective > get(std::string_view iri)
Definition: Perspective.cpp:31
auto & isOccasionalTerm() const
auto & isUncertainTerm() const
auto & beginTerm() const
auto & endTerm() const
auto & perspectiveTerm() const
auto & confidenceTerm() const
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

◆ getTripleFrame() [2/2]

void knowrob::TriplePattern::getTripleFrame ( GraphSelector frame) const

Apply this pattern to a frame.

Parameters
framea triple frame.

◆ getVariables() [1/2]

std::vector< VariablePtr > TriplePattern::getVariables ( bool  includeObjectVar = true) const
Returns
the variables in this expression.

Definition at line 182 of file TriplePattern.cpp.

182  {
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 }
VariablePtr objectVariable_

◆ getVariables() [2/2]

std::vector<VariablePtr> knowrob::TriplePattern::getVariables ( bool  includeObjectVar = true) const
Returns
the variables in this expression.

◆ graphTerm() [1/2]

auto& knowrob::TriplePattern::graphTerm ( ) const
inline
Returns
the graph term of this expression.

Definition at line 119 of file TriplePattern.h.

119 { return graphTerm_; }

◆ graphTerm() [2/2]

auto& knowrob::TriplePattern::graphTerm ( ) const
inline
Returns
the graph term of this expression.

Definition at line 119 of file TriplePattern.h.

119 { return graphTerm_; }

◆ instantiateInto() [1/2]

bool TriplePattern::instantiateInto ( Triple triple,
const std::shared_ptr< const Bindings > &  bindings = Bindings::emptyBindings() 
) const

Map the instantiation of this expression into a triple.

Parameters
triplethe triple to be instantiated.
bindingsthe substitution to be applied.
Returns
true if the instantiation was successful.

Definition at line 286 of file TriplePattern.cpp.

286  {
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 }
virtual void setSubject(std::string_view subject)=0
virtual void setGraph(std::string_view graph)=0
virtual void setStringValue(std::string_view v)=0
void setConfidence(double confidence)
Definition: Triple.h:307
virtual void setPerspective(std::string_view perspective)=0
void setIsUncertain(bool isUncertain)
Definition: Triple.h:292
void setIsOccasional(bool isOccasional)
Definition: Triple.h:287
void setBegin(double begin)
Definition: Triple.h:297
void setEnd(double end)
Definition: Triple.h:302
virtual void setObjectIRI(std::string_view object)=0
virtual void setObjectBlank(std::string_view str)=0
virtual void setSubjectBlank(std::string_view str)=0
virtual void setPredicate(std::string_view predicate)=0
void setXSDValue(std::string_view v, XSDType type)
Definition: Triple.cpp:32
StringRule & atom()
Definition: strings.cpp:54

◆ instantiateInto() [2/2]

bool knowrob::TriplePattern::instantiateInto ( Triple triple,
const std::shared_ptr< const Bindings > &  bindings = Bindings::emptyBindings() 
) const

Map the instantiation of this expression into a triple.

Parameters
triplethe triple to be instantiated.
bindingsthe substitution to be applied.
Returns
true if the instantiation was successful.

◆ isOccasionalTerm() [1/2]

auto& knowrob::TriplePattern::isOccasionalTerm ( ) const
inline
Returns
the isOccasional term of this expression.

Definition at line 191 of file TriplePattern.h.

191 { return isOccasional_; }

◆ isOccasionalTerm() [2/2]

auto& knowrob::TriplePattern::isOccasionalTerm ( ) const
inline
Returns
the isOccasional term of this expression.

Definition at line 191 of file TriplePattern.h.

191 { return isOccasional_; }

◆ isOptional() [1/2]

bool knowrob::TriplePattern::isOptional ( ) const
inline
Returns
true if this expression is optional.

Definition at line 213 of file TriplePattern.h.

213 { return isOptional_; }

◆ isOptional() [2/2]

bool knowrob::TriplePattern::isOptional ( ) const
inline
Returns
true if this expression is optional.

Definition at line 213 of file TriplePattern.h.

213 { return isOptional_; }

◆ isUncertainTerm() [1/2]

auto& knowrob::TriplePattern::isUncertainTerm ( ) const
inline
Returns
the isUncertain term of this expression.

Definition at line 202 of file TriplePattern.h.

202 { return isUncertain_; }

◆ isUncertainTerm() [2/2]

auto& knowrob::TriplePattern::isUncertainTerm ( ) const
inline
Returns
the isUncertain term of this expression.

Definition at line 202 of file TriplePattern.h.

202 { return isUncertain_; }

◆ numVariables() [1/2]

uint32_t TriplePattern::numVariables ( ) const
overridevirtual
Returns
the number of variables in this expression.

Reimplemented from knowrob::FirstOrderLiteral.

Definition at line 202 of file TriplePattern.cpp.

202  {
203  return getVariables(false).size();
204 }
std::vector< VariablePtr > getVariables(bool includeObjectVar=true) const

◆ numVariables() [2/2]

uint32_t knowrob::TriplePattern::numVariables ( ) const
overridevirtual
Returns
the number of variables in this expression.

Reimplemented from knowrob::FirstOrderLiteral.

◆ objectOperator() [1/2]

auto knowrob::TriplePattern::objectOperator ( ) const
inline
Returns
the operator for the object of the triple.

Definition at line 180 of file TriplePattern.h.

180 { return objectOperator_; }

◆ objectOperator() [2/2]

auto knowrob::TriplePattern::objectOperator ( ) const
inline
Returns
the operator for the object of the triple.

Definition at line 180 of file TriplePattern.h.

180 { return objectOperator_; }

◆ objectTerm() [1/2]

auto& knowrob::TriplePattern::objectTerm ( ) const
inline
Returns
the object term of this expression.

Definition at line 97 of file TriplePattern.h.

97 { return objectTerm_; }

◆ objectTerm() [2/2]

auto& knowrob::TriplePattern::objectTerm ( ) const
inline
Returns
the object term of this expression.

Definition at line 97 of file TriplePattern.h.

97 { return objectTerm_; }

◆ objectVariable() [1/2]

auto& knowrob::TriplePattern::objectVariable ( ) const
inline
Returns
an additional object variable to bind the actual value of the object term.

Definition at line 108 of file TriplePattern.h.

108 { return objectVariable_; }

◆ objectVariable() [2/2]

auto& knowrob::TriplePattern::objectVariable ( ) const
inline
Returns
an additional object variable to bind the actual value of the object term.

Definition at line 108 of file TriplePattern.h.

108 { return objectVariable_; }

◆ perspectiveTerm() [1/2]

auto& knowrob::TriplePattern::perspectiveTerm ( ) const
inline
Returns
the agent term of this expression.

Definition at line 136 of file TriplePattern.h.

136 { return perspectiveTerm_; }

◆ perspectiveTerm() [2/2]

auto& knowrob::TriplePattern::perspectiveTerm ( ) const
inline
Returns
the agent term of this expression.

Definition at line 136 of file TriplePattern.h.

136 { return perspectiveTerm_; }

◆ propertyTerm() [1/2]

auto& knowrob::TriplePattern::propertyTerm ( ) const
inline
Returns
the property term of this expression.

Definition at line 92 of file TriplePattern.h.

92 { return propertyTerm_; }

◆ propertyTerm() [2/2]

auto& knowrob::TriplePattern::propertyTerm ( ) const
inline
Returns
the property term of this expression.

Definition at line 92 of file TriplePattern.h.

92 { return propertyTerm_; }

◆ setBeginTerm() [1/2]

void knowrob::TriplePattern::setBeginTerm ( const groundable< Double > &  beginTerm)
inline

Set the begin term of this expression.

Parameters
beginTermthe begin term.

Definition at line 153 of file TriplePattern.h.

153 { beginTerm_ = beginTerm; }

◆ setBeginTerm() [2/2]

void knowrob::TriplePattern::setBeginTerm ( const groundable< Double > &  beginTerm)
inline

Set the begin term of this expression.

Parameters
beginTermthe begin term.

Definition at line 153 of file TriplePattern.h.

153 { beginTerm_ = beginTerm; }

◆ setConfidenceTerm() [1/2]

void knowrob::TriplePattern::setConfidenceTerm ( const groundable< Double > &  confidenceTerm)
inline

Set the confidence term of this expression.

Parameters
confidenceTermthe confidence term.

Definition at line 175 of file TriplePattern.h.

◆ setConfidenceTerm() [2/2]

void knowrob::TriplePattern::setConfidenceTerm ( const groundable< Double > &  confidenceTerm)
inline

Set the confidence term of this expression.

Parameters
confidenceTermthe confidence term.

Definition at line 175 of file TriplePattern.h.

◆ setEndTerm() [1/2]

void knowrob::TriplePattern::setEndTerm ( const groundable< Double > &  endTerm)
inline

Set the end term of this expression.

Parameters
endTermthe end term.

Definition at line 164 of file TriplePattern.h.

164 { endTerm_ = endTerm; }

◆ setEndTerm() [2/2]

void knowrob::TriplePattern::setEndTerm ( const groundable< Double > &  endTerm)
inline

Set the end term of this expression.

Parameters
endTermthe end term.

Definition at line 164 of file TriplePattern.h.

164 { endTerm_ = endTerm; }

◆ setGraphName() [1/2]

void knowrob::TriplePattern::setGraphName ( const std::string_view &  graphName)
inline

Set the graph term of this expression.

Parameters
graphNamethe name of the graph.

Definition at line 131 of file TriplePattern.h.

131 { graphTerm_ = getGraphTerm(graphName); }

◆ setGraphName() [2/2]

void knowrob::TriplePattern::setGraphName ( const std::string_view &  graphName)
inline

Set the graph term of this expression.

Parameters
graphNamethe name of the graph.

Definition at line 131 of file TriplePattern.h.

131 { graphTerm_ = getGraphTerm(graphName); }

◆ setGraphTerm() [1/2]

void knowrob::TriplePattern::setGraphTerm ( const groundable< Atom > &  graphTerm)
inline

Set the graph term of this expression.

Parameters
graphTermthe graph term.

Definition at line 125 of file TriplePattern.h.

125 { graphTerm_ = graphTerm; }

◆ setGraphTerm() [2/2]

void knowrob::TriplePattern::setGraphTerm ( const groundable< Atom > &  graphTerm)
inline

Set the graph term of this expression.

Parameters
graphTermthe graph term.

Definition at line 125 of file TriplePattern.h.

125 { graphTerm_ = graphTerm; }

◆ setIsOccasionalTerm() [1/2]

void knowrob::TriplePattern::setIsOccasionalTerm ( const groundable< Numeric > &  isOccasional)
inline

Set the isOccasional term of this expression.

Parameters
isOccasionalthe isOccasional term.

Definition at line 197 of file TriplePattern.h.

const IRIAtomPtr isOccasional
Definition: reification.h:19

◆ setIsOccasionalTerm() [2/2]

void knowrob::TriplePattern::setIsOccasionalTerm ( const groundable< Numeric > &  isOccasional)
inline

Set the isOccasional term of this expression.

Parameters
isOccasionalthe isOccasional term.

Definition at line 197 of file TriplePattern.h.

◆ setIsOptional() [1/2]

void knowrob::TriplePattern::setIsOptional ( bool  isOptional)
inline

Set this expression to be optional.

Parameters
isOptionaltrue if this expression is optional.

Definition at line 219 of file TriplePattern.h.

219 { isOptional_ = isOptional; }

◆ setIsOptional() [2/2]

void knowrob::TriplePattern::setIsOptional ( bool  isOptional)
inline

Set this expression to be optional.

Parameters
isOptionaltrue if this expression is optional.

Definition at line 219 of file TriplePattern.h.

219 { isOptional_ = isOptional; }

◆ setIsUncertainTerm() [1/2]

void knowrob::TriplePattern::setIsUncertainTerm ( const groundable< Numeric > &  isUncertain)
inline

Set the isUncertain term of this expression.

Parameters
isUncertainthe isUncertain term.

Definition at line 208 of file TriplePattern.h.

const IRIAtomPtr isUncertain
Definition: reification.h:18

◆ setIsUncertainTerm() [2/2]

void knowrob::TriplePattern::setIsUncertainTerm ( const groundable< Numeric > &  isUncertain)
inline

Set the isUncertain term of this expression.

Parameters
isUncertainthe isUncertain term.

Definition at line 208 of file TriplePattern.h.

◆ setObjectOperator() [1/2]

void knowrob::TriplePattern::setObjectOperator ( FilterType  objectOperator)
inline

Set the operator for the object of the triple.

Parameters
objectOperatorthe operator.

Definition at line 186 of file TriplePattern.h.

◆ setObjectOperator() [2/2]

void knowrob::TriplePattern::setObjectOperator ( FilterType  objectOperator)
inline

Set the operator for the object of the triple.

Parameters
objectOperatorthe operator.

Definition at line 186 of file TriplePattern.h.

◆ setObjectTerm() [1/2]

void knowrob::TriplePattern::setObjectTerm ( const TermPtr objectTerm)
inline

Set the object term of this expression.

Parameters
objectTermthe object term.

Definition at line 103 of file TriplePattern.h.

103 { objectTerm_ = objectTerm; }

◆ setObjectTerm() [2/2]

void knowrob::TriplePattern::setObjectTerm ( const TermPtr objectTerm)
inline

Set the object term of this expression.

Parameters
objectTermthe object term.

Definition at line 103 of file TriplePattern.h.

103 { objectTerm_ = objectTerm; }

◆ setObjectVariable() [1/2]

void knowrob::TriplePattern::setObjectVariable ( const VariablePtr objectVariable)
inline

Set the object variable of this expression.

Parameters
objectVariablethe object variable.

Definition at line 114 of file TriplePattern.h.

◆ setObjectVariable() [2/2]

void knowrob::TriplePattern::setObjectVariable ( const VariablePtr objectVariable)
inline

Set the object variable of this expression.

Parameters
objectVariablethe object variable.

Definition at line 114 of file TriplePattern.h.

◆ setPerspectiveTerm() [1/2]

void knowrob::TriplePattern::setPerspectiveTerm ( const groundable< Atom > &  perspectiveTerm)
inline

Set the agent term of this expression.

Parameters
perspectiveTermthe perspective term.

Definition at line 142 of file TriplePattern.h.

◆ setPerspectiveTerm() [2/2]

void knowrob::TriplePattern::setPerspectiveTerm ( const groundable< Atom > &  perspectiveTerm)
inline

Set the agent term of this expression.

Parameters
perspectiveTermthe perspective term.

Definition at line 142 of file TriplePattern.h.

◆ setSubjectTerm() [1/2]

void knowrob::TriplePattern::setSubjectTerm ( const TermPtr subjectTerm)
inline

Set the subject term of this expression.

Parameters
subjectTermthe subject term.

Definition at line 87 of file TriplePattern.h.

auto & subjectTerm() const
Definition: TriplePattern.h:81

◆ setSubjectTerm() [2/2]

void knowrob::TriplePattern::setSubjectTerm ( const TermPtr subjectTerm)
inline

Set the subject term of this expression.

Parameters
subjectTermthe subject term.

Definition at line 87 of file TriplePattern.h.

◆ setTripleFrame() [1/2]

void TriplePattern::setTripleFrame ( const GraphSelector frame)

Apply a frame to this pattern.

Parameters
framea triple frame.

Definition at line 87 of file TriplePattern.cpp.

87  {
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 }

◆ setTripleFrame() [2/2]

void knowrob::TriplePattern::setTripleFrame ( const GraphSelector frame)

Apply a frame to this pattern.

Parameters
framea triple frame.

◆ subjectTerm() [1/2]

auto& knowrob::TriplePattern::subjectTerm ( ) const
inline
Returns
the subject term of this expression.

Definition at line 81 of file TriplePattern.h.

81 { return subjectTerm_; }

◆ subjectTerm() [2/2]

auto& knowrob::TriplePattern::subjectTerm ( ) const
inline
Returns
the subject term of this expression.

Definition at line 81 of file TriplePattern.h.

81 { return subjectTerm_; }

Member Data Documentation

◆ beginTerm_

groundable< Double > knowrob::TriplePattern::beginTerm_
protected

Definition at line 259 of file TriplePattern.h.

◆ confidenceTerm_

groundable< Double > knowrob::TriplePattern::confidenceTerm_
protected

Definition at line 261 of file TriplePattern.h.

◆ endTerm_

groundable< Double > knowrob::TriplePattern::endTerm_
protected

Definition at line 260 of file TriplePattern.h.

◆ graphTerm_

groundable< Atom > knowrob::TriplePattern::graphTerm_
protected

Definition at line 257 of file TriplePattern.h.

◆ isOccasional_

groundable< Numeric > knowrob::TriplePattern::isOccasional_
protected

Definition at line 262 of file TriplePattern.h.

◆ isOptional_

bool knowrob::TriplePattern::isOptional_
protected

Definition at line 254 of file TriplePattern.h.

◆ isUncertain_

groundable< Numeric > knowrob::TriplePattern::isUncertain_
protected

Definition at line 263 of file TriplePattern.h.

◆ objectOperator_

FilterType knowrob::TriplePattern::objectOperator_
protected

Definition at line 253 of file TriplePattern.h.

◆ objectTerm_

TermPtr knowrob::TriplePattern::objectTerm_
protected

Definition at line 251 of file TriplePattern.h.

◆ objectVariable_

VariablePtr knowrob::TriplePattern::objectVariable_
protected

Definition at line 252 of file TriplePattern.h.

◆ perspectiveTerm_

groundable< Atom > knowrob::TriplePattern::perspectiveTerm_
protected

Definition at line 258 of file TriplePattern.h.

◆ propertyTerm_

TermPtr knowrob::TriplePattern::propertyTerm_
protected

Definition at line 250 of file TriplePattern.h.

◆ subjectTerm_

TermPtr knowrob::TriplePattern::subjectTerm_
protected

Definition at line 249 of file TriplePattern.h.


The documentation for this class was generated from the following files: