aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
UAIBNReader.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
50
51
52#ifndef UAIBNREADER_H
53#define UAIBNREADER_H
54
55#include <iostream>
56#include <string>
57
58#include <agrum/agrum.h>
59
62
63#ifndef DOXYGEN_SHOULD_SKIP_THIS
64// including coco-generated PARSER and SCANNER
65# undef _COCO_PARSER_H_
66# undef _COCO_SCANNER_H_
67# include <agrum/BN/io/UAI/cocoR/Parser.h>
68#endif // DOXYGEN_SHOULD_SKIP_THIS
69
70namespace gum {
71 /* =========================================================================*/
72 /* === READERS === */
73 /* =========================================================================*/
83 template < typename GUM_SCALAR >
84 class UAIBNReader: public BNReader< GUM_SCALAR > {
85 public:
95 UAIBNReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
96
101
104 UAIBN::Scanner& scanner();
105
107 const std::string& streamName() const;
108
110 bool trace() const;
111 void trace(bool b);
112
116 Size proceed() final;
117
118 void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets);
119
122
127
135 std::string errMsg(Idx i);
136
138 void showElegantErrors(std::ostream& o = std::cerr);
139
141 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
142
144 void showErrorsAndWarnings(std::ostream& o = std::cerr);
145
147 void showErrorCounts(std::ostream& o = std::cerr);
149
150 protected:
151 BayesNet< GUM_SCALAR >* _bn_;
153 UAIBN::Scanner* _scanner_;
154 UAIBN::Parser* _parser_;
155
159
160 // a boolean to throw the ioerror not in the constructor but in the
161 // proceed()
163
164 void _addFatalError_(Idx lig, Idx col,
165 const std::string& s); // throw an exception
166 void _addError_(Idx lig, Idx col, const std::string& s);
167 void _addWarning_(Idx lig, Idx col, const std::string& s);
168 };
169
170
171#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
172 extern template class UAIBNReader< double >;
173#endif
174
175} /* namespace gum */
176
177#include "UAIBNReader_tpl.h"
178
179#endif // UAIBNREADER_H
Definition of abstract classes for file input manipulation of Bayesian networks.
Headers of the BayesNetFactory class.
BNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
A factory class to ease BayesNet construction.
Class representing a Bayesian network.
Definition BayesNet.h:93
BayesNetFactory< GUM_SCALAR > * _factory_
bool errIsError(Idx i)
type of ith error or warning
Size errors()
publishing Errors API
void trace(bool b)
void _addFatalError_(Idx lig, Idx col, const std::string &s)
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
void _addError_(Idx lig, Idx col, const std::string &s)
Idx errLine(Idx i)
line of ith error or warning
const std::string & streamName() const
name of readen file
UAIBNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
Idx errCol(Idx i)
col of ith error or warning
UAIBN::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection).
std::string _streamName_
void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets)
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errorswith contents
Size proceed() final
parse.
std::string errMsg(Idx i)
message of ith error or warning
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings with contents
bool trace() const
accessor to trace function (just write the number of parser line)
~UAIBNReader()
Default destructor.
void _addWarning_(Idx lig, Idx col, const std::string &s)
UAIBN::Parser * _parser_
BayesNet< GUM_SCALAR > * _bn_
UAIBN::Scanner * _scanner_
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.