23 #ifndef DOXYGEN_SHOULD_SKIP_THIS 27 template <
typename GUM_SCALAR >
29 const std::string& filename) :
30 BNReader< GUM_SCALAR >(bn, filename) {
44 template <
typename GUM_SCALAR >
56 template <
typename GUM_SCALAR >
63 template <
typename GUM_SCALAR >
68 template <
typename GUM_SCALAR >
73 template <
typename GUM_SCALAR >
79 template <
typename GUM_SCALAR >
90 return 1 +
__parser->errors().error_count;
94 return (
__parser->errors().error_count);
97 template <
typename GUM_SCALAR >
99 std::vector< std::tuple< float, int, int, int > > quartets) {
101 Size max = quartets.size();
107 auto isInt = [&]() ->
bool {
108 return (std::get< 0 >(quartets[current]) == -1);
110 auto lig = [&]() ->
int {
return std::get< 2 >(quartets[current]); };
111 auto col = [&]() ->
int {
return std::get< 3 >(quartets[current]); };
113 auto getInt = [&]() ->
int {
115 return std::get< 1 >(quartets[current]);
117 auto getVal = [&]() -> GUM_SCALAR {
118 return (isInt()) ? (std::get< 1 >(quartets[current]))
119 : (std::get< 0 >(quartets[current]));
121 auto incCurrent = [&]() {
130 for (
NodeId i = 0; i < nbrNode; i++) {
134 __addError(lig(), col(),
"Number of modalities should be greater than 2.");
140 if (nbrPot != nbrNode)
142 lig(), col(),
"Number of CPTs should be the same as number of nodes");
145 for (
NodeId i = 0; i < nbrPot; i++) {
148 if (nbrPar == 0)
__addError(lig(), col(),
"0 is not possible here");
150 std::vector< NodeId > papas;
151 for (
NodeId j = 1; j < nbrPar; j++) {
155 __addError(lig(), col(),
"Not enough variables in the BayesNet");
156 papas.push_back(papa);
161 if (nodePot >= nbrNode)
162 __addError(lig(), col(),
"Not enough variables in the BayesNet");
166 for (
const auto papa : papas) {
167 __bn->addArc(papa, nodePot);
171 std::vector< GUM_SCALAR > v;
172 for (
NodeId i = 0; i < nbrPot; i++) {
175 if (nbrParam !=
__bn->cpt(i).domainSize())
177 lig(), col(),
"Size does not fit between parents and parameters");
178 for (
Idx j = 0; j < nbrParam; j++) {
180 v.push_back(getVal());
182 __bn->cpt(i).fillWith(v);
186 if (current != max - 1)
__addError(lig(), col(),
"Too many data in this file");
191 template <
typename GUM_SCALAR >
194 return __parser->errors().error(i).line;
196 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
200 template <
typename GUM_SCALAR >
203 return __parser->errors().error(i).column;
205 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
209 template <
typename GUM_SCALAR >
212 return __parser->errors().error(i).is_error;
214 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
218 template <
typename GUM_SCALAR >
221 return __parser->errors().error(i).msg;
223 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
227 template <
typename GUM_SCALAR >
230 __parser->errors().elegantErrors(o);
232 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
236 template <
typename GUM_SCALAR >
240 __parser->errors().elegantErrorsAndWarnings(o);
242 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
246 template <
typename GUM_SCALAR >
249 __parser->errors().simpleErrorsAndWarnings(o);
251 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
255 template <
typename GUM_SCALAR >
258 __parser->errors().syntheticResults(o);
260 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
264 template <
typename GUM_SCALAR >
269 template <
typename GUM_SCALAR >
274 template <
typename GUM_SCALAR >
277 const std::string& s) {
281 template <
typename GUM_SCALAR >
286 template <
typename GUM_SCALAR >
289 const std::string& s) {
296 #endif // DOXYGEN_SHOULD_SKIP_THIS bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
bool trace() const
accessor to trace function (just write the number of parser line)
Idx errCol(Idx i)
col of ith error or warning
void __addError(Idx lig, Idx col, const std::string &s)
void __addWarning(Idx lig, Idx col, const std::string &s)
Size proceed() final
parse.
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings with contents
Idx errLine(Idx i)
line of ith error or warning
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __addFatalError(Idx lig, Idx col, const std::string &s)
UAIReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
Size errors()
publishing Errors API
bool errIsError(Idx i)
type of ith error or warning
std::string to_string(const Formula &f)
Base class for all aGrUM's exceptions.
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errorswith contents
~UAIReader() final
Default destructor.
BayesNet< GUM_SCALAR > * __bn
std::string errMsg(Idx i)
message of ith error or warning
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
const std::string & streamName() const
name of readen file
UAI::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
#define GUM_ERROR(type, msg)
void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets)