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

#include <Property.h>

Inheritance diagram for knowrob::semweb::Property:
Collaboration diagram for knowrob::semweb::Property:

Classes

struct  PropertyComparator
 

Public Member Functions

 Property (std::string_view iri)
 
 Property (const IRIAtomPtr &iri)
 
void addDirectParent (const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
 
void removeDirectParent (const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
 
const auto & directParents () const
 
void setInverse (const std::shared_ptr< Property > &inverse)
 
const auto & inverse () const
 
bool hasFlag (PropertyFlag flag) const
 
void setFlag (PropertyFlag flag)
 
bool isDatatypeProperty () const
 
bool isAnnotationProperty () const
 
bool isObjectProperty () const
 
bool isTransitiveProperty () const
 
bool isReflexiveProperty () const
 
bool isSymmetricProperty () const
 
bool isSubPropertyOf (const std::shared_ptr< Property > &parent, bool includeSelf=true)
 
void forallParents (const PropertyVisitor &visitor, bool includeSelf=true, bool skipDuplicates=true)
 
void forallChildren (const PropertyTupleVisitor &visitor, bool skipDuplicates=true)
 
auto reification () const
 
void detach ()
 
 Property (std::string_view iri)
 
 Property (const IRIAtomPtr &iri)
 
void addDirectParent (const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
 
void removeDirectParent (const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
 
const auto & directParents () const
 
void setInverse (const std::shared_ptr< Property > &inverse)
 
const auto & inverse () const
 
bool hasFlag (PropertyFlag flag) const
 
void setFlag (PropertyFlag flag)
 
bool isDatatypeProperty () const
 
bool isAnnotationProperty () const
 
bool isObjectProperty () const
 
bool isTransitiveProperty () const
 
bool isReflexiveProperty () const
 
bool isSymmetricProperty () const
 
bool isSubPropertyOf (const std::shared_ptr< Property > &parent, bool includeSelf=true)
 
void forallParents (const PropertyVisitor &visitor, bool includeSelf=true, bool skipDuplicates=true)
 
void forallChildren (const PropertyTupleVisitor &visitor, bool skipDuplicates=true)
 
auto reification () const
 
void detach ()
 
- Public Member Functions inherited from knowrob::semweb::Resource
 Resource (std::string_view iri)
 
 Resource (const IRIAtomPtr &iri)
 
auto iri () const
 
auto iriAtom () const
 
std::string_view name () const
 
std::string_view ns (bool includeDelimiter=false) const
 
 Resource (std::string_view iri)
 
 Resource (const IRIAtomPtr &iri)
 
auto iri () const
 
auto iriAtom () const
 
std::string_view name () const
 
std::string_view ns (bool includeDelimiter=false) const
 

Static Public Member Functions

static knowrob::IRIAtomPtr reifiedIRI (std::string_view iri)
 
static knowrob::IRIAtomPtr unReifiedIRI (std::string_view iri)
 
static knowrob::IRIAtomPtr reifiedIRI (std::string_view iri)
 
static knowrob::IRIAtomPtr unReifiedIRI (std::string_view iri)
 
- Static Public Member Functions inherited from knowrob::semweb::Resource
static IRIAtomPtr unique_iri (std::string_view ns, std::string_view name)
 
static IRIAtomPtr unique_iri (std::string_view type_iri)
 
static std::string_view iri_name (std::string_view iri)
 
static std::string_view iri_ns (std::string_view iri, bool includeDelimiter=false)
 
static AtomPtr graph_atom (std::optional< std::string_view > graph)
 
static IRIAtomPtr unique_iri (std::string_view ns, std::string_view name)
 
static IRIAtomPtr unique_iri (std::string_view type_iri)
 
static std::string_view iri_name (std::string_view iri)
 
static std::string_view iri_ns (std::string_view iri, bool includeDelimiter=false)
 
static AtomPtr graph_atom (std::optional< std::string_view > graph)
 

Protected Attributes

std::shared_ptr< Propertyinverse_
 
std::map< std::shared_ptr< Property >, std::set< AtomPtr, AtomComparator >, PropertyComparatordirectParents_
 
std::set< std::shared_ptr< Property >, PropertyComparatordirectChildren_
 
std::shared_ptr< Classreification_
 
int flags_
 
- Protected Attributes inherited from knowrob::semweb::Resource
knowrob::AtomPtr iri_
 

Detailed Description

A property used in knowledge graphs.

Definition at line 40 of file Property.h.

Constructor & Destructor Documentation

◆ Property() [1/4]

Property::Property ( std::string_view  iri)
explicit

Definition at line 15 of file Property.cpp.

16  : Resource(iri), reification_(std::make_shared<Class>(reifiedIRI(iri))), flags_(0) {}
std::shared_ptr< Class > reification_
Definition: Property.h:171
static knowrob::IRIAtomPtr reifiedIRI(std::string_view iri)
Definition: Property.cpp:26
Resource(std::string_view iri)
Definition: Resource.cpp:23

◆ Property() [2/4]

Property::Property ( const IRIAtomPtr iri)
explicit

Definition at line 18 of file Property.cpp.

19  : Resource(iri), reification_(std::make_shared<Class>(reifiedIRI(iri->stringForm()))), flags_(0) {}

◆ Property() [3/4]

knowrob::semweb::Property::Property ( std::string_view  iri)
explicit

◆ Property() [4/4]

knowrob::semweb::Property::Property ( const IRIAtomPtr iri)
explicit

Member Function Documentation

◆ addDirectParent() [1/2]

void Property::addDirectParent ( const std::shared_ptr< Property > &  directParent,
std::optional< std::string_view >  graph 
)
Parameters
directParenta direct super property.
graphthe graph where the relation is defined.

Definition at line 63 of file Property.cpp.

63  {
64  auto graphAtom = graph_atom(graph);
65  auto pair = directParents_.find(directParent);
66  if (pair != directParents_.end()) {
67  // add origin to list
68  pair->second.insert(graphAtom);
69  } else {
70  // add new entry
71  directParents_[directParent].insert(graphAtom);
72  directParent->directChildren_.insert(shared_from_this());
73  }
74  reification_->addDirectParent(directParent->reification_, graph);
75 }
std::map< std::shared_ptr< Property >, std::set< AtomPtr, AtomComparator >, PropertyComparator > directParents_
Definition: Property.h:169
static AtomPtr graph_atom(std::optional< std::string_view > graph)
Definition: Resource.cpp:82

◆ addDirectParent() [2/2]

void knowrob::semweb::Property::addDirectParent ( const std::shared_ptr< Property > &  directParent,
std::optional< std::string_view >  graph 
)
Parameters
directParenta direct super property.
graphthe graph where the relation is defined.

◆ detach() [1/2]

void Property::detach ( )

Detach this property from its children and parents.

Definition at line 187 of file Property.cpp.

187  {
188  directParents_.clear();
189  directChildren_.clear();
190  inverse_.reset();
191  reification_->detach();
192 }
std::shared_ptr< Property > inverse_
Definition: Property.h:166
std::set< std::shared_ptr< Property >, PropertyComparator > directChildren_
Definition: Property.h:170

◆ detach() [2/2]

void knowrob::semweb::Property::detach ( )

Detach this property from its children and parents.

◆ directParents() [1/2]

const auto& knowrob::semweb::Property::directParents ( ) const
inline
Returns
all direct super properties of this property.

Definition at line 61 of file Property.h.

61 { return directParents_; }

◆ directParents() [2/2]

const auto& knowrob::semweb::Property::directParents ( ) const
inline
Returns
all direct super properties of this property.

Definition at line 61 of file Property.h.

61 { return directParents_; }

◆ forallChildren() [1/2]

void Property::forallChildren ( const PropertyTupleVisitor visitor,
bool  skipDuplicates = true 
)
Parameters
visitora function that is called for each child in the class hierarchy.
skipDuplicatesif true, the method calls the visitor only once for each class.

Definition at line 136 of file Property.cpp.

136  {
137  std::queue<std::pair<Property *, Property *>> queue_;
138  std::set<std::string_view> visited_;
139 
140  // push initial elements to the queue
141  for (auto &x: directChildren_) queue_.emplace(x.get(), this);
142 
143  // visit each child
144  while (!queue_.empty()) {
145  auto pair = queue_.front();
146  auto front_child = pair.first;
147  auto front_parent = pair.second;
148  queue_.pop();
149  // visit popped property
150  visitor(*front_child, *front_parent);
151  // remember visited nodes
152  if (skipDuplicates) visited_.insert(front_child->iri());
153  // push children of visited property on the queue
154  for (auto &directChild: front_child->directChildren_) {
155  if (skipDuplicates && visited_.count(directChild->iri()) > 0) continue;
156  queue_.emplace(directChild.get(), front_child);
157  }
158  }
159 }

◆ forallChildren() [2/2]

void knowrob::semweb::Property::forallChildren ( const PropertyTupleVisitor visitor,
bool  skipDuplicates = true 
)
Parameters
visitora function that is called for each child in the class hierarchy.
skipDuplicatesif true, the method calls the visitor only once for each class.

◆ forallParents() [1/2]

void Property::forallParents ( const PropertyVisitor visitor,
bool  includeSelf = true,
bool  skipDuplicates = true 
)

Visit all parents of this property.

Parameters
visitora function that is called for each parent.
includeSelftrue if the property itself should be included.
skipDuplicatestrue if duplicates should be skipped.

Definition at line 110 of file Property.cpp.

112  {
113  std::queue<Property *> queue_;
114  std::set<std::string_view> visited_;
115 
116  // push initial elements to the queue
117  if (includeSelf) queue_.push(this);
118  else for (auto &x: directParents_) queue_.push(x.first.get());
119 
120  // visit each parent
121  while (!queue_.empty()) {
122  auto front = queue_.front();
123  queue_.pop();
124  // visit popped property
125  visitor(*front);
126  // remember visited nodes
127  if (skipDuplicates) visited_.insert(front->iri());
128  // push parents of visited property on the queue
129  for (auto &directParent: front->directParents_) {
130  if (skipDuplicates && visited_.count(directParent.first->iri()) > 0) continue;
131  queue_.push(directParent.first.get());
132  }
133  }
134 }

◆ forallParents() [2/2]

void knowrob::semweb::Property::forallParents ( const PropertyVisitor visitor,
bool  includeSelf = true,
bool  skipDuplicates = true 
)

Visit all parents of this property.

Parameters
visitora function that is called for each parent.
includeSelftrue if the property itself should be included.
skipDuplicatestrue if duplicates should be skipped.

◆ hasFlag() [1/2]

bool Property::hasFlag ( PropertyFlag  flag) const
Parameters
flaga property flag.
Returns
true if this property has the flag.

Definition at line 102 of file Property.cpp.

102  {
103  return flags_ & flag;
104 }

◆ hasFlag() [2/2]

bool knowrob::semweb::Property::hasFlag ( PropertyFlag  flag) const
Parameters
flaga property flag.
Returns
true if this property has the flag.

◆ inverse() [1/2]

const auto& knowrob::semweb::Property::inverse ( ) const
inline
Returns
the inverse of this property or a null pointer reference.

Definition at line 72 of file Property.h.

72 { return inverse_; }

◆ inverse() [2/2]

const auto& knowrob::semweb::Property::inverse ( ) const
inline
Returns
the inverse of this property or a null pointer reference.

Definition at line 72 of file Property.h.

72 { return inverse_; }

◆ isAnnotationProperty() [1/2]

bool knowrob::semweb::Property::isAnnotationProperty ( ) const
inline
Returns
true if this property is an annotation property.

Definition at line 94 of file Property.h.

94 { return hasFlag(ANNOTATION_PROPERTY); }
bool hasFlag(PropertyFlag flag) const
Definition: Property.cpp:102
@ ANNOTATION_PROPERTY
Definition: Property.h:22

◆ isAnnotationProperty() [2/2]

bool knowrob::semweb::Property::isAnnotationProperty ( ) const
inline
Returns
true if this property is an annotation property.

Definition at line 94 of file Property.h.

94 { return hasFlag(ANNOTATION_PROPERTY); }

◆ isDatatypeProperty() [1/2]

bool knowrob::semweb::Property::isDatatypeProperty ( ) const
inline
Returns
true if this property is a datatype property.

Definition at line 89 of file Property.h.

89 { return hasFlag(DATATYPE_PROPERTY); }

◆ isDatatypeProperty() [2/2]

bool knowrob::semweb::Property::isDatatypeProperty ( ) const
inline
Returns
true if this property is a datatype property.

Definition at line 89 of file Property.h.

89 { return hasFlag(DATATYPE_PROPERTY); }

◆ isObjectProperty() [1/2]

bool knowrob::semweb::Property::isObjectProperty ( ) const
inline
Returns
true if this property is an object property.

Definition at line 99 of file Property.h.

99 { return hasFlag(OBJECT_PROPERTY); }

◆ isObjectProperty() [2/2]

bool knowrob::semweb::Property::isObjectProperty ( ) const
inline
Returns
true if this property is an object property.

Definition at line 99 of file Property.h.

99 { return hasFlag(OBJECT_PROPERTY); }

◆ isReflexiveProperty() [1/2]

bool knowrob::semweb::Property::isReflexiveProperty ( ) const
inline
Returns
true if this property is a reflexive property.

Definition at line 109 of file Property.h.

109 { return hasFlag(REFLEXIVE_PROPERTY); }
@ REFLEXIVE_PROPERTY
Definition: Property.h:25

◆ isReflexiveProperty() [2/2]

bool knowrob::semweb::Property::isReflexiveProperty ( ) const
inline
Returns
true if this property is a reflexive property.

Definition at line 109 of file Property.h.

109 { return hasFlag(REFLEXIVE_PROPERTY); }

◆ isSubPropertyOf() [1/2]

bool Property::isSubPropertyOf ( const std::shared_ptr< Property > &  parent,
bool  includeSelf = true 
)
Parameters
parenta super property.
includeSelfif true, the method returns true if this property is the same
Returns
true if this property is a sub property of parent.

Definition at line 161 of file Property.cpp.

161  {
162  std::queue<Property *> queue_;
163  std::set<std::string_view> visited_;
164 
165  if (includeSelf && this == parent.get()) return true;
166  queue_.push(this);
167 
168  // visit each parent
169  while (!queue_.empty()) {
170  auto front = queue_.front();
171  queue_.pop();
172 
173  // visit popped property
174  if (front->directParents_.count(parent) > 0) return true;
175  // remember visited nodes
176  visited_.insert(front->iri());
177  // push parents of visited property on the queue
178  for (auto &directParent: front->directParents_) {
179  if (visited_.count(directParent.first->iri()) > 0) continue;
180  queue_.push(directParent.first.get());
181  }
182  }
183 
184  return false;
185 }

◆ isSubPropertyOf() [2/2]

bool knowrob::semweb::Property::isSubPropertyOf ( const std::shared_ptr< Property > &  parent,
bool  includeSelf = true 
)
Parameters
parenta super property.
includeSelfif true, the method returns true if this property is the same
Returns
true if this property is a sub property of parent.

◆ isSymmetricProperty() [1/2]

bool knowrob::semweb::Property::isSymmetricProperty ( ) const
inline
Returns
true if this property is a symmetric property.

Definition at line 114 of file Property.h.

114 { return hasFlag(SYMMETRIC_PROPERTY); }
@ SYMMETRIC_PROPERTY
Definition: Property.h:26

◆ isSymmetricProperty() [2/2]

bool knowrob::semweb::Property::isSymmetricProperty ( ) const
inline
Returns
true if this property is a symmetric property.

Definition at line 114 of file Property.h.

114 { return hasFlag(SYMMETRIC_PROPERTY); }

◆ isTransitiveProperty() [1/2]

bool knowrob::semweb::Property::isTransitiveProperty ( ) const
inline
Returns
true if this property is a transitive property.

Definition at line 104 of file Property.h.

104 { return hasFlag(TRANSITIVE_PROPERTY); }
@ TRANSITIVE_PROPERTY
Definition: Property.h:24

◆ isTransitiveProperty() [2/2]

bool knowrob::semweb::Property::isTransitiveProperty ( ) const
inline
Returns
true if this property is a transitive property.

Definition at line 104 of file Property.h.

104 { return hasFlag(TRANSITIVE_PROPERTY); }

◆ reification() [1/2]

auto knowrob::semweb::Property::reification ( ) const
inline
Returns
the reification concept of this property.

Definition at line 140 of file Property.h.

140 { return reification_; }

◆ reification() [2/2]

auto knowrob::semweb::Property::reification ( ) const
inline
Returns
the reification concept of this property.

Definition at line 140 of file Property.h.

140 { return reification_; }

◆ reifiedIRI() [1/2]

knowrob::IRIAtomPtr Property::reifiedIRI ( std::string_view  iri)
static

Map an IRI of a property to the IRI of the concept that reifies the property.

Parameters
irian IRI of a property.
Returns
the reification concept of the property.

Definition at line 26 of file Property.cpp.

26  {
27  // split the IRI at the last '#' and insert 'Reified' in between
28  auto pos = iri.rfind('#');
29  char delimiter = '#';
30  if (pos == std::string::npos) {
31  pos = iri.rfind('/');
32  delimiter = '/';
33  }
34  std::stringstream ss;
35  if (pos == std::string::npos) {
36  ss << "Reified_" << iri;
37  return IRIAtom::Tabled(ss.str());
38  }
39  ss << iri.substr(0, pos) << delimiter << "Reified_" << iri.substr(pos + 1);
40  return IRIAtom::Tabled(ss.str());
41 }
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
Definition: IRIAtom.cpp:25

◆ reifiedIRI() [2/2]

static knowrob::IRIAtomPtr knowrob::semweb::Property::reifiedIRI ( std::string_view  iri)
static

Map an IRI of a property to the IRI of the concept that reifies the property.

Parameters
irian IRI of a property.
Returns
the reification concept of the property.

◆ removeDirectParent() [1/2]

void Property::removeDirectParent ( const std::shared_ptr< Property > &  directParent,
std::optional< std::string_view >  graph 
)
Parameters
directParenta direct super property.
graphthe graph where the relation is defined.

Definition at line 78 of file Property.cpp.

78  {
79  auto pair = directParents_.find(directParent);
80  if (pair != directParents_.end()) {
81  // remove origin from list
82  std::string_view v_graph = (graph) ? graph.value() : ImportHierarchy::ORIGIN_SESSION;
83  for (auto it = pair->second.begin(); it != pair->second.end(); it++) {
84  if ((*it)->stringForm() == v_graph) {
85  pair->second.erase(it);
86  break;
87  }
88  }
89  // remove if no origin is left
90  if (pair->second.empty()) {
91  directParents_.erase(pair);
92  directParent->directChildren_.erase(shared_from_this());
93  reification_->removeDirectParent(directParent->reification_, graph);
94  }
95  }
96 }
static constexpr std::string_view ORIGIN_SESSION

◆ removeDirectParent() [2/2]

void knowrob::semweb::Property::removeDirectParent ( const std::shared_ptr< Property > &  directParent,
std::optional< std::string_view >  graph 
)
Parameters
directParenta direct super property.
graphthe graph where the relation is defined.

◆ setFlag() [1/2]

void Property::setFlag ( PropertyFlag  flag)

Define a flag of this property.

Parameters
flaga property flag.

Definition at line 106 of file Property.cpp.

106  {
107  flags_ |= flag;
108 }

◆ setFlag() [2/2]

void knowrob::semweb::Property::setFlag ( PropertyFlag  flag)

Define a flag of this property.

Parameters
flaga property flag.

◆ setInverse() [1/2]

void Property::setInverse ( const std::shared_ptr< Property > &  inverse)

Define the inverse property of this property.

Parameters
inversea property.

Definition at line 98 of file Property.cpp.

98  {
99  inverse_ = inverse;
100 }
const auto & inverse() const
Definition: Property.h:72

◆ setInverse() [2/2]

void knowrob::semweb::Property::setInverse ( const std::shared_ptr< Property > &  inverse)

Define the inverse property of this property.

Parameters
inversea property.

◆ unReifiedIRI() [1/2]

knowrob::IRIAtomPtr Property::unReifiedIRI ( std::string_view  iri)
static

Map an IRI of a reification concept to the IRI of the property.

Parameters
irian IRI of a reification concept.
Returns
the property IRI.

Definition at line 43 of file Property.cpp.

43  {
44  // split the IRI at the last '#' and remove 'Reified' in between
45  auto pos = iri.rfind('#');
46  char delimiter = '#';
47  if (pos == std::string::npos) {
48  pos = iri.rfind('/');
49  delimiter = '/';
50  }
51  if (pos == std::string::npos) {
52  return IRIAtom::Tabled(iri);
53  }
54  auto reified = iri.substr(pos + 1);
55  if (reified.find("Reified_") != 0) {
56  return IRIAtom::Tabled(iri);
57  }
58  std::stringstream ss;
59  ss << iri.substr(0, pos) << delimiter << reified.substr(8);
60  return IRIAtom::Tabled(ss.str());
61 }

◆ unReifiedIRI() [2/2]

static knowrob::IRIAtomPtr knowrob::semweb::Property::unReifiedIRI ( std::string_view  iri)
static

Map an IRI of a reification concept to the IRI of the property.

Parameters
irian IRI of a reification concept.
Returns
the property IRI.

Member Data Documentation

◆ directChildren_

std::set< std::shared_ptr< Property >, PropertyComparator > knowrob::semweb::Property::directChildren_
protected

Definition at line 170 of file Property.h.

◆ directParents_

std::map< std::shared_ptr< Property >, std::set< AtomPtr, AtomComparator >, PropertyComparator > knowrob::semweb::Property::directParents_
protected

Definition at line 169 of file Property.h.

◆ flags_

int knowrob::semweb::Property::flags_
protected

Definition at line 172 of file Property.h.

◆ inverse_

std::shared_ptr< Property > knowrob::semweb::Property::inverse_
protected

Definition at line 166 of file Property.h.

◆ reification_

std::shared_ptr< Class > knowrob::semweb::Property::reification_
protected

Definition at line 171 of file Property.h.


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