8 #include "knowrob/semweb/Property.h"
9 #include "knowrob/Logger.h"
10 #include "knowrob/integration/python/utils.h"
11 #include "knowrob/semweb/ImportHierarchy.h"
19 :
Resource(
iri), reification_(std::make_shared<
Class>(reifiedIRI(
iri->stringForm()))), flags_(0) {}
22 const std::shared_ptr<Property> &rhs)
const {
23 return lhs->iri() < rhs->iri();
28 auto pos =
iri.rfind(
'#');
30 if (pos == std::string::npos) {
35 if (pos == std::string::npos) {
36 ss <<
"Reified_" <<
iri;
39 ss <<
iri.substr(0, pos) << delimiter <<
"Reified_" <<
iri.substr(pos + 1);
45 auto pos =
iri.rfind(
'#');
47 if (pos == std::string::npos) {
51 if (pos == std::string::npos) {
54 auto reified =
iri.substr(pos + 1);
55 if (reified.find(
"Reified_") != 0) {
59 ss <<
iri.substr(0, pos) << delimiter << reified.substr(8);
68 pair->second.insert(graphAtom);
72 directParent->directChildren_.insert(shared_from_this());
74 reification_->addDirectParent(directParent->reification_, graph);
83 for (
auto it = pair->second.begin(); it != pair->second.end(); it++) {
84 if ((*it)->stringForm() == v_graph) {
85 pair->second.erase(it);
90 if (pair->second.empty()) {
92 directParent->directChildren_.erase(shared_from_this());
93 reification_->removeDirectParent(directParent->reification_, graph);
112 bool skipDuplicates) {
113 std::queue<Property *> queue_;
114 std::set<std::string_view> visited_;
117 if (includeSelf) queue_.push(
this);
121 while (!queue_.empty()) {
122 auto front = queue_.front();
127 if (skipDuplicates) visited_.insert(front->iri());
129 for (
auto &directParent: front->directParents_) {
130 if (skipDuplicates && visited_.count(directParent.first->iri()) > 0)
continue;
131 queue_.push(directParent.first.get());
137 std::queue<std::pair<Property *, Property *>> queue_;
138 std::set<std::string_view> visited_;
144 while (!queue_.empty()) {
145 auto pair = queue_.front();
146 auto front_child = pair.first;
147 auto front_parent = pair.second;
150 visitor(*front_child, *front_parent);
152 if (skipDuplicates) visited_.insert(front_child->iri());
154 for (
auto &directChild: front_child->directChildren_) {
155 if (skipDuplicates && visited_.count(directChild->iri()) > 0)
continue;
156 queue_.emplace(directChild.get(), front_child);
162 std::queue<Property *> queue_;
163 std::set<std::string_view> visited_;
165 if (includeSelf &&
this == parent.get())
return true;
169 while (!queue_.empty()) {
170 auto front = queue_.front();
174 if (front->directParents_.count(parent) > 0)
return true;
176 visited_.insert(front->iri());
178 for (
auto &directParent: front->directParents_) {
179 if (visited_.count(directParent.first->iri()) > 0)
continue;
180 queue_.push(directParent.first.get());
196 void createType<semweb::Property>() {
199 enum_<PropertyFlag>(
"PropertyFlag")
208 class_<semweb::Property, bases<semweb::Resource>, std::shared_ptr<semweb::Property>, boost::noncopyable>
209 (
"Property", init<std::string_view>())
210 .def(init<const IRIAtomPtr &>())
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
static constexpr std::string_view ORIGIN_SESSION
bool isSubPropertyOf(const std::shared_ptr< Property > &parent, bool includeSelf=true)
void setInverse(const std::shared_ptr< Property > &inverse)
bool isAnnotationProperty() const
static knowrob::IRIAtomPtr unReifiedIRI(std::string_view iri)
bool isSymmetricProperty() const
void forallParents(const PropertyVisitor &visitor, bool includeSelf=true, bool skipDuplicates=true)
std::shared_ptr< Property > inverse_
Property(std::string_view iri)
bool hasFlag(PropertyFlag flag) const
bool isDatatypeProperty() const
bool isReflexiveProperty() const
void setFlag(PropertyFlag flag)
const auto & directParents() const
std::shared_ptr< Class > reification_
bool isObjectProperty() const
std::set< std::shared_ptr< Property >, PropertyComparator > directChildren_
bool isTransitiveProperty() const
static knowrob::IRIAtomPtr reifiedIRI(std::string_view iri)
void forallChildren(const PropertyTupleVisitor &visitor, bool skipDuplicates=true)
const auto & inverse() const
void removeDirectParent(const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
std::map< std::shared_ptr< Property >, std::set< AtomPtr, AtomComparator >, PropertyComparator > directParents_
void addDirectParent(const std::shared_ptr< Property > &directParent, std::optional< std::string_view > graph)
static AtomPtr graph_atom(std::optional< std::string_view > graph)
std::function< void(Property &)> PropertyVisitor
std::function< void(Property &, Property &)> PropertyTupleVisitor
IRIAtomPtr iri(std::string_view ns, std::string_view name)
std::shared_ptr< IRIAtom > IRIAtomPtr
bool operator()(const std::shared_ptr< Property > &lhs, const std::shared_ptr< Property > &rhs) const