aGrUM  0.13.2
gum::prm::o3prm::O3ClassFactory< GUM_SCALAR > Class Template Reference

Builds gum::prm::Class from gum::prm::o3prm::O3Class. More...

#include <agrum/PRM/o3prm/O3ClassFactory.h>

+ Collaboration diagram for gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >:

Public Member Functions

 O3ClassFactory (PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
 
 O3ClassFactory (const O3ClassFactory< GUM_SCALAR > &src)
 
 O3ClassFactory (O3ClassFactory< GUM_SCALAR > &&src)
 
 ~O3ClassFactory ()
 
O3ClassFactory< GUM_SCALAR > & operator= (const O3ClassFactory< GUM_SCALAR > &src)
 
O3ClassFactory< GUM_SCALAR > & operator= (O3ClassFactory< GUM_SCALAR > &&src)
 
void buildClasses ()
 
void buildImplementations ()
 
void buildParameters ()
 
void buildReferenceSlots ()
 
void declareAggregates ()
 
void completeAggregates ()
 
void declareAttributes ()
 
void completeAttributes ()
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >

Builds gum::prm::Class from gum::prm::o3prm::O3Class.

Template Parameters
GUM_SCALARThe scalar type used by the gum::prm:PRM.

Definition at line 57 of file O3ClassFactory.h.

Constructor & Destructor Documentation

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::O3ClassFactory ( PRM< GUM_SCALAR > &  prm,
O3PRM o3_prm,
O3NameSolver< GUM_SCALAR > &  solver,
ErrorsContainer errors 
)

Definition at line 36 of file O3ClassFactory_tpl.h.

40  :
41  __prm(&prm),
42  __o3_prm(&o3_prm), __solver(&solver), __errors(&errors) {
43  GUM_CONSTRUCTOR(O3ClassFactory);
44  }
O3ClassFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
O3NameSolver< GUM_SCALAR > * __solver
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::O3ClassFactory ( const O3ClassFactory< GUM_SCALAR > &  src)

Definition at line 47 of file O3ClassFactory_tpl.h.

48  :
49  __prm(src.__prm),
50  __o3_prm(src.__o3_prm), __solver(src.__solver), __errors(src.__errors),
51  __nameMap(src.__nameMap), __classMap(src.__classMap),
52  __nodeMap(src.__nodeMap), __dag(src.__dag),
53  __o3Classes(src.__o3Classes) {
54  GUM_CONS_CPY(O3ClassFactory);
55  }
HashTable< std::string, gum::NodeId > __nameMap
O3ClassFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
HashTable< NodeId, O3Class * > __nodeMap
HashTable< std::string, O3Class * > __classMap
std::vector< O3Class * > __o3Classes
O3NameSolver< GUM_SCALAR > * __solver
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::O3ClassFactory ( O3ClassFactory< GUM_SCALAR > &&  src)

Definition at line 58 of file O3ClassFactory_tpl.h.

59  :
60  __prm(std::move(src.__prm)),
61  __o3_prm(std::move(src.__o3_prm)), __solver(std::move(src.__solver)),
62  __errors(std::move(src.__errors)), __nameMap(std::move(src.__nameMap)),
63  __classMap(std::move(src.__classMap)),
64  __nodeMap(std::move(src.__nodeMap)), __dag(std::move(src.__dag)),
65  __o3Classes(std::move(src.__o3Classes)) {
66  GUM_CONS_MOV(O3ClassFactory);
67  }
HashTable< std::string, gum::NodeId > __nameMap
O3ClassFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
HashTable< NodeId, O3Class * > __nodeMap
HashTable< std::string, O3Class * > __classMap
std::vector< O3Class * > __o3Classes
O3NameSolver< GUM_SCALAR > * __solver
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::~O3ClassFactory ( )

Definition at line 70 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::operator=().

70  {
71  GUM_DESTRUCTOR(O3ClassFactory);
72  }
O3ClassFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

+ Here is the call graph for this function:

Member Function Documentation

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addParameters ( PRMFactory< GUM_SCALAR > &  factory,
O3Class c 
)
private

Definition at line 320 of file O3ClassFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addParameter(), gum::prm::o3prm::O3Parameter::FLOAT, GUM_ERROR, gum::prm::o3prm::O3Parameter::INT, and gum::prm::o3prm::O3Class::parameters().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters().

321  {
322  for (auto& p : c.parameters()) {
323  switch (p.type()) {
325  factory.addParameter("int", p.name().label(), p.value().value());
326  break;
327  }
328 
330  factory.addParameter("real", p.name().label(), p.value().value());
331  break;
332  }
333 
334  default: { GUM_ERROR(FatalError, "unknown O3Parameter type"); }
335  }
336  }
337  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addParamsToForms ( const HashTable< std::string, const PRMParameter< GUM_SCALAR > * > &  scope,
O3RuleCPT::O3Rule rule 
)
private

Definition at line 708 of file O3ClassFactory_tpl.h.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPT().

710  {
711  // Add parameters to formulas
712  for (auto& f : rule.second) {
713  f.formula().variables().clear();
714  for (const auto& values : scope) {
715  f.formula().variables().insert(values.first, values.second->value());
716  }
717  }
718  }

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addReferenceSlots ( O3Class c)
private

Definition at line 349 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkReferenceSlot(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::addReferenceSlot(), gum::prm::PRMFactory< GUM_SCALAR >::continueClass(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Class::name(), and gum::prm::o3prm::O3Class::referenceSlots().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildReferenceSlots().

349  {
350  PRMFactory< GUM_SCALAR > factory(__prm);
351 
352  factory.continueClass(c.name().label());
353 
354  // References
355  for (auto& ref : c.referenceSlots()) {
356  if (__checkReferenceSlot(c, ref)) {
357  factory.addReferenceSlot(
358  ref.type().label(), ref.name().label(), ref.isArray());
359  }
360  }
361 
362  factory.endClass(false);
363  }
bool __checkReferenceSlot(O3Class &c, O3ReferenceSlot &ref)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggParameters ( O3Class o3class,
O3Aggregate agg,
const PRMType< GUM_SCALAR > *  t 
)
private

Definition at line 985 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParametersNumber(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParameterValue(), gum::prm::o3prm::O3Aggregate::aggregateType(), GUM_ERROR, and gum::prm::o3prm::O3Label::label().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggregateForCompletion().

986  {
987  bool ok = false;
988 
990  agg.aggregateType().label())) {
997  ok = __checkParametersNumber(agg, 0);
998  break;
999  }
1000 
1004  ok = __checkParametersNumber(agg, 1);
1005  break;
1006  }
1007 
1008  default: { GUM_ERROR(FatalError, "unknown aggregate type"); }
1009  }
1010 
1011  if (!ok) { return false; }
1012 
1013  // Checking parameters type
1015  agg.aggregateType().label())) {
1019  ok = __checkParameterValue(agg, *t);
1020  break;
1021  }
1022 
1023  default: { /* Nothing to do */
1024  }
1025  }
1026 
1027  return ok;
1028  }
bool __checkParameterValue(O3Aggregate &agg, const gum::prm::PRMType< GUM_SCALAR > &t)
bool __checkParametersNumber(O3Aggregate &agg, Size n)
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const PRMType< GUM_SCALAR > * gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggParents ( O3Class o3class,
O3Aggregate agg 
)
private

Definition at line 932 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__resolveSlotChain(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Class::name(), and gum::prm::o3prm::O3Aggregate::parents().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggregateForCompletion().

933  {
934  const auto& c = __prm->getClass(o3class.name().label());
935  auto t = (const PRMType< GUM_SCALAR >*)nullptr;
936 
937  for (const auto& prnt : agg.parents()) {
938  auto elt = __resolveSlotChain(c, prnt);
939 
940  if (elt == nullptr) {
941  O3PRM_CLASS_PARENT_NOT_FOUND(prnt, *__errors);
942  return nullptr;
943 
944  } else {
945  if (t == nullptr) {
946  try {
947  t = &(elt->type());
948 
949  } catch (OperationNotAllowed&) {
950  O3PRM_CLASS_WRONG_PARENT(prnt, *__errors);
951  return nullptr;
952  }
953 
954  } else if ((*t) != elt->type()) {
955  // Wront type in chain
956  O3PRM_CLASS_WRONG_PARENT_TYPE(
957  prnt, t->name(), elt->type().name(), *__errors);
958  return nullptr;
959  }
960  }
961  }
962  return t;
963  }
const PRMClassElement< GUM_SCALAR > * __resolveSlotChain(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggregateForCompletion ( O3Class o3class,
O3Aggregate agg 
)
private

Definition at line 557 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggParameters(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggParents().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAggregates().

558  {
559  // Checking parents
560  auto t = __checkAggParents(c, agg);
561  if (t == nullptr) { return false; }
562 
563  // Checking parameters numbers
564  if (!__checkAggParameters(c, agg, t)) { return false; }
565 
566  return true;
567  }
const PRMType< GUM_SCALAR > * __checkAggParents(O3Class &o3class, O3Aggregate &agg)
bool __checkAggParameters(O3Class &o3class, O3Aggregate &agg, const PRMType< GUM_SCALAR > *t)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggregateForDeclaration ( O3Class o3class,
O3Aggregate agg 
)
private

Definition at line 920 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggTypeLegality(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, and gum::prm::o3prm::O3Aggregate::variableType().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAggregates().

921  {
922  if (!__solver->resolveType(agg.variableType())) { return false; }
923 
924  // Checking type legality if overload
925  if (!__checkAggTypeLegality(o3class, agg)) { return false; }
926 
927  return true;
928  }
bool __checkAggTypeLegality(O3Class &o3class, O3Aggregate &agg)
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggTypeLegality ( O3Class o3class,
O3Aggregate agg 
)
private

Definition at line 967 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Aggregate::name(), gum::prm::o3prm::O3Class::superLabel(), and gum::prm::o3prm::O3Aggregate::variableType().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggregateForDeclaration().

968  {
969  if (__prm->isClass(o3class.superLabel().label())) {
970  const auto& super = __prm->getClass(o3class.superLabel().label());
971  const auto& agg_type = __prm->type(agg.variableType().label());
972 
973  if (super.exists(agg.name().label())
974  && !agg_type.isSubTypeOf(super.get(agg.name().label()).type())) {
975  O3PRM_CLASS_ILLEGAL_OVERLOAD(
976  agg.name(), o3class.superLabel(), *__errors);
977  return false;
978  }
979  }
980 
981  return true;
982  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAndAddArcsToDag ( )
private

Definition at line 165 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__dag, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, gum::DAG::addArc(), and gum::prm::o3prm::O3PRM::classes().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkO3Classes().

165  {
166  for (auto& c : __o3_prm->classes()) {
167  if (c->superLabel().label() != "") {
168  if (!__solver->resolveClass(c->superLabel())) { return false; }
169 
170  auto head = __nameMap[c->superLabel().label()];
171  auto tail = __nameMap[c->name().label()];
172 
173  try {
174  __dag.addArc(tail, head);
175  } catch (InvalidDirectedCycle&) {
176  // Cyclic inheritance
177  O3PRM_CLASS_CYLIC_INHERITANCE(c->name(), c->superLabel(), *__errors);
178  return false;
179  }
180  }
181  }
182 
183  return true;
184  }
O3ClassList & classes()
Definition: O3prm.cpp:501
HashTable< std::string, gum::NodeId > __nameMap
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:40
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAndAddNodesToDag ( )
private

Definition at line 146 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__classMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__dag, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nodeMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3_prm, gum::NodeGraphPart::addNode(), gum::prm::o3prm::O3PRM::classes(), and gum::HashTable< Key, Val, Alloc >::insert().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkO3Classes().

146  {
147  for (auto& c : __o3_prm->classes()) {
148  auto id = __dag.addNode();
149 
150  try {
151  __nameMap.insert(c->name().label(), id);
152  __classMap.insert(c->name().label(), c.get());
153  __nodeMap.insert(id, c.get());
154 
155  } catch (DuplicateElement&) {
156  O3PRM_CLASS_DUPLICATE(c->name(), *__errors);
157  return false;
158  }
159  }
160 
161  return true;
162  }
O3ClassList & classes()
Definition: O3prm.cpp:501
virtual NodeId addNode()
insert a new node and return its id
HashTable< std::string, gum::NodeId > __nameMap
HashTable< NodeId, O3Class * > __nodeMap
HashTable< std::string, O3Class * > __classMap
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAttributeForCompletion ( const O3Class o3_c,
O3Attribute attr 
)
private

Definition at line 615 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParent(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRawCPT(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPT(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Class::name(), and gum::prm::o3prm::O3Attribute::parents().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAttribute().

616  {
617  // Check for parents existence
618  const auto& c = __prm->getClass(o3_c.name().label());
619  for (auto& prnt : attr.parents()) {
620  if (!__checkParent(c, prnt)) { return false; }
621  }
622 
623  // Check that CPT sums to 1
624  auto raw = dynamic_cast< O3RawCPT* >(&attr);
625  if (raw) { return __checkRawCPT(c, *raw); }
626 
627  auto rule = dynamic_cast< O3RuleCPT* >(&attr);
628  if (rule) { return __checkRuleCPT(c, *rule); }
629 
630  return true;
631  }
bool __checkRawCPT(const PRMClass< GUM_SCALAR > &c, O3RawCPT &attr)
bool __checkParent(const PRMClass< GUM_SCALAR > &c, const O3Label &prnt)
bool __checkRuleCPT(const PRMClass< GUM_SCALAR > &c, O3RuleCPT &attr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAttributeForDeclaration ( O3Class o3_c,
O3Attribute attr 
)
private

Definition at line 459 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Attribute::name(), gum::prm::o3prm::O3Class::superLabel(), and gum::prm::o3prm::O3Attribute::type().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAttribute().

460  {
461  // Check type
462  if (!__solver->resolveType(attr.type())) { return false; }
463 
464  // Checking type legality if overload
465  if (c.superLabel().label() != "") {
466  const auto& super = __prm->getClass(c.superLabel().label());
467 
468  if (!super.exists(attr.name().label())) { return true; }
469 
470  const auto& super_type = super.get(attr.name().label()).type();
471  const auto& type = __prm->type(attr.type().label());
472 
473  if (!type.isSubTypeOf(super_type)) {
474  O3PRM_CLASS_ILLEGAL_OVERLOAD(attr.name(), c.superLabel(), *__errors);
475  return false;
476  }
477  }
478  return true;
479  }
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkImplementation ( O3Class c)
private

Definition at line 200 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, gum::prm::o3prm::O3Class::aggregates(), gum::prm::o3prm::O3Class::attributes(), gum::HashTable< Key, Val, Alloc >::exists(), gum::prm::o3prm::O3Class::interfaces(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Class::name(), and gum::prm::o3prm::O3Class::referenceSlots().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildImplementations().

200  {
201  // Saving attributes names for fast lookup
202  auto attr_map = AttrMap();
203  for (auto& a : c.attributes()) {
204  attr_map.insert(a->name().label(), a.get());
205  }
206 
207  // Saving aggregates names for fast lookup
208  auto agg_map = AggMap();
209  for (auto& agg : c.aggregates()) {
210  agg_map.insert(agg.name().label(), &agg);
211  }
212 
213  auto ref_map = RefMap();
214  for (auto& ref : c.referenceSlots()) {
215  ref_map.insert(ref.name().label(), &ref);
216  }
217 
218  // Cheking interface implementation
219  for (auto& i : c.interfaces()) {
220  if (__solver->resolveInterface(i)) {
221  if (!__checkImplementation(c, i, attr_map, agg_map, ref_map)) {
222  return false;
223  }
224  }
225  }
226 
227  return true;
228  }
HashTable< std::string, O3Attribute * > AttrMap
HashTable< std::string, O3Aggregate * > AggMap
HashTable< std::string, O3ReferenceSlot * > RefMap
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkImplementation ( O3Class c,
O3Label i,
HashTable< std::string, O3Attribute * > &  attrMap,
HashTable< std::string, O3Aggregate * > &  aggMap,
HashTable< std::string, O3ReferenceSlot * > &  refMap 
)
private
template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkImplementation ( O3Label o3_type,
const PRMType< GUM_SCALAR > &  type 
)
private

Definition at line 285 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, and gum::prm::o3prm::O3Label::label().

286  {
287  if (!__solver->resolveType(o3_type)) { return false; }
288 
289  return __prm->type(o3_type.label()).isSubTypeOf(type);
290  }
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkImplementation ( O3Label o3_type,
const PRMClassElementContainer< GUM_SCALAR > &  type 
)
private

Definition at line 293 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, and gum::prm::o3prm::O3Label::label().

294  {
295  if (!__solver->resolveSlotType(o3_type)) { return false; }
296 
297  if (__prm->isInterface(o3_type.label())) {
298  return __prm->getInterface(o3_type.label()).isSubTypeOf(type);
299  } else {
300  return __prm->getClass(o3_type.label()).isSubTypeOf(type);
301  }
302  }
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkLabelsNumber ( const O3RuleCPT attr,
const O3RuleCPT::O3Rule rule 
)
private

Definition at line 671 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, and gum::prm::o3prm::O3Attribute::parents().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPT().

672  {
673  // Check that the number of labels is correct
674  if (rule.first.size() != attr.parents().size()) {
675  O3PRM_CLASS_ILLEGAL_RULE_SIZE(
676  rule, rule.first.size(), attr.parents().size(), *__errors);
677  return false;
678  }
679  return true;
680  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkLabelsValues ( const PRMClass< GUM_SCALAR > &  c,
const O3RuleCPT attr,
const O3RuleCPT::O3Rule rule 
)
private

Definition at line 683 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__resolveSlotChain(), and gum::prm::o3prm::O3Attribute::parents().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPT().

686  {
687  bool errors = false;
688  for (std::size_t i = 0; i < attr.parents().size(); ++i) {
689  auto label = rule.first[i];
690  auto prnt = attr.parents()[i];
691  try {
692  auto real_labels = __resolveSlotChain(c, prnt)->type()->labels();
693  // c.get(prnt.label()).type()->labels();
694  if (label.label() != "*"
695  && std::find(real_labels.begin(), real_labels.end(), label.label())
696  == real_labels.end()) {
697  O3PRM_CLASS_ILLEGAL_RULE_LABEL(rule, label, prnt, *__errors);
698  errors = true;
699  }
700  } catch (Exception& e) {
701  // parent does not exists and is already reported
702  }
703  }
704  return errors == false;
705  }
const PRMClassElement< GUM_SCALAR > * __resolveSlotChain(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkLocalParent ( const PRMClass< GUM_SCALAR > &  c,
const O3Label prnt 
)
private

Definition at line 645 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), and gum::prm::o3prm::O3Label::label().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParent().

646  {
647  if (!c.exists(prnt.label())) {
648  O3PRM_CLASS_PARENT_NOT_FOUND(prnt, *__errors);
649  return false;
650  }
651 
652  const auto& elt = c.get(prnt.label());
656  O3PRM_CLASS_ILLEGAL_PARENT(prnt, *__errors);
657  return false;
658  }
659 
660  return true;
661  }
Abstract class representing an element of PRM class.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkO3Classes ( )
private

Definition at line 141 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAndAddArcsToDag(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAndAddNodesToDag().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParametersNumber ( O3Aggregate agg,
Size  n 
)
private

Definition at line 1032 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3Aggregate::name(), and gum::prm::o3prm::O3Aggregate::parameters().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggParameters().

1033  {
1034  if (agg.parameters().size() != n) {
1035  O3PRM_CLASS_AGG_PARAMETERS(
1036  agg.name(), Size(n), Size(agg.parameters().size()), *__errors);
1037  return false;
1038  }
1039 
1040  return true;
1041  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParameterValue ( O3Aggregate agg,
const gum::prm::PRMType< GUM_SCALAR > &  t 
)
private

Definition at line 1044 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3Aggregate::name(), gum::prm::o3prm::O3Aggregate::parameters(), and gum::prm::PRMType< GUM_SCALAR >::variable().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggParameters().

1045  {
1046  const auto& param = agg.parameters().front();
1047  bool found = false;
1048  for (Size idx = 0; idx < t.variable().domainSize(); ++idx) {
1049  if (t.variable().label(idx) == param.label()) {
1050  found = true;
1051  break;
1052  }
1053  }
1054 
1055  if (!found) {
1056  O3PRM_CLASS_AGG_PARAMETER_NOT_FOUND(agg.name(), param, *__errors);
1057  return false;
1058  }
1059 
1060  return true;
1061  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
Definition: PRMType_tpl.h:135

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParent ( const PRMClass< GUM_SCALAR > &  c,
const O3Label prnt 
)
private

Definition at line 634 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkLocalParent(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRemoteParent(), and gum::prm::o3prm::O3Label::label().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAttributeForCompletion().

635  {
636  if (prnt.label().find('.') == std::string::npos) {
637  return __checkLocalParent(c, prnt);
638 
639  } else {
640  return __checkRemoteParent(c, prnt);
641  }
642  }
bool __checkLocalParent(const PRMClass< GUM_SCALAR > &c, const O3Label &prnt)
bool __checkRemoteParent(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &prnt)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRawCPT ( const PRMClass< GUM_SCALAR > &  c,
O3RawCPT attr 
)
private

Definition at line 776 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__resolveSlotChain(), gum::prm::PRMClass< GUM_SCALAR >::get(), gum::prm::o3prm::O3Label::label(), gum::prm::PRMObject::name(), gum::prm::o3prm::O3Attribute::name(), gum::prm::o3prm::O3Attribute::parents(), gum::prm::PRMClass< GUM_SCALAR >::scope(), gum::prm::o3prm::O3Attribute::type(), and gum::prm::o3prm::O3RawCPT::values().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAttributeForCompletion().

777  {
778  const auto& type = __prm->type(attr.type().label());
779 
780  auto domainSize = type->domainSize();
781  for (auto& prnt : attr.parents()) {
782  try {
783  domainSize *= c.get(prnt.label()).type()->domainSize();
784  } catch (NotFound&) {
785  // If we are here, all parents have been check so __resolveSlotChain
786  // will not raise an error and not return a nullptr
787  domainSize *= __resolveSlotChain(c, prnt)->type()->domainSize();
788  }
789  }
790 
791  // Check for CPT size
792  if (domainSize != attr.values().size()) {
793  O3PRM_CLASS_ILLEGAL_CPT_SIZE(c.name(),
794  attr.name(),
795  Size(attr.values().size()),
796  domainSize,
797  *__errors);
798  return false;
799  }
800 
801  // Add parameters to formulas
802  const auto& scope = c.scope();
803  for (auto& f : attr.values()) {
804  f.formula().variables().clear();
805 
806  for (const auto& values : scope) {
807  f.formula().variables().insert(values.first, values.second->value());
808  }
809  }
810 
811  // Check that CPT sums to 1
812  Size parent_size = domainSize / type->domainSize();
813  auto values = std::vector< GUM_SCALAR >(parent_size, 0.0f);
814 
815  for (std::size_t i = 0; i < attr.values().size(); ++i) {
816  try {
817  auto idx = i % parent_size;
818  auto val = (GUM_SCALAR)attr.values()[i].formula().result();
819  values[idx] += val;
820 
821  if (val < 0.0 || 1.0 < val) {
822  O3PRM_CLASS_ILLEGAL_CPT_VALUE(
823  c.name(), attr.name(), attr.values()[i], *__errors);
824  return false;
825  }
826  } catch (Exception&) {
827  O3PRM_CLASS_ILLEGAL_CPT_VALUE(
828  c.name(), attr.name(), attr.values()[i], *__errors);
829  return false;
830  }
831  }
832 
833  for (auto f : values) {
834  if (std::abs(f - GUM_SCALAR(1.0)) > 1.0e-3) {
835  O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1(
836  c.name(), attr.name(), float(f), *__errors);
837  return false;
838  } else if (std::abs(f - GUM_SCALAR(1.0)) > 1.0e-6) {
839  O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1_WARNING(
840  c.name(), attr.name(), float(f), *__errors);
841  }
842  }
843  return true;
844  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
const PRMClassElement< GUM_SCALAR > * __resolveSlotChain(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkReferenceSlot ( O3Class c,
O3ReferenceSlot ref 
)
private

Definition at line 367 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3ReferenceSlot::name(), gum::prm::o3prm::O3Class::name(), and gum::prm::o3prm::O3ReferenceSlot::type().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addReferenceSlots().

368  {
369  if (!__solver->resolveSlotType(ref.type())) { return false; }
370 
371  const auto& real_c = __prm->getClass(c.name().label());
372 
373  // Check for dupplicates
374  if (real_c.exists(ref.name().label())) {
375  const auto& elt = real_c.get(ref.name().label());
376 
378  auto slot_type = (PRMClassElementContainer< GUM_SCALAR >*)nullptr;
379 
380  if (__prm->isInterface(ref.type().label())) {
381  slot_type = &(__prm->getInterface(ref.type().label()));
382 
383  } else {
384  slot_type = &(__prm->getClass(ref.type().label()));
385  }
386 
387  auto real_ref =
388  static_cast< const PRMReferenceSlot< GUM_SCALAR >* >(&elt);
389 
390  if (slot_type->name() == real_ref->slotType().name()) {
391  O3PRM_CLASS_DUPLICATE_REFERENCE(ref.name(), *__errors);
392  return false;
393 
394  } else if (!slot_type->isSubTypeOf(real_ref->slotType())) {
395  O3PRM_CLASS_ILLEGAL_OVERLOAD(ref.name(), c.name(), *__errors);
396  return false;
397  }
398 
399  } else {
400  O3PRM_CLASS_DUPLICATE_REFERENCE(ref.name(), *__errors);
401  return false;
402  }
403  }
404 
405  // If class we need to check for illegal references
406  if (__prm->isClass(ref.type().label())) {
407  const auto& ref_type = __prm->getClass(ref.type().label());
408 
409  // No recursive reference
410  if ((&ref_type) == (&real_c)) {
411  O3PRM_CLASS_SELF_REFERENCE(c.name(), ref.name(), *__errors);
412  return false;
413  }
414 
415  // No reference to subclasses
416  if (ref_type.isSubTypeOf(real_c)) {
417  O3PRM_CLASS_ILLEGAL_SUB_REFERENCE(c.name(), ref.type(), *__errors);
418  return false;
419  }
420  }
421 
422  return true;
423  }
static INLINE bool isReferenceSlot(const PRMClassElement &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRemoteParent ( const PRMClassElementContainer< GUM_SCALAR > &  c,
const O3Label prnt 
)
private

Definition at line 664 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__resolveSlotChain().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkParent().

665  {
666  if (__resolveSlotChain(c, prnt) == nullptr) { return false; }
667  return true;
668  }
const PRMClassElement< GUM_SCALAR > * __resolveSlotChain(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPT ( const PRMClass< GUM_SCALAR > &  c,
O3RuleCPT attr 
)
private

Definition at line 756 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addParamsToForms(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkLabelsNumber(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkLabelsValues(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPTSumsTo1(), GUM_SHOWERROR, gum::prm::o3prm::O3RuleCPT::rules(), and gum::prm::PRMClass< GUM_SCALAR >::scope().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAttributeForCompletion().

757  {
758  const auto& scope = c.scope();
759  bool errors = false;
760  for (auto& rule : attr.rules()) {
761  try {
762  if (!__checkLabelsNumber(attr, rule)) { errors = true; }
763  if (!__checkLabelsValues(c, attr, rule)) { errors = true; }
764  __addParamsToForms(scope, rule);
765  if (!__checkRuleCPTSumsTo1(c, attr, rule)) { errors = true; }
766  } catch (Exception& e) {
767  GUM_SHOWERROR(e);
768  errors = true;
769  }
770  }
771 
772  return errors == false;
773  }
bool __checkLabelsValues(const PRMClass< GUM_SCALAR > &c, const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
void __addParamsToForms(const HashTable< std::string, const PRMParameter< GUM_SCALAR > * > &scope, O3RuleCPT::O3Rule &rule)
#define GUM_SHOWERROR(e)
Definition: exceptions.h:73
bool __checkLabelsNumber(const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
bool __checkRuleCPTSumsTo1(const PRMClass< GUM_SCALAR > &c, const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPTSumsTo1 ( const PRMClass< GUM_SCALAR > &  c,
const O3RuleCPT attr,
const O3RuleCPT::O3Rule rule 
)
private

Definition at line 722 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::PRMObject::name(), and gum::prm::o3prm::O3Attribute::name().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRuleCPT().

725  {
726  bool errors = false;
727  // Check that formulas are valid and sums to 1
728  GUM_SCALAR sum = 0.0;
729  for (const auto& f : rule.second) {
730  try {
731  auto value = GUM_SCALAR(f.formula().result());
732  sum += value;
733  if (value < 0.0 || 1.0 < value) {
734  O3PRM_CLASS_ILLEGAL_CPT_VALUE(c.name(), attr.name(), f, *__errors);
735  errors = true;
736  }
737  } catch (OperationNotAllowed&) {
738  O3PRM_CLASS_ILLEGAL_CPT_VALUE(c.name(), attr.name(), f, *__errors);
739  errors = true;
740  }
741  }
742 
743  // Check that CPT sums to 1
744  if (std::abs(sum - 1.0) > 1e-3) {
745  O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1(
746  c.name(), attr.name(), float(sum), *__errors);
747  errors = true;
748  } else if (std::abs(sum - 1.0f) > 1e-6) {
749  O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1_WARNING(
750  c.name(), attr.name(), float(sum), *__errors);
751  }
752  return errors == false;
753  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkSlotChainLink ( const PRMClassElementContainer< GUM_SCALAR > &  c,
const O3Label chain,
const std::string &  s 
)
private

Definition at line 885 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, and gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__resolveSlotChain().

888  {
889  if (!c.exists(s)) {
890  O3PRM_CLASS_LINK_NOT_FOUND(chain, s, *__errors);
891  return false;
892  }
893  return true;
894  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAggregates ( PRMFactory< GUM_SCALAR > &  factory,
O3Class c 
)
private

Definition at line 540 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggregateForCompletion(), gum::prm::PRMFactory< GUM_SCALAR >::addParent(), gum::prm::o3prm::O3Class::aggregates(), gum::prm::PRMFactory< GUM_SCALAR >::continueAggregator(), and gum::prm::PRMFactory< GUM_SCALAR >::endAggregator().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates().

541  {
542  // Attributes
543  for (auto& agg : c.aggregates()) {
544  if (__checkAggregateForCompletion(c, agg)) {
545  factory.continueAggregator(agg.name().label());
546 
547  for (const auto& parent : agg.parents()) {
548  factory.addParent(parent.label());
549  }
550 
551  factory.endAggregator();
552  }
553  }
554  }
bool __checkAggregateForCompletion(O3Class &o3class, O3Aggregate &agg)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAttribute ( PRMFactory< GUM_SCALAR > &  factory,
O3Class c 
)
private

Definition at line 570 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAttributeForCompletion(), gum::prm::PRMFactory< GUM_SCALAR >::addParent(), gum::prm::o3prm::O3Class::attributes(), gum::prm::PRMFactory< GUM_SCALAR >::continueAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::endAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes().

571  {
572  // Attributes
573  for (auto& attr : c.attributes()) {
574  if (__checkAttributeForCompletion(c, *attr)) {
575  factory.continueAttribute(attr->name().label());
576 
577  for (const auto& parent : attr->parents()) {
578  factory.addParent(parent.label());
579  }
580 
581  auto raw = dynamic_cast< const O3RawCPT* >(attr.get());
582 
583  if (raw) {
584  auto values = std::vector< std::string >();
585  for (const auto& val : raw->values()) {
586  values.push_back(val.formula().formula());
587  }
588  factory.setRawCPFByColumns(values);
589  }
590 
591  auto rule_cpt = dynamic_cast< const O3RuleCPT* >(attr.get());
592  if (rule_cpt) {
593  for (const auto& rule : rule_cpt->rules()) {
594  auto labels = std::vector< std::string >();
595  auto values = std::vector< std::string >();
596 
597  for (const auto& lbl : rule.first) {
598  labels.push_back(lbl.label());
599  }
600 
601  for (const auto& form : rule.second) {
602  values.push_back(form.formula().formula());
603  }
604 
605  factory.setCPFByRule(labels, values);
606  }
607  }
608 
609  factory.endAttribute();
610  }
611  }
612  }
bool __checkAttributeForCompletion(const O3Class &o3_c, O3Attribute &attr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAggregates ( O3Class c)
private

Definition at line 897 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggregateForDeclaration(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Class::aggregates(), gum::prm::PRMFactory< GUM_SCALAR >::continueClass(), gum::prm::PRMFactory< GUM_SCALAR >::endAggregator(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Class::name(), and gum::prm::PRMFactory< GUM_SCALAR >::startAggregator().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAggregates().

897  {
898  PRMFactory< GUM_SCALAR > factory(__prm);
899  factory.continueClass(c.name().label());
900 
901  for (auto& agg : c.aggregates()) {
902  if (__checkAggregateForDeclaration(c, agg)) {
903  auto params = std::vector< std::string >();
904  for (auto& p : agg.parameters()) {
905  params.push_back(p.label());
906  }
907 
908  factory.startAggregator(agg.name().label(),
909  agg.aggregateType().label(),
910  agg.variableType().label(),
911  params);
912  factory.endAggregator();
913  }
914  }
915 
916  factory.endClass(false);
917  }
bool __checkAggregateForDeclaration(O3Class &o3class, O3Aggregate &agg)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAttribute ( O3Class c)
private

Definition at line 444 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAttributeForDeclaration(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Class::attributes(), gum::prm::PRMFactory< GUM_SCALAR >::continueClass(), gum::prm::PRMFactory< GUM_SCALAR >::endAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Class::name(), and gum::prm::PRMFactory< GUM_SCALAR >::startAttribute().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAttributes().

444  {
445  PRMFactory< GUM_SCALAR > factory(__prm);
446  factory.continueClass(c.name().label());
447 
448  for (auto& attr : c.attributes()) {
449  if (__checkAttributeForDeclaration(c, *attr)) {
450  factory.startAttribute(attr->type().label(), attr->name().label());
451  factory.endAttribute();
452  }
453  }
454 
455  factory.endClass(false);
456  }
bool __checkAttributeForDeclaration(O3Class &o3_c, O3Attribute &attr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const PRMClassElement< GUM_SCALAR > * gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__resolveSlotChain ( const PRMClassElementContainer< GUM_SCALAR > &  c,
const O3Label chain 
)
private

Definition at line 848 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkSlotChainLink(), gum::prm::decomposePath(), and gum::prm::o3prm::O3Label::label().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAggParents(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkLabelsValues(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRawCPT(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkRemoteParent().

849  {
850  auto s = chain.label();
851  auto current = &c;
852  std::vector< std::string > v;
853 
854  decomposePath(chain.label(), v);
855 
856  for (size_t i = 0; i < v.size(); ++i) {
857  auto link = v[i];
858 
859  if (!__checkSlotChainLink(*current, chain, link)) { return nullptr; }
860 
861  auto elt = &(current->get(link));
862 
863  if (i == v.size() - 1) {
864  // last link, should be an attribute or aggregate
865  return elt;
866 
867  } else {
868  // should be a reference slot
869 
870  auto ref = dynamic_cast< const PRMReferenceSlot< GUM_SCALAR >* >(elt);
871  if (ref) {
872  current = &(ref->slotType());
873  } else {
874  return nullptr; // failsafe to prevent infinite loop
875  }
876  }
877  }
878 
879  // Encountered only reference slots
880 
881  return nullptr;
882  }
bool __checkSlotChainLink(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain, const std::string &s)
void decomposePath(const std::string &path, std::vector< std::string > &v)
Decompose a string in a vector of strings using "." as separators.
Definition: utils_prm.cpp:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__setO3ClassCreationOrder ( )
private

Definition at line 132 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__dag, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nodeMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, and gum::DiGraph::topologicalOrder().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses().

132  {
133  auto topo_order = __dag.topologicalOrder();
134 
135  for (auto id = topo_order.rbegin(); id != topo_order.rend(); --id) {
136  __o3Classes.push_back(__nodeMap[*id]);
137  }
138  }
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Definition: diGraph.cpp:88
HashTable< NodeId, O3Class * > __nodeMap
std::vector< O3Class * > __o3Classes

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses ( )

Definition at line 107 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkO3Classes(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__setO3ClassCreationOrder(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver, gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::Set< Key, Alloc >::insert(), and gum::prm::PRMFactory< GUM_SCALAR >::startClass().

107  {
108  PRMFactory< GUM_SCALAR > factory(__prm);
109 
110  // Class with a super class must be declared after
111  if (__checkO3Classes()) {
113 
114  for (auto c : __o3Classes) {
115  // Soving interfaces
116  auto implements = Set< std::string >();
117  for (auto& i : c->interfaces()) {
118  if (__solver->resolveInterface(i)) { implements.insert(i.label()); }
119  }
120 
121  // Adding the class
122  if (__solver->resolveClass(c->superLabel())) {
123  factory.startClass(
124  c->name().label(), c->superLabel().label(), &implements, true);
125  factory.endClass(false);
126  }
127  }
128  }
129  }
std::vector< O3Class * > __o3Classes
O3NameSolver< GUM_SCALAR > * __solver
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildImplementations ( )

Definition at line 187 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkImplementation(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3PRM::classes().

187  {
188  for (auto& c : __o3_prm->classes()) {
189  if (__checkImplementation(*c)) {
190  __prm->getClass(c->name().label()).initializeInheritance();
191  }
192  }
193  }
O3ClassList & classes()
Definition: O3prm.cpp:501

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters ( )

Definition at line 305 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addParameters(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::continueClass(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::prm::o3prm::O3Label::label(), and gum::prm::o3prm::O3Class::name().

305  {
306  PRMFactory< GUM_SCALAR > factory(__prm);
307  // Class with a super class must be declared after
308  for (auto c : __o3Classes) {
309  __prm->getClass(c->name().label()).inheritParameters();
310 
311  factory.continueClass(c->name().label());
312 
313  __addParameters(factory, *c);
314 
315  factory.endClass(false);
316  }
317  }
std::vector< O3Class * > __o3Classes
void __addParameters(PRMFactory< GUM_SCALAR > &factory, O3Class &c)

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildReferenceSlots ( )

Definition at line 340 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addReferenceSlots(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Label::label(), and gum::prm::o3prm::O3Class::name().

340  {
341  // Class with a super class must be declared after
342  for (auto c : __o3Classes) {
343  __prm->getClass(c->name().label()).inheritReferenceSlots();
345  }
346  }
std::vector< O3Class * > __o3Classes

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates ( )

Definition at line 526 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAggregates(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::continueClass(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::prm::o3prm::O3Label::label(), and gum::prm::o3prm::O3Class::name().

526  {
527  PRMFactory< GUM_SCALAR > factory(__prm);
528 
529  // Class with a super class must be declared in order
530  for (auto c : __o3Classes) {
531  factory.continueClass(c->name().label());
532 
533  __completeAggregates(factory, *c);
534 
535  factory.endClass(false);
536  }
537  }
void __completeAggregates(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
std::vector< O3Class * > __o3Classes

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes ( )

Definition at line 482 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAttribute(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Class::aggregates(), gum::prm::o3prm::O3Class::attributes(), gum::prm::PRMFactory< GUM_SCALAR >::continueClass(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::Set< Key, Alloc >::insert(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Class::name(), and gum::prm::o3prm::O3Class::superLabel().

482  {
483  PRMFactory< GUM_SCALAR > factory(__prm);
484 
485  // Class with a super class must be declared in order
486  for (auto c : __o3Classes) {
487  __prm->getClass(c->name().label()).inheritSlotChains();
488  factory.continueClass(c->name().label());
489 
490  __completeAttribute(factory, *c);
491 
492  if (c->superLabel().label() != "") {
493  auto& super = __prm->getClass(c->superLabel().label());
494  auto to_complete = Set< std::string >();
495 
496  for (auto a : super.attributes()) {
497  to_complete.insert(a->safeName());
498  }
499 
500  for (auto a : super.aggregates()) {
501  to_complete.insert(a->safeName());
502  }
503 
504  for (auto& a : c->attributes()) {
505  to_complete.erase(__prm->getClass(c->name().label())
506  .get(a->name().label())
507  .safeName());
508  }
509 
510  for (auto& a : c->aggregates()) {
511  to_complete.erase(__prm->getClass(c->name().label())
512  .get(a.name().label())
513  .safeName());
514  }
515 
516  for (auto a : to_complete) {
517  __prm->getClass(c->name().label()).completeInheritance(a);
518  }
519  }
520 
521  factory.endClass(true);
522  }
523  }
void __completeAttribute(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
std::vector< O3Class * > __o3Classes
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAggregates ( )

Definition at line 435 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAggregates(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Label::label(), and gum::prm::o3prm::O3Class::name().

435  {
436  // Class with a super class must be declared after
437  for (auto c : __o3Classes) {
438  __prm->getClass(c->name().label()).inheritAggregates();
440  }
441  }
std::vector< O3Class * > __o3Classes

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAttributes ( )

Definition at line 426 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAttribute(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3Label::label(), and gum::prm::o3prm::O3Class::name().

426  {
427  // Class with a super class must be declared after
428  for (auto c : __o3Classes) {
429  __prm->getClass(c->name().label()).inheritAttributes();
430  __declareAttribute(*c);
431  }
432  }
std::vector< O3Class * > __o3Classes

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE O3ClassFactory< GUM_SCALAR > & gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::operator= ( const O3ClassFactory< GUM_SCALAR > &  src)

Definition at line 76 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__classMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__dag, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nodeMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::~O3ClassFactory().

76  {
77  if (this == &src) { return *this; }
78  __prm = src.__prm;
79  __o3_prm = src.__o3_prm;
80  __solver = src.__solver;
81  __errors = src.__errors;
82  __nameMap = src.__nameMap;
83  __classMap = src.__classMap;
84  __nodeMap = src.__nodeMap;
85  __dag = src.__dag;
86  __o3Classes = src.__o3Classes;
87  return *this;
88  }
HashTable< std::string, gum::NodeId > __nameMap
HashTable< NodeId, O3Class * > __nodeMap
HashTable< std::string, O3Class * > __classMap
std::vector< O3Class * > __o3Classes
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE O3ClassFactory< GUM_SCALAR > & gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::operator= ( O3ClassFactory< GUM_SCALAR > &&  src)

Definition at line 92 of file O3ClassFactory_tpl.h.

References gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__classMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__dag, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__nodeMap, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__o3Classes, gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__solver.

92  {
93  if (this == &src) { return *this; }
94  __prm = std::move(src.__prm);
95  __o3_prm = std::move(src.__o3_prm);
96  __solver = std::move(src.__solver);
97  __errors = std::move(src.__errors);
98  __nameMap = std::move(src.__nameMap);
99  __classMap = std::move(src.__classMap);
100  __nodeMap = std::move(src.__nodeMap);
101  __dag = std::move(src.__dag);
102  __o3Classes = std::move(src.__o3Classes);
103  return *this;
104  }
HashTable< std::string, gum::NodeId > __nameMap
HashTable< NodeId, O3Class * > __nodeMap
HashTable< std::string, O3Class * > __classMap
std::vector< O3Class * > __o3Classes
O3NameSolver< GUM_SCALAR > * __solver

Member Data Documentation

template<typename GUM_SCALAR>
HashTable< std::string, O3Class* > gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__classMap
private

The documentation for this class was generated from the following files: