21 #ifndef DOXYGEN_SHOULD_SKIP_THIS 25 template <
typename GUM_SCALAR >
27 const std::string& filename) :
28 BNReader< GUM_SCALAR >(bn, filename) {
42 template <
typename GUM_SCALAR >
54 template <
typename GUM_SCALAR >
61 template <
typename GUM_SCALAR >
66 template <
typename GUM_SCALAR >
71 template <
typename GUM_SCALAR >
77 template <
typename GUM_SCALAR >
88 return 1 +
__parser->errors().error_count;
92 return (
__parser->errors().error_count);
95 template <
typename GUM_SCALAR >
97 std::vector< std::tuple< float, int, int, int > > quartets) {
99 Size max = quartets.size();
105 auto isInt = [&]() ->
bool {
106 return (std::get< 0 >(quartets[current]) == -1);
108 auto lig = [&]() ->
int {
return std::get< 2 >(quartets[current]); };
109 auto col = [&]() ->
int {
return std::get< 3 >(quartets[current]); };
111 auto getInt = [&]() ->
int {
113 return std::get< 1 >(quartets[current]);
115 auto getVal = [&]() -> GUM_SCALAR {
116 return (isInt()) ? (std::get< 1 >(quartets[current]))
117 : (std::get< 0 >(quartets[current]));
119 auto incCurrent = [&]() {
128 for (
NodeId i = 0; i < nbrNode; i++) {
132 __addError(lig(), col(),
"Number of modalities should be greater than 2.");
138 if (nbrPot != nbrNode)
140 lig(), col(),
"Number of CPTs should be the same as number of nodes");
143 for (
NodeId i = 0; i < nbrPot; i++) {
146 if (nbrPar == 0)
__addError(lig(), col(),
"0 is not possible here");
148 std::vector< NodeId > papas;
149 for (
NodeId j = 1; j < nbrPar; j++) {
153 __addError(lig(), col(),
"Not enough variables in the BayesNet");
154 papas.push_back(papa);
159 if (nodePot >= nbrNode)
160 __addError(lig(), col(),
"Not enough variables in the BayesNet");
164 for (
const auto papa : papas) {
165 __bn->addArc(papa, nodePot);
169 std::vector< GUM_SCALAR > v;
170 for (
NodeId i = 0; i < nbrPot; i++) {
173 if (nbrParam !=
__bn->cpt(i).domainSize())
175 lig(), col(),
"Size does not fit between parents and parameters");
176 for (
Idx j = 0; j < nbrParam; j++) {
178 v.push_back(getVal());
180 __bn->cpt(i).fillWith(v);
184 if (current != max - 1)
__addError(lig(), col(),
"Too many data in this file");
189 template <
typename GUM_SCALAR >
192 return __parser->errors().error(i).line;
194 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
198 template <
typename GUM_SCALAR >
201 return __parser->errors().error(i).column;
203 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
207 template <
typename GUM_SCALAR >
210 return __parser->errors().error(i).is_error;
212 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
216 template <
typename GUM_SCALAR >
219 return __parser->errors().error(i).msg;
221 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
225 template <
typename GUM_SCALAR >
228 __parser->errors().elegantErrors(o);
230 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
234 template <
typename GUM_SCALAR >
238 __parser->errors().elegantErrorsAndWarnings(o);
240 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
244 template <
typename GUM_SCALAR >
247 __parser->errors().simpleErrorsAndWarnings(o);
249 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
253 template <
typename GUM_SCALAR >
256 __parser->errors().syntheticResults(o);
258 GUM_ERROR(OperationNotAllowed,
"UAI file not parsed yet");
262 template <
typename GUM_SCALAR >
267 template <
typename GUM_SCALAR >
272 template <
typename GUM_SCALAR >
275 const std::string& s) {
279 template <
typename GUM_SCALAR >
284 template <
typename GUM_SCALAR >
287 const std::string& s) {
294 #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
gum is the global namespace for all aGrUM entities
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)