8 #include "knowrob/semweb/Class.h"
9 #include "knowrob/Logger.h"
10 #include "knowrob/integration/python/utils.h"
11 #include "knowrob/semweb/ImportHierarchy.h"
22 return lhs->iri() < rhs->iri();
30 pair->second.insert(graphAtom);
34 directParent->directChildren_.insert(shared_from_this());
43 for (
auto it = pair->second.begin(); it != pair->second.end(); it++) {
44 if ((*it)->stringForm() == v_graph) {
45 pair->second.erase(it);
50 if (pair->second.empty()) {
52 directParent->directChildren_.erase(shared_from_this());
62 std::queue<Class *> queue_;
63 std::set<std::string_view> visited_;
65 if (includeSelf &&
this == parent.get())
return true;
69 while (!queue_.empty()) {
70 auto front = queue_.front();
74 if (front->directParents_.count(parent) > 0)
return true;
76 visited_.insert(front->iri());
78 for (
auto &directParent: front->directParents_) {
79 if (visited_.count(directParent.first->iri()) > 0)
continue;
80 queue_.push(directParent.first.get());
89 bool skipDuplicates) {
90 std::queue<Class *> queue_;
91 std::set<std::string_view> visited_;
94 if (includeSelf) queue_.push(
this);
98 while (!queue_.empty()) {
99 auto front = queue_.front();
104 if (skipDuplicates) visited_.insert(front->iri());
106 for (
auto &directParent: front->directParents_) {
107 if (skipDuplicates && visited_.count(directParent.first->iri()) > 0)
continue;
108 queue_.push(directParent.first.get());
114 std::queue<std::pair<Class *, Class *>> queue_;
115 std::set<std::string_view> visited_;
121 while (!queue_.empty()) {
122 auto pair = queue_.front();
123 auto front_child = pair.first;
124 auto front_parent = pair.second;
127 visitor(*front_child, *front_parent);
129 if (skipDuplicates) visited_.insert(front_child->iri());
131 for (
auto &directChild: front_child->directChildren_) {
132 if (skipDuplicates && visited_.count(directChild->iri()) > 0)
continue;
133 queue_.emplace(directChild.get(), front_child);
145 void createType<semweb::Class>() {
148 class_<semweb::Class, bases<semweb::Resource>, std::shared_ptr<semweb::Class>, boost::noncopyable>
149 (
"Class", init<std::string_view>())
150 .def(init<const IRIAtomPtr &>())
static constexpr std::string_view ORIGIN_SESSION
Class(std::string_view iri)
std::set< std::shared_ptr< Class >, ClassComparator > directChildren_
bool isSubClassOf(const std::shared_ptr< Class > &parent, bool includeSelf=true)
const auto & directParents() const
void forallChildren(const ClassTupleVisitor &visitor, bool skipDuplicates=true)
bool isDirectSubClassOf(const std::shared_ptr< Class > &directParent)
void addDirectParent(const std::shared_ptr< Class > &directParent, std::optional< std::string_view > graph)
void forallParents(const ClassVisitor &visitor, bool includeSelf=true, bool skipDuplicates=true)
void removeDirectParent(const std::shared_ptr< Class > &directParent, std::optional< std::string_view > graph)
std::map< std::shared_ptr< Class >, std::set< AtomPtr, AtomComparator >, ClassComparator > directParents_
static AtomPtr graph_atom(std::optional< std::string_view > graph)
std::function< void(Class &)> ClassVisitor
std::function< void(Class &, Class &)> ClassTupleVisitor
IRIAtomPtr iri(std::string_view ns, std::string_view name)
std::shared_ptr< IRIAtom > IRIAtomPtr
bool operator()(const std::shared_ptr< Class > &lhs, const std::shared_ptr< Class > &rhs) const