aGrUM  0.16.0
UAIReader.h
Go to the documentation of this file.
1 
23 #ifndef UAIREADER_H
24 #define UAIREADER_H
25 
26 #include <agrum/BN/BayesNet.h>
28 #include <agrum/BN/io/BNReader.h>
29 #include <agrum/agrum.h>
30 #include <iostream>
31 #include <string>
32 
33 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 // including coco-generated PARSER and SCANNER
35 # undef COCO_PARSER_H__
36 # undef COCO_SCANNER_H__
37 # include <agrum/BN/io/UAI/cocoR/Parser.h>
38 #endif // DOXYGEN_SHOULD_SKIP_THIS
39 
40 namespace gum {
41  /* =========================================================================*/
42  /* === READERS === */
43  /* =========================================================================*/
53  template < typename GUM_SCALAR >
54  class UAIReader : public BNReader< GUM_SCALAR > {
55  public:
65  UAIReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
66 
70  ~UAIReader() final;
71 
74  UAI::Scanner& scanner();
75 
77  const std::string& streamName() const;
78 
80  bool trace() const;
81  void trace(bool b);
82 
86  Size proceed() final;
87 
88  void buildFromQuartets(
89  std::vector< std::tuple< float, int, int, int > > quartets);
90 
93 
95  Size errors();
97  Size warnings();
98 
100  Idx errLine(Idx i);
102  Idx errCol(Idx i);
104  bool errIsError(Idx i);
106  std::string errMsg(Idx i);
107 
109  void showElegantErrors(std::ostream& o = std::cerr);
110 
112  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
113 
115  void showErrorsAndWarnings(std::ostream& o = std::cerr);
116 
118  void showErrorCounts(std::ostream& o = std::cerr);
120 
121  protected:
124  UAI::Scanner* __scanner;
125  UAI::Parser* __parser;
126 
127  std::string __streamName;
130 
131  // a boolean to throw the ioerror not in the constructor but in the
132  // proceed()
133  bool __ioerror;
134 
135  void __addFatalError(Idx lig,
136  Idx col,
137  const std::string& s); // throw an exception
138  void __addError(Idx lig, Idx col, const std::string& s);
139  void __addWarning(Idx lig, Idx col, const std::string& s);
140  };
141 
142 
143 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
144  extern template class UAIReader< double >;
145 #endif
146 
147 } /* namespace gum */
148 
149 #include "UAIReader_tpl.h"
150 
151 #endif // UAIREADER_H
Class representing a Bayesian Network.
Definition: BayesNet.h:78
bool trace() const
accessor to trace function (just write the number of parser line)
Idx errCol(Idx i)
col of ith error or warning
std::string __streamName
Definition: UAIReader.h:127
UAI::Parser * __parser
Definition: UAIReader.h:125
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Definition: agrum.h:25
Pure virtual class for reading a BN from a file.
Definition: BNReader.h:55
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size errors()
publishing Errors API
bool errIsError(Idx i)
type of ith error or warning
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
BayesNetFactory< GUM_SCALAR > * __factory
Definition: UAIReader.h:123
bool __parseDone
Definition: UAIReader.h:129
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
Definition: UAIReader.h:122
std::string errMsg(Idx i)
message of ith error or warning
Pure virtual class for reading a BN from a file.
Definition: UAIReader.h:54
UAI::Scanner * __scanner
Definition: UAIReader.h:124
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
Size Idx
Type for indexes.
Definition: types.h:53
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.
Definition: types.h:48
bool __traceScanning
Definition: UAIReader.h:128
A factory class to ease BayesNet construction.
Definition: BayesNet.h:45
void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets)
Size warnings()
of errors