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

#include <ReifiedTriple.h>

Public Member Functions

 ReifiedTriple (const Triple &triple, const VocabularyPtr &vocabulary, const IRIAtomPtr &reifiedName=nullptr)
 
auto begin ()
 
auto end ()
 
auto begin () const
 
auto end () const
 
 ReifiedTriple (const Triple &triple, const VocabularyPtr &vocabulary, const IRIAtomPtr &reifiedName=nullptr)
 
auto begin ()
 
auto end ()
 
auto begin () const
 
auto end () const
 

Static Public Member Functions

static bool isPartOfReification (const Triple &triple)
 
static bool isReifiable (const Triple &triple)
 
static bool isPartOfReification (const Triple &triple)
 
static bool isReifiable (const Triple &triple)
 

Protected Member Functions

Triplecreate (std::string_view subject, const AtomPtr &property, const std::optional< std::string_view > &g)
 
Triplecreate (std::string_view subject, const AtomPtr &property, const std::optional< std::string_view > &g)
 

Protected Attributes

VocabularyPtr vocabulary_
 
std::vector< TriplePtrreified_
 
knowrob::IRIAtomPtr name_
 
std::string generatedString_
 

Detailed Description

A collection of triples that creates a reified view on another triple. Note that triple data is not copy, so caller should ensure that the original triple is not deleted while the reified view is used.

Definition at line 19 of file ReifiedTriple.h.

Constructor & Destructor Documentation

◆ ReifiedTriple() [1/2]

ReifiedTriple::ReifiedTriple ( const Triple triple,
const VocabularyPtr vocabulary,
const IRIAtomPtr reifiedName = nullptr 
)
explicit

Create a reified view on a triple.

Parameters
triplethe triple to reify.
vocabularythe vocabulary to use for reification.
reifiedNamethe name of the reified triple.

Definition at line 14 of file ReifiedTriple.cpp.

15  {
16  auto property = vocabulary->defineProperty(triple.predicate());
17  // map the property to a Relation concept
18  auto relationType = property->reification();
19  // generate a unique individual name
20  name_ = reifiedName ? reifiedName : semweb::Resource::unique_iri(
21  reification::individualPrefix->stringForm(),
22  semweb::Resource::iri_name(relationType->iri()));
23  const auto &name = name_->stringForm();
24  // set origin of the reified triples
25  auto g = triple.graph();
26 
27  // need to avoid copy of TriplePtr, so we reserve space in the vector to fit them exactly
28  uint32_t triple_count = 3;
29  if (triple.perspective()) triple_count += 1;
30  if (triple.isUncertain() || triple.confidence()) triple_count += 1;
31  if (triple.isOccasional()) triple_count += 1;
32  if (triple.confidence()) triple_count += 1;
33  if (triple.begin()) triple_count += 1;
34  if (triple.end()) triple_count += 1;
35  reified_.reserve(triple_count);
36 
37  // create a rdf:type assertion for the relation individual
38  create(name, rdf::type, g)->setObjectIRI(relationType->iri());
39 
40  // set the subject, and object of the reified triple
41  if (triple.isSubjectBlank()) {
43  } else {
45  }
46  if (triple.isObjectBlank()) {
48  } else if (triple.isObjectIRI()) {
50  } else if (triple.xsdType()) {
51  if (triple.xsdType().value() == XSDType::STRING) {
53  } else {
56  }
57  }
58 
59  // set the optional properties of the reified triple
60  if (triple.perspective()) {
61  create(name, reification::hasPerspective, g)->setObjectIRI(triple.perspective().value());
62  }
63  if (triple.isUncertain() || triple.confidence()) {
65  }
66  if (triple.isOccasional()) {
68  }
69  if (triple.confidence()) {
70  create(name, reification::hasConfidence, g)->setDoubleValue(triple.confidence().value());
71  }
72  if (triple.begin()) {
73  create(name, reification::hasBeginTime, g)->setDoubleValue(triple.begin().value());
74  }
75  if (triple.end()) {
76  create(name, reification::hasEndTime, g)->setDoubleValue(triple.end().value());
77  }
78 }
knowrob::IRIAtomPtr name_
Definition: ReifiedTriple.h:68
Triple * create(std::string_view subject, const AtomPtr &property, const std::optional< std::string_view > &g)
std::vector< TriplePtr > reified_
Definition: ReifiedTriple.h:67
std::string generatedString_
Definition: ReifiedTriple.h:69
virtual std::string_view valueAsString() const =0
auto xsdType() const
Definition: Triple.h:64
virtual std::optional< std::string_view > perspective() const =0
bool isUncertain() const
Definition: Triple.h:267
virtual void setDoubleValue(double v)=0
virtual std::optional< std::string_view > graph() const =0
auto end() const
Definition: Triple.h:277
virtual std::string_view subject() const =0
auto confidence() const
Definition: Triple.h:282
auto begin() const
Definition: Triple.h:272
bool isSubjectBlank() const
Definition: Triple.h:44
virtual std::string_view predicate() const =0
std::string createStringValue() const
Definition: Triple.cpp:71
virtual void setObjectIRI(std::string_view object)=0
bool isObjectIRI() const
Definition: Triple.h:54
virtual void setObjectBlank(std::string_view str)=0
bool isOccasional() const
Definition: Triple.h:262
bool isObjectBlank() const
Definition: Triple.h:49
virtual void setBooleanValue(bool v)=0
void setXSDValue(std::string_view v, XSDType type)
Definition: Triple.cpp:32
static std::string_view iri_name(std::string_view iri)
Definition: Resource.cpp:57
static IRIAtomPtr unique_iri(std::string_view ns, std::string_view name)
Definition: Resource.cpp:38
const IRIAtomPtr type
Definition: rdf.h:15
const IRIAtomPtr hasSubject
Definition: reification.h:15
const IRIAtomPtr isUncertain
Definition: reification.h:18
const IRIAtomPtr hasConfidence
Definition: reification.h:21
const AtomPtr individualPrefix
Definition: reification.h:13
const IRIAtomPtr isOccasional
Definition: reification.h:19
const IRIAtomPtr hasEndTime
Definition: reification.h:23
const IRIAtomPtr hasLiteral
Definition: reification.h:17
const IRIAtomPtr hasBeginTime
Definition: reification.h:22
const IRIAtomPtr hasPerspective
Definition: reification.h:20
const IRIAtomPtr hasObject
Definition: reification.h:16

◆ ReifiedTriple() [2/2]

knowrob::ReifiedTriple::ReifiedTriple ( const Triple triple,
const VocabularyPtr vocabulary,
const IRIAtomPtr reifiedName = nullptr 
)
explicit

Create a reified view on a triple.

Parameters
triplethe triple to reify.
vocabularythe vocabulary to use for reification.
reifiedNamethe name of the reified triple.

Member Function Documentation

◆ begin() [1/4]

auto knowrob::ReifiedTriple::begin ( )
inline
Returns
begin iterator over the reified triples.

Definition at line 33 of file ReifiedTriple.h.

33 { return reified_.begin(); }

◆ begin() [2/4]

auto knowrob::ReifiedTriple::begin ( )
inline
Returns
begin iterator over the reified triples.

Definition at line 33 of file ReifiedTriple.h.

33 { return reified_.begin(); }

◆ begin() [3/4]

auto knowrob::ReifiedTriple::begin ( ) const
inline
Returns
begin iterator over the reified triples.

Definition at line 43 of file ReifiedTriple.h.

43 { return reified_.begin(); }

◆ begin() [4/4]

auto knowrob::ReifiedTriple::begin ( ) const
inline
Returns
begin iterator over the reified triples.

Definition at line 43 of file ReifiedTriple.h.

43 { return reified_.begin(); }

◆ create() [1/2]

Triple * ReifiedTriple::create ( std::string_view  subject,
const AtomPtr property,
const std::optional< std::string_view > &  g 
)
protected

Definition at line 81 of file ReifiedTriple.cpp.

81  {
82  auto &reified = reified_.emplace_back(new TripleView());
83  reified->setSubject(subject);
84  reified->setPredicate(property->stringForm());
85  if (g.has_value()) {
86  reified->setGraph(g.value());
87  }
88  return reified.ptr;
89 }
TripleTemplate< std::string_view > TripleView
Definition: Triple.h:581

◆ create() [2/2]

Triple* knowrob::ReifiedTriple::create ( std::string_view  subject,
const AtomPtr property,
const std::optional< std::string_view > &  g 
)
protected

◆ end() [1/4]

auto knowrob::ReifiedTriple::end ( )
inline
Returns
end iterator over the reified triples.

Definition at line 38 of file ReifiedTriple.h.

38 { return reified_.end(); }

◆ end() [2/4]

auto knowrob::ReifiedTriple::end ( )
inline
Returns
end iterator over the reified triples.

Definition at line 38 of file ReifiedTriple.h.

38 { return reified_.end(); }

◆ end() [3/4]

auto knowrob::ReifiedTriple::end ( ) const
inline
Returns
end iterator over the reified triples.

Definition at line 48 of file ReifiedTriple.h.

48 { return reified_.end(); }

◆ end() [4/4]

auto knowrob::ReifiedTriple::end ( ) const
inline
Returns
end iterator over the reified triples.

Definition at line 48 of file ReifiedTriple.h.

48 { return reified_.end(); }

◆ isPartOfReification() [1/2]

bool ReifiedTriple::isPartOfReification ( const Triple triple)
static

Check if a triple belongs to the reified representation of another triple.

Parameters
triplethe triple to check.
Returns
true if the triple is part of a reification.

Definition at line 91 of file ReifiedTriple.cpp.

91  {
92  return triple.subject().compare(
93  0,
94  reification::individualPrefix->stringForm().size(),
95  reification::individualPrefix->stringForm()) == 0;
96 }

◆ isPartOfReification() [2/2]

static bool knowrob::ReifiedTriple::isPartOfReification ( const Triple triple)
static

Check if a triple belongs to the reified representation of another triple.

Parameters
triplethe triple to check.
Returns
true if the triple is part of a reification.

◆ isReifiable() [1/2]

bool ReifiedTriple::isReifiable ( const Triple triple)
static

Check if a triple is reifiable, i.e. if it is contextualized such that a reified representation is required in case a backend does not support contextualization of triples.

Parameters
triplethe triple to check.
Returns
true if the triple is reifiable.

Definition at line 98 of file ReifiedTriple.cpp.

98  {
99  bool hasNonEgoPerspective = triple.perspective() && !Perspective::isEgoPerspective(triple.perspective().value());
100  return hasNonEgoPerspective ||
101  triple.isUncertain() ||
102  triple.isOccasional() ||
103  triple.confidence() ||
104  triple.begin() ||
105  triple.end();
106 }
static bool isEgoPerspective(std::string_view iri)
Definition: Perspective.cpp:27

◆ isReifiable() [2/2]

static bool knowrob::ReifiedTriple::isReifiable ( const Triple triple)
static

Check if a triple is reifiable, i.e. if it is contextualized such that a reified representation is required in case a backend does not support contextualization of triples.

Parameters
triplethe triple to check.
Returns
true if the triple is reifiable.

Member Data Documentation

◆ generatedString_

std::string knowrob::ReifiedTriple::generatedString_
protected

Definition at line 69 of file ReifiedTriple.h.

◆ name_

knowrob::IRIAtomPtr knowrob::ReifiedTriple::name_
protected

Definition at line 68 of file ReifiedTriple.h.

◆ reified_

std::vector< TriplePtr > knowrob::ReifiedTriple::reified_
protected

Definition at line 67 of file ReifiedTriple.h.

◆ vocabulary_

VocabularyPtr knowrob::ReifiedTriple::vocabulary_
protected

Definition at line 66 of file ReifiedTriple.h.


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