![]() |
aGrUM
0.16.0
|
Represents a O3PRMR context. More...
#include <O3prmrInterpreter.h>
Public Member Functions | |
O3prmrInterpreter () | |
This constructor create an empty context. More... | |
~O3prmrInterpreter () | |
Destructor. Delete current context. More... | |
bool | interpretFile (const std::string &filename) |
Interpret the file or the command line. More... | |
bool | interpretLine (const std::string &line) |
const gum::prm::PRM< double > * | prm () const |
Retrieve prm object. More... | |
const gum::prm::PRMInference< double > * | inference () const |
Retrieve inference motor object. More... | |
const std::vector< QueryResult > & | results () const |
Return a vector of QueryResults. Each QueryResults is a struct with query command, time and values, a vector of struct SingleResult, with pair label/value. More... | |
ErrorsContainer | errorsContainer () const |
Return container with all errors. More... | |
O3prmrContext< double > * | getContext () const |
Getter and setter for the context. More... | |
void | setContext (O3prmrContext< double > *context) |
Setter for the context. More... | |
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 calculate from package if any. More... | |
void | addPath (std::string path) |
Root paths to search from there packages. Default are './' and one is calculate from request package if any. More... | |
void | clearPaths () |
Root paths to search from there packages. Default are './' and one is calculate from request package if any. More... | |
bool | isInSyntaxMode () const |
syntax mode don't process anything, just check syntax. Default is false. More... | |
void | setSyntaxMode (bool f) |
syntax mode don't process anything, just check syntax. More... | |
bool | isVerboseMode () const |
verbose mode show more details on the program execution. Default is false. More... | |
void | setVerboseMode (bool f) |
verbose mode show more details on the program execution. More... | |
Size | count () const |
En cas d'échec, l'API de gestion d'erreurs est présente. More... | |
Size | errors () const |
of errorsMore... | |
Size | warnings () const |
of warningsMore... | |
ParseError | error (Idx i) const |
throw a string error if i >= count More... | |
void | showElegantErrors (std::ostream &o=std::cerr) const |
send on std::cerr the list of errors More... | |
void | showElegantErrorsAndWarnings (std::ostream &o=std::cerr) const |
send on std::cerr the list of errors or warnings More... | |
void | showErrorCounts (std::ostream &o=std::cerr) const |
send on std::cerr the number of errors and the number of warnings More... | |
Represents a O3PRMR context.
O3prmr use the <double> version of the O3PRM templatized ecosystem
Definition at line 70 of file O3prmrInterpreter.h.
gum::prm::o3prmr::O3prmrInterpreter::O3prmrInterpreter | ( | ) |
This constructor create an empty context.
Definition at line 54 of file O3prmrInterpreter.cpp.
gum::prm::o3prmr::O3prmrInterpreter::~O3prmrInterpreter | ( | ) |
Destructor. Delete current context.
Definition at line 61 of file O3prmrInterpreter.cpp.
References m_bn, m_context, m_inf_map, m_reader, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm().
|
private |
Definition at line 188 of file O3prmrInterpreter.cpp.
References GUM_ERROR.
Referenced by interpretFile().
|
private |
Definition at line 977 of file O3prmrInterpreter.cpp.
References gum::ErrorsContainer::addError(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::filename(), gum::ErrorsContainer::last(), m_context, m_current_line, m_errors, m_log, m_verbose, and gum::ParseError::toString().
Referenced by checkObserve(), checkQuery(), checkSemantic(), checkUnobserve(), import(), interpret(), observe(), query(), and unobserve().
void gum::prm::o3prmr::O3prmrInterpreter::addPath | ( | std::string | path | ) |
Root paths to search from there packages. Default are './' and one is calculate from request package if any.
Definition at line 97 of file O3prmrInterpreter.cpp.
References GUM_ERROR, gum::Directory::isDir(), and m_paths.
|
private |
Definition at line 984 of file O3prmrInterpreter.cpp.
References gum::ErrorsContainer::addWarning(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::filename(), gum::ErrorsContainer::last(), m_context, m_current_line, m_errors, m_log, m_verbose, and gum::ParseError::toString().
Referenced by generateInfEngine(), observe(), and unobserve().
|
private |
Definition at line 434 of file O3prmrInterpreter.cpp.
References addError(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::chain, gum::Instantiation::end(), gum::Exception::errorContent(), findAttributeName(), findInstanceName(), gum::prm::PRMSystem< GUM_SCALAR >::get(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::Instantiation::inc(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::leftValue, gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::potentiel, gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::rightValue, gum::Instantiation::setFirst(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::system, system(), and gum::Instantiation::val().
Referenced by checkSemantic().
|
private |
Definition at line 506 of file O3prmrInterpreter.cpp.
References addError(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::chain, gum::Exception::errorContent(), findAttributeName(), findInstanceName(), gum::prm::PRMSystem< GUM_SCALAR >::get(), gum::prm::PRMInstance< GUM_SCALAR >::get(), system(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::system, and gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::value.
Referenced by checkSemantic().
|
private |
Check semantic validity of context.
Import first all import, and check that systems, instances, attributes and labels exists. While checking, prepare data structures for interpretation. Return true if all is right, false otherwise.
Note : Stop checking at first error unless syntax mode is activated.
Definition at line 311 of file O3prmrInterpreter.cpp.
References gum::prm::o3prmr::O3prmrSession< GUM_SCALAR >::addCommand(), addError(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::addImport(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::addSession(), checkObserve(), checkQuery(), checkSetEngine(), checkSetGndEngine(), checkUnobserve(), gum::ErrorsContainer::elegantErrorsAndWarnings(), gum::Exception::errorContent(), errors(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::imports(), isInSyntaxMode(), isVerboseMode(), m_context, m_current_line, m_errors, m_log, m_verbose, gum::prm::o3prmr::O3prmrCommand::Observe, gum::prm::o3prmr::O3prmrCommand::Query, gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::sessions(), gum::prm::o3prmr::O3prmrCommand::SetEngine, gum::prm::o3prmr::O3prmrCommand::SetGndEngine, gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::toString(), and gum::prm::o3prmr::O3prmrCommand::Unobserve.
Referenced by interpretFile(), and interpretLine().
|
private |
Definition at line 423 of file O3prmrInterpreter.cpp.
References m_engine, and gum::prm::o3prmr::SetEngineCommand::value.
Referenced by checkSemantic().
|
private |
Definition at line 428 of file O3prmrInterpreter.cpp.
References m_bn_engine, and gum::prm::o3prmr::SetGndEngineCommand::value.
Referenced by checkSemantic().
|
private |
Definition at line 481 of file O3prmrInterpreter.cpp.
References addError(), gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::chain, gum::Exception::errorContent(), findAttributeName(), findInstanceName(), gum::prm::PRMSystem< GUM_SCALAR >::get(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::system, system(), and gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::value.
Referenced by checkSemantic().
void gum::prm::o3prmr::O3prmrInterpreter::clearPaths | ( | ) |
Root paths to search from there packages. Default are './' and one is calculate from request package if any.
Definition at line 108 of file O3prmrInterpreter.cpp.
References m_paths.
Size gum::prm::o3prmr::O3prmrInterpreter::count | ( | ) | const |
En cas d'échec, l'API de gestion d'erreurs est présente.
Definition at line 938 of file O3prmrInterpreter.cpp.
References gum::ErrorsContainer::count(), and m_errors.
Referenced by error(), and import().
ParseError gum::prm::o3prmr::O3prmrInterpreter::error | ( | Idx | i | ) | const |
throw a string error if i >= count
Definition at line 947 of file O3prmrInterpreter.cpp.
References count(), gum::ErrorsContainer::error(), and m_errors.
Size gum::prm::o3prmr::O3prmrInterpreter::errors | ( | ) | const |
Definition at line 941 of file O3prmrInterpreter.cpp.
References gum::ErrorsContainer::error_count, and m_errors.
Referenced by checkSemantic(), import(), interpret(), interpretFile(), and interpretLine().
ErrorsContainer gum::prm::o3prmr::O3prmrInterpreter::errorsContainer | ( | ) | const |
Return container with all errors.
Definition at line 954 of file O3prmrInterpreter.cpp.
References m_errors.
|
private |
Definition at line 735 of file O3prmrInterpreter.cpp.
References gum::prm::PRMInstance< GUM_SCALAR >::exists(), and gum::prm::PRMObject::name().
Referenced by checkObserve(), checkQuery(), and checkUnobserve().
|
private |
Definition at line 721 of file O3prmrInterpreter.cpp.
References gum::prm::PRMSystem< GUM_SCALAR >::exists(), and gum::prm::PRMObject::name().
Referenced by checkObserve(), checkQuery(), and checkUnobserve().
|
private |
Definition at line 692 of file O3prmrInterpreter.cpp.
References gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::aliasToImport(), m_context, and prm().
Referenced by system().
|
private |
Definition at line 894 of file O3prmrInterpreter.cpp.
References addWarning(), gum::prm::PRMSystem< GUM_SCALAR >::groundedBN(), m_bn, m_engine, m_inf, m_inf_map, m_log, m_verbose, and prm().
Referenced by observe(), and query().
O3prmrContext< double > * gum::prm::o3prmr::O3prmrInterpreter::getContext | ( | ) | const |
Getter and setter for the context.
Getter for the context.
Definition at line 75 of file O3prmrInterpreter.cpp.
References m_context.
std::vector< std::string > gum::prm::o3prmr::O3prmrInterpreter::getPaths | ( | ) | const |
Root paths to search from there packages. Default are working dir, request file dir if any and one is calculate from package if any.
Root paths to search from there packages. Default are './' and one is calculate from request package if any.
Definition at line 91 of file O3prmrInterpreter.cpp.
References m_paths.
|
private |
Definition at line 534 of file O3prmrInterpreter.cpp.
References gum::Directory::absolutePath(), gum::ErrorsContainer::add(), addError(), count(), gum::ErrorsContainer::count(), gum::ErrorsContainer::error(), gum::Exception::errorContent(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errors(), errors(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errorsContainer(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::filename(), m_errors, m_log, m_paths, m_reader, m_verbose, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::readFile(), and gum::replace().
const PRMInference< double > * gum::prm::o3prmr::O3prmrInterpreter::inference | ( | ) | const |
Retrieve inference motor object.
Definition at line 128 of file O3prmrInterpreter.cpp.
References m_inf.
|
private |
Crée le prm correspondant au contexte courant.
Renvoie true en cas de succès, ou false en cas échéant d'échec de l'interprétation du contexte (import introuvable ou non défini, etc).
Definition at line 237 of file O3prmrInterpreter.cpp.
References addError(), gum::Exception::errorContent(), errors(), isVerboseMode(), m_log, m_verbose, gum::prm::o3prmr::O3prmrCommand::Observe, observe(), gum::prm::o3prmr::O3prmrCommand::Query, query(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::sessions(), gum::prm::o3prmr::O3prmrCommand::SetEngine, setEngine(), gum::prm::o3prmr::O3prmrCommand::SetGndEngine, setGndEngine(), gum::prm::o3prmr::O3prmrCommand::Unobserve, and unobserve().
Referenced by interpretFile(), and interpretLine().
bool gum::prm::o3prmr::O3prmrInterpreter::interpretFile | ( | const std::string & | filename | ) |
Interpret the file or the command line.
Parse the file or the command line.
If syntax mode is activated, check only syntax and semantic. If errors occured, return false. Errors messages can be retrieve be errorsContainer() methods. If any errors occured, return true. Requests results can be retrieve be results() methods.
If errors occured, return false. Errors messages can be retrieve be getErrorsContainer() methods. If any errors occured, return true. Requests results can be retrieve be results() methods.
Definition at line 146 of file O3prmrInterpreter.cpp.
References __readFile(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::addClassPath(), checkSemantic(), errors(), gum::ErrorsContainer::errors, interpret(), isInSyntaxMode(), m_context, m_errors, m_paths, m_reader, m_results, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm().
bool gum::prm::o3prmr::O3prmrInterpreter::interpretLine | ( | const std::string & | line | ) |
Definition at line 209 of file O3prmrInterpreter.cpp.
References checkSemantic(), errors(), gum::ErrorsContainer::errors, interpret(), isInSyntaxMode(), m_errors, and m_results.
bool gum::prm::o3prmr::O3prmrInterpreter::isInSyntaxMode | ( | ) | const |
syntax mode don't process anything, just check syntax. Default is false.
syntax mode don't process anything, just check syntax.
Definition at line 111 of file O3prmrInterpreter.cpp.
References m_syntax_flag.
Referenced by checkSemantic(), interpretFile(), and interpretLine().
bool gum::prm::o3prmr::O3prmrInterpreter::isVerboseMode | ( | ) | const |
verbose mode show more details on the program execution. Default is false.
verbose mode show more details on the program execution.
Definition at line 117 of file O3prmrInterpreter.cpp.
References m_verbose.
Referenced by checkSemantic(), and interpret().
|
private |
Definition at line 761 of file O3prmrInterpreter.cpp.
References addError(), gum::prm::PRMInference< GUM_SCALAR >::addEvidence(), addWarning(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::chain, gum::Exception::errorContent(), generateInfEngine(), gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::leftValue, m_inf, m_log, m_verbose, gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::potentiel, gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::rightValue, and gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::system.
Referenced by interpret().
Retrieve prm object.
Definition at line 123 of file O3prmrInterpreter.cpp.
References m_reader, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm().
Referenced by findSystemName(), generateInfEngine(), and system().
|
private |
Definition at line 814 of file O3prmrInterpreter.cpp.
References addError(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::chain, gum::prm::o3prmr::QueryResult::command, gum::Instantiation::end(), gum::Exception::errorContent(), generateInfEngine(), gum::MultiDimDecorator< GUM_SCALAR >::get(), GUM_SHOWERROR, gum::Instantiation::inc(), gum::prm::o3prmr::SingleResult::label, gum::DiscreteVariable::label(), m_inf, m_inf_map, m_log, m_results, m_verbose, gum::prm::PRMInference< GUM_SCALAR >::marginal(), gum::Timer::reset(), gum::Instantiation::setFirst(), gum::Timer::step(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::system, gum::prm::o3prmr::QueryResult::time, gum::prm::PRMAttribute< GUM_SCALAR >::type(), gum::Instantiation::val(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::value, gum::prm::o3prmr::QueryResult::values, and gum::prm::PRMType::variable().
Referenced by interpret().
const std::vector< QueryResult > & gum::prm::o3prmr::O3prmrInterpreter::results | ( | ) | const |
Return a vector of QueryResults. Each QueryResults is a struct with query command, time and values, a vector of struct SingleResult, with pair label/value.
Return a std::vector of QueryResults. Each QueryResults is a struct with query command, time and values, a std::vector of struct SingleResult, with pair label/value.
Definition at line 135 of file O3prmrInterpreter.cpp.
References m_results.
void gum::prm::o3prmr::O3prmrInterpreter::setContext | ( | O3prmrContext< double > * | context | ) |
Setter for the context.
Definition at line 80 of file O3prmrInterpreter.cpp.
References m_context.
|
private |
Definition at line 884 of file O3prmrInterpreter.cpp.
References m_engine, and gum::prm::o3prmr::SetEngineCommand::value.
Referenced by interpret().
|
private |
Definition at line 889 of file O3prmrInterpreter.cpp.
References m_bn_engine, and gum::prm::o3prmr::SetGndEngineCommand::value.
Referenced by interpret().
void gum::prm::o3prmr::O3prmrInterpreter::setSyntaxMode | ( | bool | f | ) |
syntax mode don't process anything, just check syntax.
Definition at line 114 of file O3prmrInterpreter.cpp.
References m_syntax_flag.
void gum::prm::o3prmr::O3prmrInterpreter::setVerboseMode | ( | bool | f | ) |
verbose mode show more details on the program execution.
Definition at line 120 of file O3prmrInterpreter.cpp.
References m_verbose.
void gum::prm::o3prmr::O3prmrInterpreter::showElegantErrors | ( | std::ostream & | o = std::cerr | ) | const |
send on std::cerr the list of errors
Definition at line 959 of file O3prmrInterpreter.cpp.
References gum::ErrorsContainer::elegantErrors(), and m_errors.
void gum::prm::o3prmr::O3prmrInterpreter::showElegantErrorsAndWarnings | ( | std::ostream & | o = std::cerr | ) | const |
send on std::cerr the list of errors or warnings
Definition at line 964 of file O3prmrInterpreter.cpp.
References gum::ErrorsContainer::elegantErrorsAndWarnings(), and m_errors.
void gum::prm::o3prmr::O3prmrInterpreter::showErrorCounts | ( | std::ostream & | o = std::cerr | ) | const |
send on std::cerr the number of errors and the number of warnings
Definition at line 969 of file O3prmrInterpreter.cpp.
References m_errors, and gum::ErrorsContainer::syntheticResults().
|
private |
Definition at line 745 of file O3prmrInterpreter.cpp.
References findSystemName(), gum::prm::PRM< GUM_SCALAR >::getSystem(), gum::prm::PRM< GUM_SCALAR >::isSystem(), m_context, gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::mainImport(), prm(), and gum::prm::o3prmr::ImportCommand::value.
Referenced by checkObserve(), checkQuery(), and checkUnobserve().
|
private |
Definition at line 791 of file O3prmrInterpreter.cpp.
References addError(), addWarning(), gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::chain, gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), m_inf, m_log, m_verbose, gum::prm::PRMInference< GUM_SCALAR >::removeEvidence(), and gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::value.
Referenced by interpret().
Size gum::prm::o3prmr::O3prmrInterpreter::warnings | ( | ) | const |
Definition at line 944 of file O3prmrInterpreter.cpp.
References m_errors, and gum::ErrorsContainer::warning_count.
|
private |
Definition at line 171 of file O3prmrInterpreter.h.
Referenced by generateInfEngine(), and ~O3prmrInterpreter().
|
private |
Definition at line 176 of file O3prmrInterpreter.h.
Referenced by checkSetGndEngine(), and setGndEngine().
|
private |
Definition at line 168 of file O3prmrInterpreter.h.
Referenced by addError(), addWarning(), checkSemantic(), findSystemName(), getContext(), interpretFile(), setContext(), system(), and ~O3prmrInterpreter().
|
private |
Definition at line 182 of file O3prmrInterpreter.h.
Referenced by addError(), addWarning(), and checkSemantic().
|
private |
Definition at line 175 of file O3prmrInterpreter.h.
Referenced by checkSetEngine(), generateInfEngine(), and setEngine().
|
private |
Definition at line 178 of file O3prmrInterpreter.h.
Referenced by addError(), addWarning(), checkSemantic(), count(), error(), errors(), errorsContainer(), import(), interpretFile(), interpretLine(), showElegantErrors(), showElegantErrorsAndWarnings(), showErrorCounts(), and warnings().
|
private |
Definition at line 173 of file O3prmrInterpreter.h.
Referenced by generateInfEngine(), inference(), observe(), query(), and unobserve().
|
private |
Definition at line 174 of file O3prmrInterpreter.h.
Referenced by generateInfEngine(), query(), and ~O3prmrInterpreter().
|
private |
Definition at line 181 of file O3prmrInterpreter.h.
Referenced by addError(), addWarning(), checkSemantic(), generateInfEngine(), import(), interpret(), observe(), query(), and unobserve().
|
private |
Definition at line 170 of file O3prmrInterpreter.h.
Referenced by addPath(), clearPaths(), getPaths(), import(), and interpretFile().
|
private |
Definition at line 169 of file O3prmrInterpreter.h.
Referenced by import(), interpretFile(), prm(), and ~O3prmrInterpreter().
|
private |
Definition at line 177 of file O3prmrInterpreter.h.
Referenced by interpretFile(), interpretLine(), query(), and results().
|
private |
Definition at line 179 of file O3prmrInterpreter.h.
Referenced by isInSyntaxMode(), and setSyntaxMode().
|
private |
Definition at line 180 of file O3prmrInterpreter.h.
Referenced by addError(), addWarning(), checkSemantic(), generateInfEngine(), import(), interpret(), isVerboseMode(), observe(), query(), setVerboseMode(), and unobserve().