34 EntityFusionMethod(
"PriorAttributeEnrichmentFusion"), priorKnowledgePrx(priorKnowledgePrx), forceOverwrite(forceOverwrite)
40 if (!priorKnowledgePrx)
45 addPriorAttrs(updateEntity);
50 if (!priorKnowledgePrx)
55 EntityBasePtr fusedEntity = EntityBasePtr::dynamicCast(updateEntity->ice_clone());
56 addPriorAttrs(fusedEntity);
63 ARMARX_DEBUG_S <<
"PriorAttributeEnrichmentFusion::fuseEntity() called";
65 copyMissingAttrs(oldEntity, newEntity);
66 addPriorAttrs(newEntity);
71 void PriorAttributeEnrichmentFusion::addPriorAttrs(
const EntityBasePtr& entity)
const
77 std::string classname = inst->getMostProbableClass();
79 if (!classname.empty())
81 EntityBasePtr priorEntity = priorKnowledgePrx->getObjectClassesSegment()->getEntityByName(classname);
85 copyMissingAttrs(priorEntity, entity);
95 void PriorAttributeEnrichmentFusion::copyMissingAttrs(
const EntityBasePtr& srcEntity,
const EntityBasePtr& destEntity)
const
97 NameList attrNames = srcEntity->getAttributeNames();
99 for (NameList::const_iterator it = attrNames.begin(); it != attrNames.end(); ++it)
100 if (forceOverwrite || !destEntity->hasAttribute(*it))
102 ARMARX_VERBOSE <<
"Adding attribute: " << srcEntity->getAttribute(*it)->getName();
103 destEntity->putAttribute(srcEntity->getAttribute(*it));