aGrUM 3.2.0
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-2026 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-2026 *
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 GUM_UAI_MRF_READER_H
52#define GUM_UAI_MRF_READER_H
53
54#include <iostream>
55#include <string>
56
57#include <agrum/agrum.h>
58
60
61#include <string_view>
62
63#ifndef DOXYGEN_SHOULD_SKIP_THIS
64// including coco-generated PARSER and SCANNER; GUM_COCOR_PUBLIC is locally
65// forced to this module's own export macro so the grammar is tagged
66// correctly even in a translation unit (e.g. gumTest) that does not define
67// AGRUM_MRF_EXPORTING.
68# undef _COCO_PARSER_H_
69# undef _COCO_SCANNER_H_
70# pragma push_macro("GUM_COCOR_PUBLIC")
71# undef GUM_COCOR_PUBLIC
72# define GUM_COCOR_PUBLIC GUM_PUBLIC_MRF
73# include <agrum/MRF/io/UAI/cocoR/Parser.h>
74# pragma pop_macro("GUM_COCOR_PUBLIC")
75#endif // DOXYGEN_SHOULD_SKIP_THIS
76
77namespace gum {
78 /* =========================================================================*/
79 /* === READERS === */
80 /* =========================================================================*/
90 template < GUM_Numeric GUM_SCALAR >
91 class UAIMRFReader: public MRFReader< GUM_SCALAR > {
92 public:
102 UAIMRFReader(MarkovRandomField< GUM_SCALAR >* MN, std::string_view filename);
103
107 ~UAIMRFReader() override;
108
111 UAIMRF::Scanner& scanner();
112
114 const std::string& streamName() const;
115
117 bool trace() const;
118 void trace(bool b);
119
123 Size proceed() final;
124
125 void buildFromQuartets(std::vector< std::tuple< float, int, int, int > > quartets);
126
129
134
142 std::string errMsg(Idx i);
143
145 void showElegantErrors(std::ostream& o = std::cerr);
146
148 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
149
151 void showErrorsAndWarnings(std::ostream& o = std::cerr);
152
154 void showErrorCounts(std::ostream& o = std::cerr);
156
157 protected:
158 MarkovRandomField< GUM_SCALAR >* _mn_;
159 UAIMRF::Scanner* _scanner_;
160 UAIMRF::Parser* _parser_;
161
165
166 // a boolean to throw the ioerror not in the constructor but in the
167 // proceed()
169
170 void _addFatalError_(Idx lig, Idx col,
171 std::string_view s); // throw an exception
172 void _addError_(Idx lig, Idx col, std::string_view s);
173 void _addWarning_(Idx lig, Idx col, std::string_view s);
174 };
175
176
177#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
178 extern template class GUM_PUBLIC_MRF UAIMRFReader< double >;
179#endif
180
181} /* namespace gum */
182
183#include "UAIMRFReader_tpl.h"
184
185#endif // GUM_UAI_MRF_READER_H
Definition of abstract classes for file input manipulation of Markov random fields.
MRFReader(MarkovRandomField< GUM_SCALAR > *MN, std::string_view 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.
UAIMRFReader(MarkovRandomField< GUM_SCALAR > *MN, std::string_view filename)
Constructor A reader is defined for reading a defined file.
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 _addWarning_(Idx lig, Idx col, std::string_view s)
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
MarkovRandomField< GUM_SCALAR > * _mn_
~UAIMRFReader() override
Default destructor.
void _addError_(Idx lig, Idx col, std::string_view 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
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
Idx errLine(Idx i)
line of ith error or warning
const std::string & streamName() const
name of read file
void _addFatalError_(Idx lig, Idx col, std::string_view s)
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
template class GUM_PUBLIC_MRF UAIMRFReader< double >
STL namespace.