aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
O3prmBNReader.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Inline implementation of O3prBNmReader : reader for BN using o3prm
25  * syntaxt
26  *
27  * this class generates the groundedBN from a class or an instance name.
28  *
29  * @author Pierre-Henri WUILLEMIN(@LIP6) and Lionel TORTI
30  */
31 #ifndef GUM_PRM_O3PRM_BNREADER_H
32 #define GUM_PRM_O3PRM_BNREADER_H
33 
34 #include <algorithm>
35 #include <string>
36 
37 #include <agrum/BN/io/BNReader.h>
38 #include <agrum/tools/core/errorsContainer.h>
39 
40 #include <agrum/PRM/PRM.h>
41 #include <agrum/PRM/o3prm/O3prmReader.h>
42 
43 namespace gum {
44  /**
45  * @class O3prmBNReader
46  * @headerfile O3prmBNReader.h <agrum/PRM/o3prm/O3prmBNReader.h>
47  * @ingroup o3prm_group
48  *
49  * @brief Read an O3PRM and transform the gum::prm::PRMSystem into
50  * gum::BayesNet.
51  *
52  * @tparam GUM_SCALAR The scalar type used both for the gum::prm::PRM and the
53  * gum::BayesNet.
54  */
55  template < typename GUM_SCALAR >
56  class O3prmBNReader: public BNReader< GUM_SCALAR > {
57  public:
58  O3prmBNReader(BayesNet< GUM_SCALAR >* bn,
59  const std::string& filename,
60  const std::string& entityName = "",
61  const std::string& classPath = "");
62 
63  ~O3prmBNReader();
64 
65  /// parse the file
66  /// @return the number of detected errors and warnings
67  /// @throws IOError if file not exists
68  Size proceed();
69 
70  /// @{
71  /// publishing Errors API
72 
73  /// # of errors
74  Size errors() { return _errors_.error_count; }
75  /// # of errors
76  Size warnings() { return _errors_.warning_count; }
77 
78  Idx errLine(Idx i) { return _errors_.error(i).line; }
79  /// col of ith error or warning
80  Idx errCol(Idx i) { return _errors_.error(i).column; }
81  /// type of ith error or warning
82  bool errIsError(Idx i) { return _errors_.error(i).is_error; }
83  /// message of ith error or warning
84  std::string errMsg(Idx i) { return _errors_.error(i).msg; }
85 
86  /// send on std::cerr the list of errors
87  void showElegantErrors(std::ostream& o = std::cerr) { _errors_.elegantErrors(o); }
88 
89  /// send on std::cerr the list of errors or warnings
90  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) {
91  _errors_.elegantErrorsAndWarnings(o);
92  }
93 
94  /// send on std::cerr the number of errors and the number of warnings
95  void showErrorCounts(std::ostream& o = std::cerr) { _errors_.syntheticResults(o); }
96  /// @}
97 
98  private:
99  std::string _filename_;
100 
101  std::string _classpath_;
102  std::string _entityName_;
103 
106 
107  void _generateBN_(prm::PRMSystem< GUM_SCALAR >& system);
108  static std::string _getVariableName_(const std::string& path,
109  const std::string& type,
110  const std::string& name,
111  const std::string& toRemove = "");
112  static std::string _getEntityName_(const std::string& filename);
113  static std::string _getInstanceName_(const std::string& classname);
114  };
115 
116 } // namespace gum
117 
118 // always include the implementation of the templates
119 #include <agrum/PRM/o3prm/O3prmBNReader_tpl.h>
120 
121 
122 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
123 extern template class gum::O3prmBNReader< double >;
124 #endif
125 
126 
127 #endif // GUM_PRM_O3PRM_BNREADER_H
void _generateBN_(prm::PRMSystem< GUM_SCALAR > &system)
Idx errCol(Idx i)
col of ith error or warning
Definition: O3prmBNReader.h:80
Idx errLine(Idx i)
publishing Errors API
Definition: O3prmBNReader.h:78
std::string _filename_
Definition: O3prmBNReader.h:99
static std::string _getVariableName_(const std::string &path, const std::string &type, const std::string &name, const std::string &toRemove="")
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
O3prmBNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename, const std::string &entityName="", const std::string &classPath="")
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
Definition: O3prmBNReader.h:90
ErrorsContainer _errors_
static std::string _getEntityName_(const std::string &filename)
std::string errMsg(Idx i)
message of ith error or warning
Definition: O3prmBNReader.h:84
std::string _entityName_
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errors
Definition: O3prmBNReader.h:87
BayesNet< GUM_SCALAR > * _bn_
Size errors()
publishing Errors API
Definition: O3prmBNReader.h:74
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
Definition: O3prmBNReader.h:95
std::string _classpath_
bool errIsError(Idx i)
type of ith error or warning
Definition: O3prmBNReader.h:82
Read an O3PRM and transform the gum::prm::PRMSystem into gum::BayesNet.
Definition: O3prmBNReader.h:56
Size proceed()
parse the file
Size warnings()
of errors
Definition: O3prmBNReader.h:76