aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
O3prmrInterpreter.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
48
49#ifndef SKOORINTERPRETER_H
50#define SKOORINTERPRETER_H
51
52#ifndef DOXYGEN_SHOULD_SKIP_THIS
55
56#endif // DOXYGEN_SHOULD_SKIP_THIS
57
58namespace gum {
59
60 namespace prm {
61
62 namespace o3prmr {
63
68 public:
69 std::string label;
70 float p;
71 };
72
77 public:
78 double time;
79 std::string command;
80 std::vector< SingleResult > values;
81 };
82
88 public:
93
102 bool interpretFile(const std::string& filename);
103 bool interpretLine(const std::string& line);
104
106 const gum::prm::PRM< double >* prm() const;
112 const std::vector< QueryResult >& results() const;
115
118 void setContext(O3prmrContext< double >* context);
119
123 std::vector< std::string > getPaths() const;
124 void addPath(std::string path);
125 void clearPaths();
126
129 bool isInSyntaxMode() const;
130 void setSyntaxMode(bool f);
131
134 bool isVerboseMode() const;
135 void setVerboseMode(bool f);
136
141 Size count() const;
143 Size errors() const;
145 Size warnings() const;
147 ParseError error(Idx i) const;
149 void showElegantErrors(std::ostream& o = std::cerr) const;
151 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
153 void showErrorCounts(std::ostream& o = std::cerr) const;
154
155 private:
157 bool checkSetEngine(SetEngineCommand* command);
161 bool checkQuery(QueryCommand< double >* command);
162
164 bool import(O3prmrContext< double >* context, std::string import);
165 bool observe(const ObserveCommand< double >* command);
166 bool unobserve(const UnobserveCommand< double >* command);
167 void query(const QueryCommand< double >* command);
168 void setEngine(const SetEngineCommand* command);
169 void setGndEngine(const SetGndEngineCommand* command);
170
171 std::string findSystemName(std::string& s);
172 std::string findInstanceName(std::string& s, const gum::prm::PRMSystem< double >& sys);
173 std::string findAttributeName(const std::string& s,
174 const gum::prm::PRMInstance< double >& instance);
175 const PRMSystem< double >& system(std::string& ident);
177
178 void addError(std::string msg);
179 void addWarning(std::string msg);
180
181 std::string _readFile_(const std::string& file);
182
185 std::vector< std::string > m_paths;
187 // Don't delete this, the m_inf_map will do it
190 std::string m_engine;
191 std::string m_bn_engine;
192 std::vector< QueryResult > m_results;
196 std::ostream& m_log;
198
200 // gum::BayesNetInference<gum::prm::prm_float>* bn;
201
202 }; // class O3prmrInterpreter
203
204 } // namespace o3prmr
205 } // namespace prm
206} // namespace gum
207
208#endif // GUM_SKOORINTERPRETER_H
Headers for the O3prmReader class.
Headers of O3prmInterpreter.
This class is used contain and manipulate gum::ParseError.
The class for generic Hash Tables.
Definition hashTable.h:637
This class is used to represent parsing errors for the different parser implemented in aGrUM.
~O3prmrInterpreter()
Destructor. Delete current context.
const PRMSystem< double > & system(std::string &ident)
std::string _readFile_(const std::string &file)
bool checkQuery(QueryCommand< double > *command)
std::string findAttributeName(const std::string &s, const gum::prm::PRMInstance< double > &instance)
void addPath(std::string path)
Root paths to search from there packages. Default are './' and one is calculate from request package ...
void showElegantErrors(std::ostream &o=std::cerr) const
send on std::cerr the list of errors
bool observe(const ObserveCommand< double > *command)
bool checkSetGndEngine(SetGndEngineCommand *command)
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings
bool interpretFile(const std::string &filename)
Interpret the file or the command line.
std::vector< std::string > getPaths() const
Root paths to search from there packages. Default are working dir, request file dir if any and one is...
void setContext(O3prmrContext< double > *context)
Setter for the context.
ErrorsContainer errorsContainer() const
Return container with all errors.
void showErrorCounts(std::ostream &o=std::cerr) const
send on std::cerr the number of errors and the number of warnings
void setSyntaxMode(bool f)
syntax mode don't process anything, just check syntax.
const gum::prm::PRMInference< double > * inference() const
Retrieve inference motor object.
O3prmrInterpreter()
This constructor create an empty context.
bool checkObserve(ObserveCommand< double > *command)
std::vector< QueryResult > m_results
gum::prm::PRMInference< double > * m_inf
bool isInSyntaxMode() const
syntax mode don't process anything, just check syntax. Default is false.
O3prmrContext< double > * getContext() const
Getter and setter for the context.
HashTable< const PRMSystem< double > *, PRMInference< double > * > m_inf_map
void generateInfEngine(const gum::prm::PRMSystem< double > &sys)
void clearPaths()
Root paths to search from there packages. Default are './' and one is calculate from request package ...
bool checkUnobserve(UnobserveCommand< double > *command)
O3prmrContext< double > * m_context
const std::vector< QueryResult > & results() const
Return a vector of QueryResults. Each QueryResults is a struct with query command,...
std::vector< std::string > m_paths
gum::prm::o3prm::O3prmReader< double > * m_reader
bool isVerboseMode() const
verbose mode show more details on the program execution. Default is false.
bool checkSemantic(O3prmrContext< double > *context)
Check semantic validity of context.
bool interpret(O3prmrContext< double > *c)
Crée le prm correspondant au contexte courant.
void setGndEngine(const SetGndEngineCommand *command)
void setEngine(const SetEngineCommand *command)
std::string findInstanceName(std::string &s, const gum::prm::PRMSystem< double > &sys)
const gum::prm::PRM< double > * prm() const
Retrieve prm object.
bool checkSetEngine(SetEngineCommand *command)
std::string findSystemName(std::string &s)
void query(const QueryCommand< double > *command)
bool interpretLine(const std::string &line)
bool unobserve(const UnobserveCommand< double > *command)
ParseError error(Idx i) const
throw a string error if i >= count
Size count() const
En cas d'échec, l'API de gestion d'erreurs est présente.
void setVerboseMode(bool f)
verbose mode show more details on the program execution.
std::vector< SingleResult > values
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
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46