knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Property.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_SEMWEB_PROPERTY_H
7 #define KNOWROB_SEMWEB_PROPERTY_H
8 
9 #include <memory>
10 #include <list>
11 #include <functional>
12 #include "Resource.h"
13 #include "knowrob/terms/IRIAtom.h"
14 #include "Class.h"
15 
16 namespace knowrob::semweb {
20  enum PropertyFlag {
21  DATATYPE_PROPERTY = 1 << 0,
22  ANNOTATION_PROPERTY = 1 << 1,
23  OBJECT_PROPERTY = 1 << 2,
24  TRANSITIVE_PROPERTY = 1 << 3,
25  REFLEXIVE_PROPERTY = 1 << 4,
26  SYMMETRIC_PROPERTY = 1 << 5
27  };
28 
29  // forward declaration
30  class Property;
31 
32  // called for each parent in the property hierarchy
33  using PropertyVisitor = std::function<void(Property &)>;
34  // called for each parent in the property hierarchy
36 
40  class Property : public Resource, public std::enable_shared_from_this<Property> {
41  public:
42  explicit Property(std::string_view iri);
43 
44  explicit Property(const IRIAtomPtr &iri);
45 
50  void addDirectParent(const std::shared_ptr<Property> &directParent, std::optional<std::string_view> graph);
51 
56  void removeDirectParent(const std::shared_ptr<Property> &directParent, std::optional<std::string_view> graph);
57 
61  const auto &directParents() const { return directParents_; }
62 
67  void setInverse(const std::shared_ptr<Property> &inverse);
68 
72  const auto &inverse() const { return inverse_; }
73 
78  bool hasFlag(PropertyFlag flag) const;
79 
84  void setFlag(PropertyFlag flag);
85 
89  bool isDatatypeProperty() const { return hasFlag(DATATYPE_PROPERTY); }
90 
95 
99  bool isObjectProperty() const { return hasFlag(OBJECT_PROPERTY); }
100 
105 
110 
115 
121  bool isSubPropertyOf(const std::shared_ptr<Property> &parent, bool includeSelf = true);
122 
129  void forallParents(const PropertyVisitor &visitor, bool includeSelf = true, bool skipDuplicates = true);
130 
135  void forallChildren(const PropertyTupleVisitor &visitor, bool skipDuplicates = true);
136 
140  auto reification() const { return reification_; }
141 
147  static knowrob::IRIAtomPtr reifiedIRI(std::string_view iri);
148 
154  static knowrob::IRIAtomPtr unReifiedIRI(std::string_view iri);
155 
159  void detach();
160 
161  protected:
162  struct PropertyComparator {
163  bool operator()(const std::shared_ptr<Property> &lhs, const std::shared_ptr<Property> &rhs) const;
164  };
165 
166  std::shared_ptr<Property> inverse_;
167  std::map<std::shared_ptr<Property>,
168  std::set<AtomPtr, AtomComparator>,
170  std::set<std::shared_ptr<Property>, PropertyComparator> directChildren_;
171  std::shared_ptr<Class> reification_;
172  int flags_;
173  };
174 
175  using PropertyPtr = std::shared_ptr<Property>;
176 
177 } // knowrob
178 
179 #endif //KNOWROB_SEMWEB_PROPERTY_H
void removeDirectParent(const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
auto reification() const
Definition: Property.h:140
static knowrob::IRIAtomPtr unReifiedIRI(std::string_view iri)
bool isAnnotationProperty() const
Definition: Property.h:94
Property(const IRIAtomPtr &iri)
bool isSymmetricProperty() const
Definition: Property.h:114
void addDirectParent(const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
std::shared_ptr< Property > inverse_
Definition: Property.h:166
bool hasFlag(PropertyFlag flag) const
Definition: Property.cpp:102
static knowrob::IRIAtomPtr reifiedIRI(std::string_view iri)
bool isDatatypeProperty() const
Definition: Property.h:89
bool isReflexiveProperty() const
Definition: Property.h:109
const auto & directParents() const
Definition: Property.h:61
std::shared_ptr< Class > reification_
Definition: Property.h:171
bool isObjectProperty() const
Definition: Property.h:99
void forallParents(const PropertyVisitor &visitor, bool includeSelf=true, bool skipDuplicates=true)
void setFlag(PropertyFlag flag)
std::set< std::shared_ptr< Property >, PropertyComparator > directChildren_
Definition: Property.h:170
bool isSubPropertyOf(const std::shared_ptr< Property > &parent, bool includeSelf=true)
bool isTransitiveProperty() const
Definition: Property.h:104
Property(std::string_view iri)
void setInverse(const std::shared_ptr< Property > &inverse)
void forallChildren(const PropertyTupleVisitor &visitor, bool skipDuplicates=true)
bool hasFlag(PropertyFlag flag) const
const auto & inverse() const
Definition: Property.h:72
std::map< std::shared_ptr< Property >, std::set< AtomPtr, AtomComparator >, PropertyComparator > directParents_
Definition: Property.h:169
FunctionRule & function()
Definition: terms.cpp:140
const IRIAtomPtr Property
Definition: rdf.h:16
@ SYMMETRIC_PROPERTY
Definition: Property.h:26
@ TRANSITIVE_PROPERTY
Definition: Property.h:24
@ ANNOTATION_PROPERTY
Definition: Property.h:22
@ REFLEXIVE_PROPERTY
Definition: Property.h:25
std::function< void(Property &)> PropertyVisitor
Definition: Property.h:33
std::shared_ptr< Property > PropertyPtr
Definition: Property.h:175
std::function< void(Property &, Property &)> PropertyTupleVisitor
Definition: Property.h:35
std::shared_ptr< IRIAtom > IRIAtomPtr
Definition: IRIAtom.h:57
bool operator()(const std::shared_ptr< Property > &lhs, const std::shared_ptr< Property > &rhs) const