50 ARMARX_LOG <<
"Starting PriorKnowledgeImporter";
52 dataBasePrx = getProxy<CommonStorageInterfacePrx>(
"CommonStorage");
53 memoryPrx = getProxy<PriorKnowledgeInterfacePrx>(
"PriorKnowledge");
54 classesSegmentPrx = memoryPrx->getObjectClassesSegment();
61 filesDBName = getProperty<std::string>(
"FilesDbName").getValue();
62 filesDir = getProperty<std::string>(
"FilesDirectory").getValue();
64 const std::string taskName = getProperty<std::string>(
"TaskName").getValue();
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!"