aGrUM  0.14.2
UAIReader.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef UAIREADER_H
21 #define UAIREADER_H
22 
23 #include <agrum/BN/BayesNet.h>
25 #include <agrum/BN/io/BNReader.h>
26 #include <agrum/agrum.h>
27 #include <iostream>
28 #include <string>
29 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 // including coco-generated PARSER and SCANNER
32 # undef COCO_PARSER_H__
33 # undef COCO_SCANNER_H__
34 # include <agrum/BN/io/UAI/cocoR/Parser.h>
35 #endif // DOXYGEN_SHOULD_SKIP_THIS
36 
37 namespace gum {
38  /* =========================================================================*/
39  /* === READERS === */
40  /* =========================================================================*/
50  template < typename GUM_SCALAR >
51  class UAIReader : public BNReader< GUM_SCALAR > {
52  public:
62  UAIReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
63 
67  ~UAIReader() final;
68 
71  UAI::Scanner& scanner();
72 
74  const std::string& streamName() const;
75 
77  bool trace() const;
78  void trace(bool b);
79 
83  Size proceed() final;
84 
85  void buildFromQuartets(
86  std::vector< std::tuple< float, int, int, int > > quartets);
87 
90 
92  Size errors();
94  Size warnings();
95 
97  Idx errLine(Idx i);
99  Idx errCol(Idx i);
101  bool errIsError(Idx i);
103  std::string errMsg(Idx i);
104 
106  void showElegantErrors(std::ostream& o = std::cerr);
107 
109  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
110 
112  void showErrorsAndWarnings(std::ostream& o = std::cerr);
113 
115  void showErrorCounts(std::ostream& o = std::cerr);
117 
118  protected:
121  UAI::Scanner* __scanner;
122  UAI::Parser* __parser;
123 
124  std::string __streamName;
127 
128  // a boolean to throw the ioerror not in the constructor but in the
129  // proceed()
130  bool __ioerror;
131 
132  void __addFatalError(Idx lig,
133  Idx col,
134  const std::string& s); // throw an exception
135  void __addError(Idx lig, Idx col, const std::string& s);
136  void __addWarning(Idx lig, Idx col, const std::string& s);
137  };
138 
139 
140 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
141  extern template class UAIReader< double >;
142 #endif
143 
144 } /* namespace gum */
145 
146 #include "UAIReader_tpl.h"
147 
148 #endif // UAIREADER_H
Class representing a Bayesian Network.
Definition: BayesNet.h:76
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:124
UAI::Parser * __parser
Definition: UAIReader.h:122
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
Class representing Bayesian networks.
Idx errLine(Idx i)
line of ith error or warning
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Pure virtual class for reading a BN from a file.
Definition: BNReader.h:52
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.
Definition of abstract classes for file input manipulation of Bayesian Networks.
Size errors()
publishing Errors API
bool errIsError(Idx i)
type of ith error or warning
Headers of the BayesNetFactory class.
BayesNetFactory< GUM_SCALAR > * __factory
Definition: UAIReader.h:120
bool __parseDone
Definition: UAIReader.h:126
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:119
std::string errMsg(Idx i)
message of ith error or warning
Pure virtual class for reading a BN from a file.
Definition: UAIReader.h:51
UAI::Scanner * __scanner
Definition: UAIReader.h:121
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:50
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:45
bool __traceScanning
Definition: UAIReader.h:125
A factory class to ease BayesNet construction.
Definition: BayesNet.h:43
void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets)
Size warnings()
of errors