50 ARMARX_LOG <<
"Starting PriorKnowledgeImporter";
54 classesSegmentPrx = memoryPrx->getObjectClassesSegment();
66 if (taskName ==
"ImportFiles")
70 else if (taskName ==
"AddParents")
74 else if (taskName ==
"ConvertFormat")
78 else if (taskName ==
"AddRelations")
89 PriorKnowledgeImporter::importFiles()
91 ARMARX_INFO <<
"Importing object models from " << filesDir;
93 namespace fs = std::filesystem;
94 fs::path ivDir(filesDir);
95 fs::directory_iterator end_iter;
99 if (!fs::exists(ivDir) || !fs::is_directory(ivDir))
104 for (fs::directory_iterator dir_iter(ivDir); dir_iter != end_iter; ++dir_iter)
106 if (fs::is_regular_file(dir_iter->status()) &&
107 (dir_iter->path().extension() ==
".iv" || dir_iter->path().extension() ==
".wrl"))
109 fs::path ivFile = dir_iter->path();
116 ARMARX_INFO <<
"Import complete, # of loaded files: " << fileCount;
121 const std::string& className)
124 newClass->setName(className);
129 simoxWrapper->setAndStoreModelIVFiles(ivFile, ivFile, filesDBName);
131 EntityBasePtr ent = classesSegmentPrx->getEntityByName(newClass->getName());
136 <<
"(Id: " << ent->getId() <<
")";
137 classesSegmentPrx->updateEntity(ent->getId(), ent);
141 classesSegmentPrx->addEntity(newClass);
146 PriorKnowledgeImporter::addParents()
148 EntityIdList ids = classesSegmentPrx->getAllEntityIds();
150 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
152 ObjectClassBasePtr cls = classesSegmentPrx->getObjectClassById(*it);
156 cls->clearParentClasses();
157 cls->addParentClass(
"Entity");
159 if (cls->getName() ==
"Cup")
161 cls->addParentClass(
"Dishes");
163 else if (cls->getName() !=
"coffeefilters")
165 cls->addParentClass(
"Food");
168 classesSegmentPrx->updateEntity(cls->getId(), cls);
174 PriorKnowledgeImporter::convertToNewFormat()
176 const std::string collNS = classesSegmentPrx->getWriteCollectionNS();
177 CollectionInterfacePrx coll = dataBasePrx->requestCollection(collNS);
178 EntityIdList ids = classesSegmentPrx->getAllEntityIds();
180 int countConverted = 0, countFailed = 0;
182 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
185 DBStorableData dbEntity = coll->findByMongoId(*it);
186 dbSerializer->deserialize(dbEntity, cls);
190 classesSegmentPrx->updateEntity(cls->getId(), cls);
195 ARMARX_ERROR <<
"Error deserializing entity: id =" << *it
202 ARMARX_INFO <<
"Entities converted: " << countConverted <<
", failed: " << countFailed
207 PriorKnowledgeImporter::addRelations()
209 PersistentRelationSegmentBasePrx relSegmentPrx = memoryPrx->getRelationsSegment();
211 EntityRefBasePtr tableRef = classesSegmentPrx->getEntityRefByName(
"TableWithRolls");
212 EntityRefBasePtr cupRef = classesSegmentPrx->getEntityRefByName(
"Cup");
214 if (tableRef && cupRef)
216 rel->setEntities({cupRef, tableRef});
218 relSegmentPrx->addEntity(rel);
223 ARMARX_ERROR <<
"Failed to create relation: object class(es) not found!"
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
void onInitComponent() override
Pure virtual hook for the subclass.
void importObjectClass(const std::string &ivFile, const std::string &className)
void onConnectComponent() override
Pure virtual hook for the subclass.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
const LogSender::manipulator flush
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
IceInternal::Handle< Relation > RelationPtr