aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
O3prmBNReader.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
51#ifndef GUM_PRM_O3PRM_BNREADER_H
52#define GUM_PRM_O3PRM_BNREADER_H
53
54#include <algorithm>
55#include <string>
56
59
60namespace gum {
72 template < typename GUM_SCALAR >
73 class O3prmBNReader: public BNReader< GUM_SCALAR > {
74 public:
75 O3prmBNReader(BayesNet< GUM_SCALAR >* bn,
76 const std::string& filename,
77 const std::string& entityName = "",
78 const std::string& classPath = "");
79
81
85 Size proceed();
86
89
91 Size errors() { return _errors_.error_count; }
92
94 Size warnings() { return _errors_.warning_count; }
95
96 Idx errLine(Idx i) { return _errors_.error(i).line; }
97
99 Idx errCol(Idx i) { return _errors_.error(i).column; }
100
102 bool errIsError(Idx i) { return _errors_.error(i).is_error; }
103
105 std::string errMsg(Idx i) { return _errors_.error(i).msg; }
106
108 void showElegantErrors(std::ostream& o = std::cerr) { _errors_.elegantErrors(o); }
109
111 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) {
112 _errors_.elegantErrorsAndWarnings(o);
113 }
114
116 void showErrorCounts(std::ostream& o = std::cerr) { _errors_.syntheticResults(o); }
117
119
120 private:
121 std::string _filename_;
122
123 std::string _classpath_;
124 std::string _entityName_;
125
126 BayesNet< GUM_SCALAR >* _bn_;
128
130 static std::string _getVariableName_(const std::string& path,
131 const std::string& type,
132 const std::string& name,
133 const std::string& toRemove = "");
134 static std::string _getEntityName_(const std::string& filename);
135 static std::string _getInstanceName_(const std::string& classname);
136 };
137
138} // namespace gum
139
140// always include the implementation of the templates
142
143
144#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
145extern template class gum::O3prmBNReader< double >;
146#endif
147
148
149#endif // GUM_PRM_O3PRM_BNREADER_H
Definition of abstract classes for file input manipulation of Bayesian networks.
Inline implementation of O3prmReader.
Headers for the O3prmReader class.
BNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
This class is used contain and manipulate gum::ParseError.
Read an O3PRM and transform the gum::prm::PRMSystem into gum::BayesNet.
Size errors()
publishing Errors API
std::string _filename_
static std::string _getInstanceName_(const std::string &classname)
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
Idx errLine(Idx i)
publishing Errors API
std::string _entityName_
ErrorsContainer _errors_
O3prmBNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename, const std::string &entityName="", const std::string &classPath="")
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errors
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
bool errIsError(Idx i)
type of ith error or warning
void _generateBN_(prm::PRMSystem< GUM_SCALAR > &system)
std::string _classpath_
BayesNet< GUM_SCALAR > * _bn_
static std::string _getVariableName_(const std::string &path, const std::string &type, const std::string &name, const std::string &toRemove="")
std::string errMsg(Idx i)
message of ith error or warning
static std::string _getEntityName_(const std::string &filename)
Idx errCol(Idx i)
col of ith error or warning
Size proceed()
parse the file
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition PRMSystem.h:70
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