aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
UAIMRFReader.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#ifndef UAI_MRF_READER_H
52#define UAI_MRF_READER_H
53
54#include <iostream>
55#include <string>
56
57#include <agrum/agrum.h>
58
60
61#ifndef DOXYGEN_SHOULD_SKIP_THIS
62// including coco-generated PARSER and SCANNER
63# undef _COCO_PARSER_H_
64# undef _COCO_SCANNER_H_
65# include <agrum/MRF/io/UAI/cocoR/Parser.h>
66#endif // DOXYGEN_SHOULD_SKIP_THIS
67
68namespace gum {
69 /* =========================================================================*/
70 /* === READERS === */
71 /* =========================================================================*/
81 template < typename GUM_SCALAR >
82 class UAIMRFReader: public MRFReader< GUM_SCALAR > {
83 public:
93 UAIMRFReader(MarkovRandomField< GUM_SCALAR >* MN, const std::string& filename);
94
99
102 UAIMRF::Scanner& scanner();
103
105 const std::string& streamName() const;
106
108 bool trace() const;
109 void trace(bool b);
110
114 Size proceed() final;
115
116 void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets);
117
120
125
133 std::string errMsg(Idx i);
134
136 void showElegantErrors(std::ostream& o = std::cerr);
137
139 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
140
142 void showErrorsAndWarnings(std::ostream& o = std::cerr);
143
145 void showErrorCounts(std::ostream& o = std::cerr);
147
148 protected:
149 MarkovRandomField< GUM_SCALAR >* _mn_;
150 UAIMRF::Scanner* _scanner_;
151 UAIMRF::Parser* _parser_;
152
156
157 // a boolean to throw the ioerror not in the constructor but in the
158 // proceed()
160
161 void _addFatalError_(Idx lig, Idx col,
162 const std::string& s); // throw an exception
163 void _addError_(Idx lig, Idx col, const std::string& s);
164 void _addWarning_(Idx lig, Idx col, const std::string& s);
165 };
166
167
168#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
169 extern template class UAIMRFReader< double >;
170#endif
171
172} /* namespace gum */
173
174#include "UAIMRFReader_tpl.h"
175
176#endif // UAI_MRF_READER_H
Definition of abstract classes for file input manipulation of Markov random fields.
MRFReader(MarkovRandomField< GUM_SCALAR > *MN, const std::string &filename)
Constructor A reader is defined for reading a defined file.
UAIMRF::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection).
Size proceed() final
parse.
void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets)
bool errIsError(Idx i)
type of ith error or warning
Idx errCol(Idx i)
col of ith error or warning
UAIMRF::Scanner * _scanner_
Size errors()
publishing Errors API
UAIMRF::Parser * _parser_
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
void trace(bool b)
std::string errMsg(Idx i)
message of ith error or warning
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errorswith contents
~UAIMRFReader()
Default destructor.
MarkovRandomField< GUM_SCALAR > * _mn_
void _addFatalError_(Idx lig, Idx col, const std::string &s)
std::string _streamName_
bool trace() const
accessor to trace function (just write the number of parser line)
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings with contents
UAIMRFReader(MarkovRandomField< GUM_SCALAR > *MN, const std::string &filename)
Constructor A reader is defined for reading a defined file.
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
void _addWarning_(Idx lig, Idx col, const std::string &s)
const std::string & streamName() const
name of read file
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.