aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
gum::prm::o3prmr::O3prmrInterpreter Class Reference

Represents a O3PRMR context. More...

#include <O3prmrInterpreter.h>

Collaboration diagram for gum::prm::o3prmr::O3prmrInterpreter:
[legend]

Public Member Functions

 O3prmrInterpreter ()
 This constructor create an empty context.
 ~O3prmrInterpreter ()
 Destructor. Delete current context.
bool interpretFile (std::string_view filename)
 Interpret the file or the command line.
bool interpretLine (std::string_view line)
const gum::prm::PRM< double > * prm () const
 Retrieve prm object.
const gum::prm::PRMInference< double > * inference () const
 Retrieve inference motor object.
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.
ErrorsContainer errorsContainer () const
 Return container with all errors.
O3prmrContext< double > * getContext () const
 Getter and setter for the context.
void setContext (O3prmrContext< double > *context)
 Setter for the context.
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.
void addPath (std::string path)
 Root paths to search from there packages. Default are './' and one is calculate from request package if any.
void clearPaths ()
 Root paths to search from there packages. Default are './' and one is calculate from request package if any.
bool isInSyntaxMode () const
 syntax mode don't process anything, just check syntax. Default is false.
void setSyntaxMode (bool f)
 syntax mode don't process anything, just check syntax.
bool isVerboseMode () const
 verbose mode show more details on the program execution. Default is false.
void setVerboseMode (bool f)
 verbose mode show more details on the program execution.
Size count () const
 En cas d'échec, l'API de gestion d'erreurs est présente.
Size errors () const
Size warnings () const
ParseError error (Idx i) const
 throw a string error if i >= count
void showElegantErrors (std::ostream &o=std::cerr) const
 send on std::cerr the list of errors
void showElegantErrorsAndWarnings (std::ostream &o=std::cerr) const
 send on std::cerr the list of errors or warnings
void showErrorCounts (std::ostream &o=std::cerr) const
 send on std::cerr the number of errors and the number of warnings

Private Member Functions

bool checkSemantic (O3prmrContext< double > *context)
 Check semantic validity of context.
bool checkSetEngine (SetEngineCommand *command)
bool checkSetGndEngine (SetGndEngineCommand *command)
bool checkObserve (ObserveCommand< double > *command)
bool checkUnobserve (UnobserveCommand< double > *command)
bool checkQuery (QueryCommand< double > *command)
bool interpret (O3prmrContext< double > *c)
 Crée le prm correspondant au contexte courant.
bool import (O3prmrContext< double > *context, std::string import)
bool observe (const ObserveCommand< double > *command)
bool unobserve (const UnobserveCommand< double > *command)
void query (const QueryCommand< double > *command)
void setEngine (const SetEngineCommand *command)
void setGndEngine (const SetGndEngineCommand *command)
std::string findSystemName (std::string &s)
std::string findInstanceName (std::string &s, const gum::prm::PRMSystem< double > &sys)
std::string findAttributeName (std::string_view s, const gum::prm::PRMInstance< double > &instance)
const PRMSystem< double > & system (std::string &ident)
void generateInfEngine (const gum::prm::PRMSystem< double > &sys)
void addError (std::string msg)
void addWarning (std::string msg)
std::string _readFile_ (std::string_view file)

Private Attributes

O3prmrContext< double > * m_context
gum::prm::o3prm::O3prmReader< double > * m_reader
std::vector< std::string > m_paths
gum::BayesNet< double > * m_bn
gum::prm::PRMInference< double > * m_inf
HashTable< const PRMSystem< double > *, PRMInference< double > * > m_inf_map
std::string m_engine
std::string m_bn_engine
std::vector< QueryResult > m_results
gum::ErrorsContainer m_errors
bool m_syntax_flag
bool m_verbose
std::ostream & m_log
int m_current_line

Detailed Description

Represents a O3PRMR context.

O3prmr use the <double> version of the O3PRM templatized ecosystem

Definition at line 87 of file O3prmrInterpreter.h.

Constructor & Destructor Documentation

◆ O3prmrInterpreter()

gum::prm::o3prmr::O3prmrInterpreter::O3prmrInterpreter ( )

This constructor create an empty context.

Definition at line 76 of file O3prmrInterpreter.cpp.

76 :
77 m_context(new O3prmrContext< double >()), m_reader(new o3prm::O3prmReader< double >()),
78 m_bn(0), m_inf(0), m_syntax_flag(false), m_verbose(false), m_log(std::cout),
79 m_current_line(-1) {}
gum::prm::PRMInference< double > * m_inf
O3prmrContext< double > * m_context
gum::prm::o3prm::O3prmReader< double > * m_reader

References m_bn, m_context, m_current_line, m_inf, m_log, m_reader, m_syntax_flag, and m_verbose.

◆ ~O3prmrInterpreter()

gum::prm::o3prmr::O3prmrInterpreter::~O3prmrInterpreter ( )

Destructor. Delete current context.

Definition at line 82 of file O3prmrInterpreter.cpp.

82 {
83 delete m_context;
84 if (m_bn) { delete m_bn; }
85 for (auto p: m_inf_map) {
86 delete p.second;
87 }
88 delete m_reader->prm();
89 delete m_reader;
90 }
gum::prm::PRM< GUM_SCALAR > * prm()
HashTable< const PRMSystem< double > *, PRMInference< double > * > m_inf_map

References m_bn, m_context, m_inf_map, m_reader, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm().

Here is the call graph for this function:

Member Function Documentation

◆ _readFile_()

std::string gum::prm::o3prmr::O3prmrInterpreter::_readFile_ ( std::string_view file)
private

Definition at line 199 of file O3prmrInterpreter.cpp.

199 {
200 // read entire file into string
201 std::ifstream istream(std::string(file), std::ifstream::binary);
202 if (istream) {
203 // get length of file:
204 istream.seekg(0, istream.end);
205 int length = int(istream.tellg());
206 istream.seekg(0, istream.beg);
207
208 std::string str;
209 str.resize(length, ' '); // reserve space
210 char* begin = &*str.begin();
211
212 istream.read(begin, length);
213 istream.close();
214
215 return str;
216 }
217 GUM_ERROR(OperationNotAllowed, "Could not open file")
218 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References GUM_ERROR.

Referenced by interpretFile().

Here is the caller graph for this function:

◆ addError()

void gum::prm::o3prmr::O3prmrInterpreter::addError ( std::string msg)
private

Definition at line 934 of file O3prmrInterpreter.cpp.

934 {
936
937 if (m_verbose) m_log << m_errors.last().toString() << std::endl;
938 }
ParseError last() const
Returns the last added error.
void addError(std::string_view msg, std::string_view filename, Idx line, Idx col)
Adds an error.
std::string toString() const
Return a std::string representation of this gum::ParseError.

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(), and interpret().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addPath()

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 112 of file O3prmrInterpreter.cpp.

112 {
113 if (path.length() && path.back() != '/') { path = path + '/'; }
114
115 std::filesystem::directory_entry dir(path);
116 if (dir.exists()) {
117 m_paths.push_back(path);
118 } else {
119 GUM_ERROR(NotFound, "not a directory")
120 }
121 }
std::vector< std::string > m_paths

References GUM_ERROR, and m_paths.

◆ addWarning()

void gum::prm::o3prmr::O3prmrInterpreter::addWarning ( std::string msg)
private

Definition at line 941 of file O3prmrInterpreter.cpp.

941 {
943
944 if (m_verbose) m_log << m_errors.last().toString() << std::endl;
945 }
void addWarning(std::string_view msg, std::string_view filename, Idx line, Idx col)
Adds a warning.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkObserve()

bool gum::prm::o3prmr::O3prmrInterpreter::checkObserve ( ObserveCommand< double > * command)
private

Definition at line 433 of file O3prmrInterpreter.cpp.

433 {
434 try {
435 std::string left_val = command->leftValue;
436 const std::string right_val = command->rightValue;
437
438 // Contruct the pair (instance,attribut)
439 const PRMSystem< double >& sys = system(left_val);
440 const PRMInstance< double >& instance = sys.get(findInstanceName(left_val, sys));
441 const PRMAttribute< double >& attr = instance.get(findAttributeName(left_val, instance));
442 typename PRMInference< double >::Chain chain = std::make_pair(&instance, &attr);
443
444 command->system = &sys;
445 command->chain = std::make_pair(&instance, &attr);
446
447 // Check label exists for this type.
448 // Tensor<double> e;
449 command->potentiel.add(chain.second->type().variable());
450 Instantiation i(command->potentiel);
451 bool found = false;
452
453 for (i.setFirst(); !i.end(); i.inc()) {
454 if (chain.second->type().variable().label(i.val(chain.second->type().variable()))
455 == right_val) {
456 command->potentiel.set(i, (double)1.0);
457 found = true;
458 } else {
459 command->potentiel.set(i, (double)0.0);
460 }
461 }
462
463 if (!found) addError(right_val + " is not a label of " + left_val);
464
465 // else command->potentiel = e;
466
467 return found;
468 } catch (Exception& err) { addError(err.errorContent()); } catch (std::string& err) {
469 addError(err);
470 }
471
472 return false;
473 }
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > * > Chain
Code alias.
const PRMSystem< double > & system(std::string &ident)
std::string findAttributeName(std::string_view s, const gum::prm::PRMInstance< double > &instance)
std::string findInstanceName(std::string &s, const gum::prm::PRMSystem< double > &sys)

References addError(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::chain, gum::Instantiation::end(), gum::Exception::errorContent(), findAttributeName(), findInstanceName(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::prm::PRMSystem< 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(), system(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::system, and gum::Instantiation::val().

Referenced by checkSemantic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkQuery()

bool gum::prm::o3prmr::O3prmrInterpreter::checkQuery ( QueryCommand< double > * command)
private

Definition at line 497 of file O3prmrInterpreter.cpp.

497 {
498 try {
499 std::string name = command->value;
500
501 // Contruct the pair (instance,attribut)
502 const PRMSystem< double >& sys = system(name);
503 const PRMInstance< double >& instance = sys.get(findInstanceName(name, sys));
504 const PRMAttribute< double >& attr = instance.get(findAttributeName(name, instance));
505 // PRMInference<double>::Chain chain = std::make_pair(&instance,
506 // &attr);
507
508 command->system = &sys;
509 command->chain = std::make_pair(&instance, &attr);
510
511 return true;
512 } catch (Exception& err) { addError(err.errorContent()); } catch (std::string& err) {
513 addError(err);
514 }
515
516 return false;
517 }

References addError(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::chain, gum::Exception::errorContent(), findAttributeName(), findInstanceName(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::prm::PRMSystem< GUM_SCALAR >::get(), system(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::system, and gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::value.

Referenced by checkSemantic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkSemantic()

bool gum::prm::o3prmr::O3prmrInterpreter::checkSemantic ( O3prmrContext< double > * context)
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 317 of file O3prmrInterpreter.cpp.

317 {
318 // Don't parse if any syntax errors.
319 if (errors() > 0) return false;
320
321 // On importe tous les systèmes.
322 for (const auto command: context->imports()) {
323 m_current_line = command->line;
324 // if import doen't succed stop here unless syntax mode is activated.
325 bool succeed = import(context, command->value);
326
327 if (!succeed && !isInSyntaxMode()) return false;
328
329 // En cas de succès, on met à jour le contexte global
330 if (succeed) m_context->addImport(*command);
331 }
332
333 if (m_verbose)
334 m_log << "## Check semantic for " << context->sessions().size() << " sessions"
335 << std::endl;
336
337 // On vérifie chaque session
338 for (const auto session: context->sessions()) {
339 std::string sessionName = session->name();
340 O3prmrSession< double >* new_session = new O3prmrSession< double >(sessionName);
341
342 if (m_verbose)
343 m_log << "## Start session '" << sessionName << "'..." << std::endl << std::endl;
344
345 for (const auto command: session->commands()) {
346 if (m_verbose)
347 m_log << "# * Going to check command : " << command->toString() << std::endl;
348
349 // Update the current line (for warnings and errors)
350 m_current_line = command->line;
351
352 // We check it.
353 bool result = true;
354
355 try {
356 switch (command->type()) {
358 result = checkSetEngine((SetEngineCommand*)command);
359 break;
360
362 result = checkSetGndEngine((SetGndEngineCommand*)command);
363 break;
364
366 result = checkObserve((ObserveCommand< double >*)command);
367 break;
368
370 result = checkUnobserve((UnobserveCommand< double >*)command);
371 break;
372
374 result = checkQuery((QueryCommand< double >*)command);
375 break;
376
377 default :
378 addError("Error : Unknow command : " + command->toString()
379 + "\n -> Command not processed.");
380 result = false;
381 }
382 } catch (Exception& err) {
383 result = false;
384 addError(err.errorContent());
385 } catch (std::string& err) {
386 result = false;
387 addError(err);
388 }
389
390 // If there was a problem, skip the rest of this session,
391 // unless syntax mode is activated.
392 if (!result && !isInSyntaxMode()) {
393 if (m_verbose) m_log << "Errors : skip the rest of this session." << std::endl;
394
395 break;
396 }
397
398 // On l'ajoute au contexte globale
399 if (result) new_session->addCommand((const O3prmrCommand*)command);
400 }
401
402 // Ajoute la session au contexte global,
403 // ou à la dernière session.
404 if (sessionName == "default" && m_context->sessions().size() > 0)
405 *(m_context->sessions().back()) += *new_session;
406 else m_context->addSession(*new_session);
407
408 if (m_verbose)
409 m_log << std::endl
410 << "## Session '" << sessionName << "' finished." << std::endl
411 << std::endl
412 << std::endl;
413
414 // todo : check memory leak
415 // delete new_session; ??
416 }
417
419
420 return errors() == 0;
421 }
void elegantErrorsAndWarnings(std::ostream &o) const
Print errors on output stream.
void addImport(int line, std::string_view import, std::string_view alias)
std::vector< O3prmrSession< GUM_SCALAR > * > sessions() const
void addSession(const O3prmrSession< GUM_SCALAR > &session)
bool checkQuery(QueryCommand< double > *command)
bool checkSetGndEngine(SetGndEngineCommand *command)
bool checkObserve(ObserveCommand< double > *command)
bool isInSyntaxMode() const
syntax mode don't process anything, just check syntax. Default is false.
bool checkUnobserve(UnobserveCommand< double > *command)
bool isVerboseMode() const
verbose mode show more details on the program execution. Default is false.
bool checkSetEngine(SetEngineCommand *command)
O3prmrSession(std::string_view name="")

References gum::prm::o3prmr::O3prmrSession< GUM_SCALAR >::O3prmrSession(), 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::SetEngineCommand::toString(), and gum::prm::o3prmr::O3prmrCommand::Unobserve.

Referenced by interpretFile(), and interpretLine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkSetEngine()

bool gum::prm::o3prmr::O3prmrInterpreter::checkSetEngine ( SetEngineCommand * command)
private

Definition at line 423 of file O3prmrInterpreter.cpp.

423 {
424 m_engine = command->value;
425 return m_engine == "SVED" || m_engine == "GRD" || m_engine == "SVE";
426 }

References m_engine, and gum::prm::o3prmr::SetEngineCommand::value.

Referenced by checkSemantic().

Here is the caller graph for this function:

◆ checkSetGndEngine()

bool gum::prm::o3prmr::O3prmrInterpreter::checkSetGndEngine ( SetGndEngineCommand * command)
private

Definition at line 428 of file O3prmrInterpreter.cpp.

428 {
429 m_bn_engine = command->value;
430 return m_bn_engine == "VE" || m_bn_engine == "VEBB" || m_bn_engine == "lazy";
431 }

References m_bn_engine, and gum::prm::o3prmr::SetGndEngineCommand::value.

Referenced by checkSemantic().

Here is the caller graph for this function:

◆ checkUnobserve()

bool gum::prm::o3prmr::O3prmrInterpreter::checkUnobserve ( UnobserveCommand< double > * command)
private

Definition at line 475 of file O3prmrInterpreter.cpp.

475 {
476 try {
477 std::string name = command->value;
478
479 // Contruct the pair (instance,attribut)
480 const PRMSystem< double >& sys = system(name);
481 const PRMInstance< double >& instance = sys.get(findInstanceName(name, sys));
482 const PRMAttribute< double >& attr = instance.get(findAttributeName(name, instance));
483 // PRMInference<double>::Chain chain = std::make_pair(&instance,
484 // &attr);
485
486 command->system = &sys;
487 command->chain = std::make_pair(&instance, &attr);
488
489 return true;
490 } catch (Exception& err) { addError(err.errorContent()); } catch (std::string& err) {
491 addError(err);
492 }
493
494 return false;
495 }

References addError(), gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::chain, gum::Exception::errorContent(), findAttributeName(), findInstanceName(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::prm::PRMSystem< GUM_SCALAR >::get(), system(), gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::system, and gum::prm::o3prmr::UnobserveCommand< GUM_SCALAR >::value.

Referenced by checkSemantic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearPaths()

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 125 of file O3prmrInterpreter.cpp.

125{ m_paths.clear(); }

References m_paths.

◆ count()

Size gum::prm::o3prmr::O3prmrInterpreter::count ( ) const

En cas d'échec, l'API de gestion d'erreurs est présente.

of errors + warnings

Definition at line 897 of file O3prmrInterpreter.cpp.

897{ return m_errors.count(); }
Size count() const
Returns the number of errors and warnings.

References gum::ErrorsContainer::count(), and m_errors.

Referenced by error(), and import().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error()

ParseError gum::prm::o3prmr::O3prmrInterpreter::error ( Idx i) const

throw a string error if i >= count

Definition at line 906 of file O3prmrInterpreter.cpp.

906 {
907 if (i >= count()) throw "Index out of bound.";
908
909 return m_errors.error(i);
910 }
ParseError error(Idx i) const
Returns the i-th error.
Size count() const
En cas d'échec, l'API de gestion d'erreurs est présente.

References count(), gum::ErrorsContainer::error(), and m_errors.

Here is the call graph for this function:

◆ errors()

Size gum::prm::o3prmr::O3prmrInterpreter::errors ( ) const

of errors

Definition at line 900 of file O3prmrInterpreter.cpp.

900{ return m_errors.error_count; }
Size error_count
Number of errors detected.

References gum::ErrorsContainer::error_count, and m_errors.

Referenced by checkSemantic(), import(), interpret(), interpretFile(), and interpretLine().

Here is the caller graph for this function:

◆ errorsContainer()

ErrorsContainer gum::prm::o3prmr::O3prmrInterpreter::errorsContainer ( ) const

Return container with all errors.

Definition at line 913 of file O3prmrInterpreter.cpp.

913{ return m_errors; }

References m_errors.

◆ findAttributeName()

std::string gum::prm::o3prmr::O3prmrInterpreter::findAttributeName ( std::string_view s,
const gum::prm::PRMInstance< double > & instance )
private

Definition at line 709 of file O3prmrInterpreter.cpp.

710 {
711 if (!instance.exists(s))
712 throw "'" + std::string{s} + "' is not an attribute of instance '" + instance.name()
713 + "'.";
714
715 return std::string{s};
716 }
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
const std::string & name() const
Returns the name of this object.

References gum::prm::PRMInstance< GUM_SCALAR >::exists(), and gum::prm::PRMObject::name().

Referenced by checkObserve(), checkQuery(), and checkUnobserve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findInstanceName()

std::string gum::prm::o3prmr::O3prmrInterpreter::findInstanceName ( std::string & s,
const gum::prm::PRMSystem< double > & sys )
private

Definition at line 696 of file O3prmrInterpreter.cpp.

697 {
698 // We have found system before, so 's' has been stripped.
699 size_t dot = s.find_first_of('.');
700 std::string name = s.substr(0, dot);
701
702 if (!sys.exists(name))
703 throw "'" + name + "' is not an instance of system '" + sys.name() + "'.";
704
705 s = s.substr(dot + 1);
706 return name;
707 }
bool exists(std::string_view name) const
Retruns true either if name is an instance or an array in this PRMSystem.

References gum::prm::PRMSystem< GUM_SCALAR >::exists(), and gum::prm::PRMObject::name().

Referenced by checkObserve(), checkQuery(), and checkUnobserve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findSystemName()

std::string gum::prm::o3prmr::O3prmrInterpreter::findSystemName ( std::string & s)
private

Definition at line 668 of file O3prmrInterpreter.cpp.

668 {
669 size_t dot = s.find_first_of('.');
670 std::string name = s.substr(0, dot);
671
672 // We look first for real system, next for alias.
673 if (prm()->isSystem(name)) {
674 s = s.substr(dot + 1);
675 return name;
676 }
677
678 if (!m_context->aliasToImport(name).empty()) {
679 s = s.substr(dot + 1);
680 return m_context->aliasToImport(name);
681 }
682
683 while (dot != std::string::npos) {
684 if (prm()->isSystem(name)) {
685 s = s.substr(dot + 1);
686 return name;
687 }
688
689 dot = s.find('.', dot + 1);
690 name = s.substr(0, dot);
691 }
692
693 throw "could not find any system in '" + s + "'.";
694 }
std::string aliasToImport(std::string_view alias)
const gum::prm::PRM< double > * prm() const
Retrieve prm object.

References gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::aliasToImport(), m_context, and prm().

Referenced by system().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateInfEngine()

void gum::prm::o3prmr::O3prmrInterpreter::generateInfEngine ( const gum::prm::PRMSystem< double > & sys)
private

Definition at line 855 of file O3prmrInterpreter.cpp.

855 {
856 if (m_verbose) m_log << "# Building the inference engine... " << std::flush;
857
858 //
859 if (m_engine == "SVED") {
860 m_inf = new SVED< double >(*(prm()), sys);
861
862 //
863 } else if (m_engine == "SVE") {
864 m_inf = new SVE< double >(*(prm()), sys);
865 } else {
866 if (m_engine != "GRD") {
867 addWarning("unkown engine '" + m_engine + "', use GRD insteed.");
868 }
869
870 MarginalTargetedInference< double >* bn_inf = nullptr;
871 if (m_bn) { delete m_bn; }
872 m_bn = new BayesNet< double >();
874
875 if (m_verbose) m_log << "(Grounding the network... " << std::flush;
876
877 sys.groundedBN(bn_factory);
878
879 if (m_verbose) m_log << "Finished)" << std::flush;
880
881 // bn_inf = new LazyPropagation<double>( *m_bn );
883
884 auto grd_inf = new GroundedInference< double >(*(prm()), sys);
885 grd_inf->setBNInference(bn_inf);
886 m_inf = grd_inf;
887 }
888
889 m_inf_map.insert(&sys, m_inf);
890 if (m_verbose) m_log << "Finished." << std::endl;
891 }
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian network of this system.
SVED(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
Default Constructor.
Definition SVED_tpl.h:485
SVE(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default Constructor.
Definition SVE_tpl.h:623
template class GUM_PUBLIC_BN BayesNetFactory< double >
template class GUM_PUBLIC_BN BayesNet< double >
Definition BayesNet.cpp:48
template class GUM_PUBLIC_BN VariableElimination< double >

References gum::prm::GroundedInference< GUM_SCALAR >::GroundedInference(), gum::prm::SVE< GUM_SCALAR >::SVE(), gum::prm::SVED< GUM_SCALAR >::SVED(), addWarning(), gum::BayesNet< double >, gum::BayesNetFactory< double >, gum::prm::PRMSystem< GUM_SCALAR >::groundedBN(), m_bn, m_engine, m_inf, m_inf_map, m_log, m_verbose, prm(), and gum::VariableElimination< double >.

Referenced by observe(), and query().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContext()

O3prmrContext< double > * gum::prm::o3prmr::O3prmrInterpreter::getContext ( ) const

Getter and setter for the context.

Getter for the context.

Definition at line 96 of file O3prmrInterpreter.cpp.

96{ return m_context; }

References m_context.

◆ getPaths()

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 108 of file O3prmrInterpreter.cpp.

108{ return m_paths; }

References m_paths.

◆ import()

bool gum::prm::o3prmr::O3prmrInterpreter::import ( O3prmrContext< double > * context,
std::string import )
private

Definition at line 522 of file O3prmrInterpreter.cpp.

522 {
523 try {
524 if (m_verbose) { m_log << "# Loading system '" << import_name << "' => '" << std::flush; }
525
526 std::string import_package = import_name;
527
528 std::replace(import_name.begin(), import_name.end(), '.', '/');
529 import_name += ".o3prm";
530
531 if (m_verbose) { m_log << import_name << "' ... " << std::endl << std::flush; }
532
533 std::ifstream file_test;
534 bool found = false;
535 std::string import_abs_filename;
536
537 // Search in o3prmr file dir.
538 std::string o3prmrFilename = context->filename();
539
540 if (!o3prmrFilename.empty()) {
541 if (auto index = o3prmrFilename.find_last_of('/'); index != std::string::npos) {
542 std::string dir = o3prmrFilename.substr(0, index + 1);
543 import_abs_filename = dir + import_name;
544
545 if (m_verbose) {
546 m_log << "# Search from filedir '" << import_abs_filename << "' ... " << std::flush;
547 }
548
549 file_test.open(import_abs_filename.c_str());
550
551 if (file_test.is_open()) {
552 if (m_verbose) { m_log << "found !" << std::endl << std::flush; }
553
554 file_test.close();
555 found = true;
556 } else if (m_verbose) {
557 m_log << "not found." << std::endl << std::flush;
558 }
559 }
560 }
561
562 // Deduce root path from package name.
563 std::string package = context->package();
564
565 if (!found && !package.empty()) {
566 std::string root;
567
568 // if filename is not empty, start from it.
569 std::string filename = context->filename();
570
571 if (!filename.empty()) {
572 if (auto size = filename.find_last_of('/'); size != std::string::npos) {
573 root += filename.substr(0, size + 1); // take with the '/'
574 }
575 }
576
577 //
578 root += "../";
579 int count = (int)std::count(package.begin(), package.end(), '.');
580
581 for (int i = 0; i < count; i++)
582 root += "../";
583
584 import_abs_filename = std::filesystem::absolute(std::filesystem::path(root)
585 / std::filesystem::path(import_name))
586 .string();
587
588 if (m_verbose) {
589 m_log << "# Search from package '" << package << "' => '" << import_abs_filename
590 << "' ... " << std::flush;
591 }
592
593 file_test.open(import_abs_filename.c_str());
594
595 if (file_test.is_open()) {
596 if (m_verbose) { m_log << "found !" << std::endl << std::flush; }
597
598 file_test.close();
599 found = true;
600 } else if (m_verbose) {
601 m_log << "not found." << std::endl << std::flush;
602 }
603 }
604
605 // Search import in all paths.
606 for (const auto& path: m_paths) {
607 import_abs_filename = path + import_name;
608
609 if (m_verbose) {
610 m_log << "# Search from classpath '" << import_abs_filename << "' ... " << std::flush;
611 }
612
613 file_test.open(import_abs_filename.c_str());
614
615 if (file_test.is_open()) {
616 if (m_verbose) { m_log << " found !" << std::endl << std::flush; }
617
618 file_test.close();
619 found = true;
620 break;
621 } else if (m_verbose) {
622 m_log << " not found." << std::endl << std::flush;
623 }
624 }
625
626 if (!found) {
627 if (m_verbose) { m_log << "Finished with errors." << std::endl; }
628
629 addError("import not found.");
630 return false;
631 }
632
633 // May throw std::IOError if file does't exist
634 Size previousO3prmError = m_reader->errors();
635 Size previousO3prmrError = errors();
636
637 try {
638 m_reader->readFile(import_abs_filename, import_package);
639
640 // Show errors and warning
641 if (m_verbose
642 && (m_reader->errors() > (unsigned int)previousO3prmError
643 || errors() > previousO3prmrError)) {
644 m_log << "Finished with errors." << std::endl;
645 } else if (m_verbose) {
646 m_log << "Finished." << std::endl;
647 }
648 } catch (const IOError& err) {
649 if (m_verbose) { m_log << "Finished with errors." << std::endl; }
650
651 addError(err.errorContent());
652 }
653
654 // Add o3prm errors and warnings to o3prmr errors
655 for (; previousO3prmError < m_reader->errorsContainer().count(); previousO3prmError++) {
656 m_errors.add(m_reader->errorsContainer().error(previousO3prmError));
657 }
658
659 return errors() == previousO3prmrError;
660 } catch (const Exception& err) {
661 if (m_verbose) { m_log << "Finished with exceptions." << std::endl; }
662
663 addError(err.errorContent());
664 return false;
665 }
666 }
GUM_NODISCARD std::string errorContent() const
Returns the message content.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

References addError(), count(), gum::Exception::errorContent(), errors(), gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::filename(), m_errors, m_log, m_paths, m_reader, and m_verbose.

Here is the call graph for this function:

◆ inference()

const PRMInference< double > * gum::prm::o3prmr::O3prmrInterpreter::inference ( ) const

Retrieve inference motor object.

Definition at line 143 of file O3prmrInterpreter.cpp.

143{ return m_inf; }

References m_inf.

◆ interpret()

bool gum::prm::o3prmr::O3prmrInterpreter::interpret ( O3prmrContext< double > * c)
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 246 of file O3prmrInterpreter.cpp.

246 {
247 if (isVerboseMode()) m_log << "## Start interpretation." << std::endl << std::flush;
248
249 // Don't parse if any syntax errors.
250 if (errors() > 0) return false;
251
252 // For each session
253 std::vector< O3prmrSession< double >* > sessions = c->sessions();
254
255 for (const auto session: sessions)
256 for (auto command: session->commands()) {
257 // We process it.
258 bool result = true;
259
260 try {
261 switch (command->type()) {
263 result = observe((ObserveCommand< double >*)command);
264 break;
265
267 result = unobserve((UnobserveCommand< double >*)command);
268 break;
269
271 setEngine((SetEngineCommand*)command);
272 break;
273
275 setGndEngine((SetGndEngineCommand*)command);
276 break;
277
279 query((QueryCommand< double >*)command);
280 break;
281 }
282 } catch (Exception& err) {
283 result = false;
284 addError(err.errorContent());
285 } catch (std::string& err) {
286 result = false;
287 addError(err);
288 }
289
290 // If there was a problem, skip the rest of this session,
291 // unless syntax mode is activated.
292 if (!result) {
293 if (m_verbose) m_log << "Errors : skip the rest of this session." << std::endl;
294
295 break;
296 }
297 }
298
299 if (isVerboseMode()) m_log << "## End interpretation." << std::endl << std::flush;
300
301 return errors() == 0;
302 }
bool observe(const ObserveCommand< double > *command)
void setGndEngine(const SetGndEngineCommand *command)
void setEngine(const SetEngineCommand *command)
void query(const QueryCommand< double > *command)
bool unobserve(const UnobserveCommand< double > *command)

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpretFile()

bool gum::prm::o3prmr::O3prmrInterpreter::interpretFile ( std::string_view 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 157 of file O3prmrInterpreter.cpp.

157 {
158 m_results.clear();
159
160 try {
161 std::string file_content = _readFile_(filename);
162
163 delete m_context;
164 m_context = new O3prmrContext< double >(std::string(filename));
165 O3prmrContext< double > c{std::string(filename)};
166
167 // On vérifie la syntaxe
168 unsigned char* buffer = new unsigned char[file_content.length() + 1];
169 strcpy((char*)buffer, file_content.c_str());
170 Scanner s(buffer, int(file_content.length() + 1));
171 Parser p(&s);
172 p.setO3prmrContext(&c);
173 p.Parse();
174
175 m_errors = p.errors();
176
177 if (errors() > 0) { return false; }
178
179 // Set paths to search from.
180 delete m_reader->prm();
181 delete m_reader;
182 m_reader = new o3prm::O3prmReader< double >();
183
184 for (size_t i = 0; i < m_paths.size(); i++) {
186 }
187
188 // On vérifie la sémantique.
189 if (!checkSemantic(&c)) { return false; }
190
191 if (isInSyntaxMode()) {
192 return true;
193 } else {
194 return interpret(&c);
195 }
196 } catch (gum::Exception&) { return false; }
197 }
std::vector< ParseError > errors
The list of gum::ParseError contained in this gum::ErrorsContainer.
void addClassPath(std::string_view class_path)
Add a list of paths to look for o3prm files.
std::string _readFile_(std::string_view file)
std::vector< QueryResult > m_results
bool checkSemantic(O3prmrContext< double > *context)
Check semantic validity of context.
bool interpret(O3prmrContext< double > *c)
Crée le prm correspondant au contexte courant.

References _readFile_(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::addClassPath(), checkSemantic(), errors(), interpret(), isInSyntaxMode(), m_context, m_errors, m_paths, m_reader, m_results, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm().

Here is the call graph for this function:

◆ interpretLine()

bool gum::prm::o3prmr::O3prmrInterpreter::interpretLine ( std::string_view line)

Definition at line 220 of file O3prmrInterpreter.cpp.

220 {
221 m_results.clear();
222
223 // On vérifie la syntaxe
224 O3prmrContext< double > c;
225 Scanner s((unsigned char*)line.data(), (int)line.length());
226 Parser p(&s);
227 p.setO3prmrContext(&c);
228 p.Parse();
229 m_errors = p.errors();
230
231 if (errors() > 0) return false;
232
233 // On vérifie la sémantique.
234 if (!checkSemantic(&c)) return false;
235
236 if (isInSyntaxMode()) return true;
237 else return interpret(&c);
238 }

References checkSemantic(), errors(), interpret(), isInSyntaxMode(), m_errors, and m_results.

Here is the call graph for this function:

◆ isInSyntaxMode()

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 128 of file O3prmrInterpreter.cpp.

128{ return m_syntax_flag; }

References m_syntax_flag.

Referenced by checkSemantic(), interpretFile(), and interpretLine().

Here is the caller graph for this function:

◆ isVerboseMode()

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 134 of file O3prmrInterpreter.cpp.

134{ return m_verbose; }

References m_verbose.

Referenced by checkSemantic(), and interpret().

Here is the caller graph for this function:

◆ observe()

bool gum::prm::o3prmr::O3prmrInterpreter::observe ( const ObserveCommand< double > * command)
private

Definition at line 733 of file O3prmrInterpreter.cpp.

733 {
734 const typename PRMInference< double >::Chain& chain = command->chain;
735
736 // Generate the inference engine if it doesn't exist.
737 if (!m_inf) { generateInfEngine(*(command->system)); }
738
739 // Prevent from something
740 if (m_inf->hasEvidence(chain)) addWarning(command->leftValue + " is already observed");
741
742 m_inf->addEvidence(chain, command->potentiel);
743
744 if (m_verbose)
745 m_log << "# Added evidence " << command->rightValue << " over attribute "
746 << command->leftValue << std::endl;
747
748 return true;
749 } catch (OperationNotAllowed& ex) {
750 addError("something went wrong when adding evidence " + command->rightValue + " over "
751 + command->leftValue + " : " + ex.errorContent());
752 return false;
753 } catch (const std::string& msg) {
754 addError(msg);
755 return false;
756 }
void addEvidence(const Chain &chain, const Tensor< GUM_SCALAR > &p)
Add an evidence to the given instance's elt.
bool hasEvidence(const PRMInstance< GUM_SCALAR > &i) const
Returns true if i has evidence.
void generateInfEngine(const gum::prm::PRMSystem< double > &sys)

References gum::prm::PRMInference< GUM_SCALAR >::addEvidence(), addWarning(), gum::prm::o3prmr::ObserveCommand< GUM_SCALAR >::chain, 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prm()

const PRM< double > * gum::prm::o3prmr::O3prmrInterpreter::prm ( ) const

Retrieve prm object.

Definition at line 140 of file O3prmrInterpreter.cpp.

140{ return m_reader->prm(); }

References m_reader, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm().

Referenced by findSystemName(), generateInfEngine(), and system().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ query()

void gum::prm::o3prmr::O3prmrInterpreter::query ( const QueryCommand< double > * command)
private

Definition at line 780 of file O3prmrInterpreter.cpp.

780 {
781 const std::string& query = command->value;
782
783 if (m_inf_map.exists(command->system)) {
784 m_inf = m_inf_map[command->system];
785 } else {
786 m_inf = nullptr;
787 }
788
789 // Create inference engine if it has not been already created.
790 if (!m_inf) { generateInfEngine(*(command->system)); }
791
792 // Inference
793 if (m_verbose) {
794 m_log << "# Starting inference over query: " << query << "... " << std::endl;
795 }
796
797 Timer timer;
798 timer.reset();
799
801 m_inf->posterior(command->chain, m);
802
803 // Compute spent time
804 double t = timer.step();
805
806 if (m_verbose) { m_log << "Finished." << std::endl; }
807
808 if (m_verbose) { m_log << "# Time in seconds (accuracy ~0.001): " << t << std::endl; }
809
810 // Show results
811
812 if (m_verbose) { m_log << std::endl; }
813
814 QueryResult result;
815 result.command = query;
816 result.time = t;
817
818 Instantiation j(m);
819 const PRMAttribute< double >& attr = *(command->chain.second);
820
821 for (j.setFirst(); !j.end(); j.inc()) {
822 // auto label_value = j.val ( attr.type().variable() );
823 auto label_value = j.val(0);
824 std::string label = attr.type().variable().label(label_value);
825 float value = float(m.get(j));
826
827 SingleResult singleResult;
828 singleResult.label = label;
829 singleResult.p = value;
830
831 result.values.push_back(singleResult);
832
833 if (m_verbose) { m_log << label << " : " << value << std::endl; }
834 }
835
836 m_results.push_back(result);
837
838 if (m_verbose) { m_log << std::endl; }
839 } catch (Exception& e) {
840 GUM_SHOWERROR(e);
841 throw "something went wrong while infering: " + e.errorContent();
842 } catch (const std::string& msg) { addError(msg); }
void posterior(const Chain &chain, Tensor< GUM_SCALAR > &m)
Compute the posterior of the formal attribute pointed by chain and stores it in m.
#define GUM_SHOWERROR(e)
Definition exceptions.h:89
template class GUM_SHARED_PUBLIC Tensor< double >
Definition tensor.cpp:53

References gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::chain, gum::prm::o3prmr::QueryResult::command, gum::Instantiation::end(), generateInfEngine(), gum::MultiDimDecorator< GUM_ELEMENT >::get(), gum::Instantiation::inc(), gum::DiscreteVariable::label(), gum::prm::o3prmr::SingleResult::label, m_inf, m_inf_map, m_log, m_results, m_verbose, gum::prm::o3prmr::SingleResult::p, gum::prm::PRMInference< GUM_SCALAR >::posterior(), query(), gum::Timer::reset(), gum::Instantiation::setFirst(), gum::Timer::step(), gum::prm::o3prmr::QueryCommand< GUM_SCALAR >::system, gum::Tensor< double >, 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(), and query().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ results()

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 148 of file O3prmrInterpreter.cpp.

148{ return m_results; }

References m_results.

◆ setContext()

void gum::prm::o3prmr::O3prmrInterpreter::setContext ( O3prmrContext< double > * context)

Setter for the context.

Definition at line 99 of file O3prmrInterpreter.cpp.

99 {
100 delete m_context;
101
102 if (context == 0) m_context = new O3prmrContext< double >();
103 else m_context = context;
104 }

References m_context.

◆ setEngine()

void gum::prm::o3prmr::O3prmrInterpreter::setEngine ( const SetEngineCommand * command)
private

Definition at line 845 of file O3prmrInterpreter.cpp.

845 {
846 m_engine = command->value;
847 }

References m_engine, and gum::prm::o3prmr::SetEngineCommand::value.

Referenced by interpret().

Here is the caller graph for this function:

◆ setGndEngine()

void gum::prm::o3prmr::O3prmrInterpreter::setGndEngine ( const SetGndEngineCommand * command)
private

Definition at line 850 of file O3prmrInterpreter.cpp.

850 {
851 m_bn_engine = command->value;
852 }

References m_bn_engine, and gum::prm::o3prmr::SetGndEngineCommand::value.

Referenced by interpret().

Here is the caller graph for this function:

◆ setSyntaxMode()

void gum::prm::o3prmr::O3prmrInterpreter::setSyntaxMode ( bool f)

syntax mode don't process anything, just check syntax.

Definition at line 131 of file O3prmrInterpreter.cpp.

131{ m_syntax_flag = f; }

References m_syntax_flag.

◆ setVerboseMode()

void gum::prm::o3prmr::O3prmrInterpreter::setVerboseMode ( bool f)

verbose mode show more details on the program execution.

Definition at line 137 of file O3prmrInterpreter.cpp.

137{ m_verbose = f; }

References m_verbose.

◆ showElegantErrors()

void gum::prm::o3prmr::O3prmrInterpreter::showElegantErrors ( std::ostream & o = std::cerr) const

send on std::cerr the list of errors

Definition at line 916 of file O3prmrInterpreter.cpp.

916 {
918 }
void elegantErrors(std::ostream &o) const
Print errors on output stream.

References gum::ErrorsContainer::elegantErrors(), and m_errors.

Here is the call graph for this function:

◆ showElegantErrorsAndWarnings()

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 921 of file O3prmrInterpreter.cpp.

921 {
923 }

References gum::ErrorsContainer::elegantErrorsAndWarnings(), and m_errors.

Here is the call graph for this function:

◆ showErrorCounts()

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 926 of file O3prmrInterpreter.cpp.

926 {
928 }
void syntheticResults(std::ostream &o) const
Print errors on output stream.

References m_errors, and gum::ErrorsContainer::syntheticResults().

Here is the call graph for this function:

◆ system()

const PRMSystem< double > & gum::prm::o3prmr::O3prmrInterpreter::system ( std::string & ident)
private

Definition at line 719 of file O3prmrInterpreter.cpp.

719 {
720 try {
721 return prm()->getSystem(findSystemName(ident));
722 } catch (const std::string&) {}
723
724 if ((m_context->mainImport() != 0) && prm()->isSystem(m_context->mainImport()->value))
725 return prm()->getSystem(m_context->mainImport()->value);
726
727 throw "could not find any system or alias in '" + ident
728 + "' and no default alias has been set.";
729 }
const ImportCommand * mainImport() const
std::string findSystemName(std::string &s)

References findSystemName(), m_context, gum::prm::o3prmr::O3prmrContext< GUM_SCALAR >::mainImport(), prm(), and gum::prm::o3prmr::ImportCommand::value.

Referenced by checkObserve(), checkQuery(), and checkUnobserve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unobserve()

bool gum::prm::o3prmr::O3prmrInterpreter::unobserve ( const UnobserveCommand< double > * command)
private

Definition at line 760 of file O3prmrInterpreter.cpp.

760 {
761 std::string name = command->value;
762 typename PRMInference< double >::Chain chain = command->chain;
763
764 // Prevent from something
765 if (!m_inf || !m_inf->hasEvidence(chain)) {
766 addWarning(name + " was not observed");
767 } else {
768 m_inf->removeEvidence(chain);
769
770 if (m_verbose) m_log << "# Removed evidence over attribute " << name << std::endl;
771 }
772
773 return true;
774 } catch (const std::string& msg) {
775 addError(msg);
776 return false;
777 }
void removeEvidence(const Chain &chain)
Remove evidence on the given instance's elt.

References 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warnings()

Size gum::prm::o3prmr::O3prmrInterpreter::warnings ( ) const

of warnings

Definition at line 903 of file O3prmrInterpreter.cpp.

References m_errors, and gum::ErrorsContainer::warning_count.

Member Data Documentation

◆ m_bn

gum::BayesNet< double >* gum::prm::o3prmr::O3prmrInterpreter::m_bn
private

Definition at line 186 of file O3prmrInterpreter.h.

Referenced by O3prmrInterpreter(), ~O3prmrInterpreter(), and generateInfEngine().

◆ m_bn_engine

std::string gum::prm::o3prmr::O3prmrInterpreter::m_bn_engine
private

Definition at line 191 of file O3prmrInterpreter.h.

Referenced by checkSetGndEngine(), and setGndEngine().

◆ m_context

O3prmrContext< double >* gum::prm::o3prmr::O3prmrInterpreter::m_context
private

◆ m_current_line

int gum::prm::o3prmr::O3prmrInterpreter::m_current_line
private

Definition at line 197 of file O3prmrInterpreter.h.

Referenced by O3prmrInterpreter(), addError(), addWarning(), and checkSemantic().

◆ m_engine

std::string gum::prm::o3prmr::O3prmrInterpreter::m_engine
private

Definition at line 190 of file O3prmrInterpreter.h.

Referenced by checkSetEngine(), generateInfEngine(), and setEngine().

◆ m_errors

◆ m_inf

gum::prm::PRMInference< double >* gum::prm::o3prmr::O3prmrInterpreter::m_inf
private

◆ m_inf_map

HashTable< const PRMSystem< double >*, PRMInference< double >* > gum::prm::o3prmr::O3prmrInterpreter::m_inf_map
private

Definition at line 189 of file O3prmrInterpreter.h.

Referenced by ~O3prmrInterpreter(), generateInfEngine(), and query().

◆ m_log

std::ostream& gum::prm::o3prmr::O3prmrInterpreter::m_log
private

◆ m_paths

std::vector< std::string > gum::prm::o3prmr::O3prmrInterpreter::m_paths
private

Definition at line 185 of file O3prmrInterpreter.h.

Referenced by addPath(), clearPaths(), getPaths(), import(), and interpretFile().

◆ m_reader

gum::prm::o3prm::O3prmReader< double >* gum::prm::o3prmr::O3prmrInterpreter::m_reader
private

◆ m_results

std::vector< QueryResult > gum::prm::o3prmr::O3prmrInterpreter::m_results
private

Definition at line 192 of file O3prmrInterpreter.h.

Referenced by interpretFile(), interpretLine(), query(), and results().

◆ m_syntax_flag

bool gum::prm::o3prmr::O3prmrInterpreter::m_syntax_flag
private

Definition at line 194 of file O3prmrInterpreter.h.

Referenced by O3prmrInterpreter(), isInSyntaxMode(), and setSyntaxMode().

◆ m_verbose

bool gum::prm::o3prmr::O3prmrInterpreter::m_verbose
private

The documentation for this class was generated from the following files: