aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
O3prmBNReader.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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) {
88  errors__.elegantErrors(o);
89  }
90 
91  /// send on std::cerr the list of errors or warnings
92  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) {
93  errors__.elegantErrorsAndWarnings(o);
94  }
95 
96  /// send on std::cerr the number of errors and the number of warnings
97  void showErrorCounts(std::ostream& o = std::cerr) {
98  errors__.syntheticResults(o);
99  }
100  /// @}
101 
102  private:
103  std::string filename__;
104 
105  std::string classpath__;
106  std::string entityName__;
107 
110 
111  void generateBN__(prm::PRMSystem< GUM_SCALAR >& system);
112  static std::string getVariableName__(const std::string& path,
113  const std::string& type,
114  const std::string& name,
115  const std::string& toRemove = "");
116  static std::string getEntityName__(const std::string& filename);
117  static std::string getInstanceName__(const std::string& classname);
118  };
119 
120 } // namespace gum
121 
122 // always include the implementation of the templates
123 #include <agrum/PRM/o3prm/O3prmBNReader_tpl.h>
124 
125 
126 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
127 extern template class gum::O3prmBNReader< double >;
128 #endif
129 
130 
131 #endif // GUM_PRM_O3PRM_BNREADER_H
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 classpath__
std::string filename__
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
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)
ErrorsContainer errors__
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
Definition: O3prmBNReader.h:92
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
Definition: O3prmBNReader.h:84
void generateBN__(prm::PRMSystem< GUM_SCALAR > &system)
BayesNet< GUM_SCALAR > * bn__
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errors
Definition: O3prmBNReader.h:87
Size errors()
publishing Errors API
Definition: O3prmBNReader.h:74
static std::string getEntityName__(const std::string &filename)
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
Definition: O3prmBNReader.h:97
bool errIsError(Idx i)
type of ith error or warning
Definition: O3prmBNReader.h:82
std::string entityName__
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