48 ARMARX_LOG <<
"Starting PriorKnowledgeImporter";
50 dataBasePrx = getProxy<CommonStorageInterfacePrx>(
"CommonStorage");
51 memoryPrx = getProxy<PriorKnowledgeInterfacePrx>(
"PriorKnowledge");
52 classesSegmentPrx = memoryPrx->getObjectClassesSegment();
59 filesDBName = getProperty<std::string>(
"FilesDbName").getValue();
60 filesDir = getProperty<std::string>(
"FilesDirectory").getValue();
62 const std::string taskName = getProperty<std::string>(
"TaskName").getValue();
64 if (taskName ==
"ImportFiles")
68 else if (taskName ==
"AddParents")
72 else if (taskName ==
"ConvertFormat")
76 else if (taskName ==
"AddRelations")
87 void PriorKnowledgeImporter::importFiles()
89 ARMARX_INFO <<
"Importing object models from " << filesDir;
91 namespace fs = std::filesystem;
92 fs::path ivDir(filesDir);
93 fs::directory_iterator end_iter;
97 if (!fs::exists(ivDir) || !fs::is_directory(ivDir))
102 for (fs::directory_iterator dir_iter(ivDir) ; dir_iter != end_iter ; ++dir_iter)
104 if (fs::is_regular_file(dir_iter->status()) && (dir_iter->path().extension() ==
".iv" || dir_iter->path().extension() ==
".wrl"))
106 fs::path ivFile = dir_iter->path();
113 ARMARX_INFO <<
"Import complete, # of loaded files: " << fileCount;
120 newClass->setName(className);
124 simoxWrapper->setAndStoreModelIVFiles(ivFile, ivFile, filesDBName);
126 EntityBasePtr ent = classesSegmentPrx->getEntityByName(newClass->getName());
130 ARMARX_IMPORTANT <<
"Updating existing entity " << ent->getName() <<
"(Id: " << ent->getId() <<
")";
131 classesSegmentPrx->updateEntity(ent->getId(), ent);
135 classesSegmentPrx->addEntity(newClass);
140 void PriorKnowledgeImporter::addParents()
142 EntityIdList ids = classesSegmentPrx->getAllEntityIds();
144 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
146 ObjectClassBasePtr cls = classesSegmentPrx->getObjectClassById(*it);
150 cls->clearParentClasses();
151 cls->addParentClass(
"Entity");
153 if (cls->getName() ==
"Cup")
155 cls->addParentClass(
"Dishes");
157 else if (cls->getName() !=
"coffeefilters")
159 cls->addParentClass(
"Food");
162 classesSegmentPrx->updateEntity(cls->getId(), cls);
167 void PriorKnowledgeImporter::convertToNewFormat()
169 const std::string collNS = classesSegmentPrx->getWriteCollectionNS();
170 CollectionInterfacePrx coll = dataBasePrx->requestCollection(collNS);
171 EntityIdList ids = classesSegmentPrx->getAllEntityIds();
173 int countConverted = 0, countFailed = 0;
175 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
178 DBStorableData dbEntity = coll->findByMongoId(*it);
179 dbSerializer->deserialize(dbEntity, cls);
183 classesSegmentPrx->updateEntity(cls->getId(), cls);
197 void PriorKnowledgeImporter::addRelations()
199 PersistentRelationSegmentBasePrx relSegmentPrx = memoryPrx->getRelationsSegment();
201 EntityRefBasePtr tableRef = classesSegmentPrx->getEntityRefByName(
"TableWithRolls");
202 EntityRefBasePtr cupRef = classesSegmentPrx->getEntityRefByName(
"Cup");
204 if (tableRef && cupRef)
206 rel->setEntities({cupRef, tableRef});
208 relSegmentPrx->addEntity(rel);