aGrUM  0.13.2
gum::prm::o3prmr::O3prmrInterpreter Class Reference

Represents a O3PRMR context. More...

#include <O3prmrInterpreter.h>

+ Collaboration diagram for gum::prm::o3prmr::O3prmrInterpreter:

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 errors

More...
 
Size warnings () const
 

of warnings

More...
 
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...
 

Detailed Description

Represents a O3PRMR context.

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

Definition at line 68 of file O3prmrInterpreter.h.

Constructor & Destructor Documentation

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

This constructor create an empty context.

Definition at line 51 of file O3prmrInterpreter.cpp.

51  :
53  m_reader(new o3prm::O3prmReader< double >()), m_bn(0), m_inf(0),
54  m_syntax_flag(false), m_verbose(false), m_log(std::cout),
55  m_current_line(-1) {}
gum::prm::o3prm::O3prmReader< double > * m_reader
gum::prm::PRMInference< double > * m_inf
O3prmrContext< double > * m_context
gum::prm::o3prmr::O3prmrInterpreter::~O3prmrInterpreter ( )

Destructor. Delete current context.

Definition at line 58 of file O3prmrInterpreter.cpp.

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

58  {
59  delete m_context;
60  if (m_bn) { delete m_bn; }
61  for (auto p : m_inf_map) {
62  delete p.second;
63  }
64  delete m_reader->prm();
65  delete m_reader;
66  }
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:108
gum::prm::o3prm::O3prmReader< double > * m_reader
HashTable< const PRMSystem< double > *, PRMInference< double > * > m_inf_map
O3prmrContext< double > * m_context

+ Here is the call graph for this function:

Member Function Documentation

std::string gum::prm::o3prmr::O3prmrInterpreter::__readFile ( const std::string &  file)
private

Definition at line 185 of file O3prmrInterpreter.cpp.

References GUM_ERROR.

Referenced by interpretFile().

185  {
186  // read entire file into string
187  std::ifstream istream(file, std::ifstream::binary);
188  if (istream) {
189  // get length of file:
190  istream.seekg(0, istream.end);
191  int length = int(istream.tellg());
192  istream.seekg(0, istream.beg);
193 
194  std::string str;
195  str.resize(length, ' '); // reserve space
196  char* begin = &*str.begin();
197 
198  istream.read(begin, length);
199  istream.close();
200 
201  return str;
202  }
203  GUM_ERROR(OperationNotAllowed, "Could not open file");
204  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

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

Definition at line 975 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().

975  {
977 
978  if (m_verbose) m_log << m_errors.last().toString() << std::endl;
979  }
ParseError last() const
Returns the last added error.
std::string toString() const
Return a std::string representation of this gum::ParseError.
void addError(const std::string &msg, const std::string &filename, Idx line, Idx col)
Adds an error.
O3prmrContext< double > * m_context

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References GUM_ERROR, gum::Directory::isDir(), and m_paths.

94  {
95  if (path.length() && path.back() != '/') { path = path + '/'; }
96  if (Directory::isDir(path)) {
97  m_paths.push_back(path);
98  } else {
99  GUM_ERROR(NotFound, "not a directory");
100  }
101  }
std::vector< std::string > m_paths
static bool isDir(const std::string &path)
&brief Return true if directory is a valid directory, false otherwise.
Definition: utils_dir.cpp:32
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

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

Definition at line 982 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().

982  {
984 
985  if (m_verbose) m_log << m_errors.last().toString() << std::endl;
986  }
ParseError last() const
Returns the last added error.
void addWarning(const std::string &msg, const std::string &filename, Idx line, Idx col)
Adds a warning.
std::string toString() const
Return a std::string representation of this gum::ParseError.
O3prmrContext< double > * m_context

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 431 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().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 503 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().

503  {
504  try {
505  std::string name = command->value;
506 
507  // Contruct the pair (instance,attribut)
508  const PRMSystem< double >& sys = system(name);
509  const PRMInstance< double >& instance =
510  sys.get(findInstanceName(name, sys));
511  const PRMAttribute< double >& attr =
512  instance.get(findAttributeName(name, instance));
513  // PRMInference<double>::Chain chain = std::make_pair(&instance,
514  // &attr);
515 
516  command->system = &sys;
517  command->chain = std::make_pair(&instance, &attr);
518 
519  return true;
520 
521  } catch (Exception& err) {
522  addError(err.errorContent());
523  } catch (std::string& err) { addError(err); }
524 
525  return false;
526  }
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it&#39;s NodeId in the relational skeleton.
std::string findAttributeName(const std::string &s, const gum::prm::PRMInstance< double > &instance)
const PRMSystem< double > & system(std::string &ident)
std::string findInstanceName(std::string &s, const gum::prm::PRMSystem< double > &sys)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 308 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, and gum::prm::o3prmr::O3prmrCommand::Unobserve.

Referenced by interpretFile(), and interpretLine().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 420 of file O3prmrInterpreter.cpp.

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

Referenced by checkSemantic().

420  {
421  m_engine = command->value;
422  return m_engine == "SVED" || m_engine == "GRD" || m_engine == "SVE";
423  }

+ Here is the caller graph for this function:

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

Definition at line 425 of file O3prmrInterpreter.cpp.

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

Referenced by checkSemantic().

425  {
426  m_bn_engine = command->value;
427  return m_bn_engine == "VE" || m_bn_engine == "VEBB"
428  || m_bn_engine == "lazy";
429  }

+ Here is the caller graph for this function:

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

Definition at line 478 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().

478  {
479  try {
480  std::string name = command->value;
481 
482  // Contruct the pair (instance,attribut)
483  const PRMSystem< double >& sys = system(name);
484  const PRMInstance< double >& instance =
485  sys.get(findInstanceName(name, sys));
486  const PRMAttribute< double >& attr =
487  instance.get(findAttributeName(name, instance));
488  // PRMInference<double>::Chain chain = std::make_pair(&instance,
489  // &attr);
490 
491  command->system = &sys;
492  command->chain = std::make_pair(&instance, &attr);
493 
494  return true;
495 
496  } catch (Exception& err) {
497  addError(err.errorContent());
498  } catch (std::string& err) { addError(err); }
499 
500  return false;
501  }
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it&#39;s NodeId in the relational skeleton.
std::string findAttributeName(const std::string &s, const gum::prm::PRMInstance< double > &instance)
const PRMSystem< double > & system(std::string &ident)
std::string findInstanceName(std::string &s, const gum::prm::PRMSystem< double > &sys)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References m_paths.

105 { m_paths.clear(); }
std::vector< std::string > m_paths
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 936 of file O3prmrInterpreter.cpp.

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

Referenced by error(), and import().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

throw a string error if i >= count

Definition at line 945 of file O3prmrInterpreter.cpp.

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

945  {
946  if (i >= count()) throw "Index out of bound.";
947 
948  return m_errors.error(i);
949  }
Size count() const
En cas d&#39;échec, l&#39;API de gestion d&#39;erreurs est présente.
ParseError error(Idx i) const
Returns the i-th error.

+ Here is the call graph for this function:

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

of errors

Definition at line 939 of file O3prmrInterpreter.cpp.

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

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

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

+ Here is the caller graph for this function:

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

Return container with all errors.

Definition at line 952 of file O3prmrInterpreter.cpp.

References m_errors.

952  {
953  return m_errors;
954  }
std::string gum::prm::o3prmr::O3prmrInterpreter::findAttributeName ( const std::string &  s,
const gum::prm::PRMInstance< double > &  instance 
)
private

Definition at line 733 of file O3prmrInterpreter.cpp.

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

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

734  {
735  if (!instance.exists(s))
736  throw "'" + s + "' is not an attribute of instance '" + instance.name()
737  + "'.";
738 
739  return s;
740  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 719 of file O3prmrInterpreter.cpp.

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

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

720  {
721  // We have found system before, so 's' has been stripped.
722  size_t dot = s.find_first_of('.');
723  std::string name = s.substr(0, dot);
724 
725  if (!sys.exists(name))
726  throw "'" + name + "' is not an instance of system '" + sys.name()
727  + "'.";
728 
729  s = s.substr(dot + 1);
730  return name;
731  }
bool exists(const std::string &name) const
Retruns true either if name is an instance or an array in this PRMSystem.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 690 of file O3prmrInterpreter.cpp.

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

Referenced by system().

690  {
691  size_t dot = s.find_first_of('.');
692  std::string name = s.substr(0, dot);
693 
694  // We look first for real system, next for alias.
695  if (prm()->isSystem(name)) {
696  s = s.substr(dot + 1);
697  return name;
698  }
699 
700  if (!m_context->aliasToImport(name).empty()) {
701  s = s.substr(dot + 1);
702  return m_context->aliasToImport(name);
703  }
704 
705  while (dot != std::string::npos) {
706  if (prm()->isSystem(name)) {
707  s = s.substr(dot + 1);
708  return name;
709  }
710 
711  dot = s.find('.', dot + 1);
712  name = s.substr(0, dot);
713  }
714 
715  throw "could not find any system in '" + s + "'.";
716  }
std::string aliasToImport(const std::string &alias)
const gum::prm::PRM< double > * prm() const
Retrieve prm object.
O3prmrContext< double > * m_context

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 892 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().

892  {
893  if (m_verbose)
894  m_log << "# Building the inference engine... " << std::flush;
895 
896  //
897  if (m_engine == "SVED") {
898  m_inf = new SVED< double >(*(prm()), sys);
899 
900  //
901  } else if (m_engine == "SVE") {
902  m_inf = new SVE< double >(*(prm()), sys);
903 
904  } else {
905  if (m_engine != "GRD") {
906  addWarning("unkown engine '" + m_engine + "', use GRD insteed.");
907  }
908 
909  MarginalTargetedInference< double >* bn_inf = nullptr;
910  if (m_bn) { delete m_bn; }
911  m_bn = new BayesNet< double >();
912  BayesNetFactory< double > bn_factory(m_bn);
913 
914  if (m_verbose) m_log << "(Grounding the network... " << std::flush;
915 
916  sys.groundedBN(bn_factory);
917 
918  if (m_verbose) m_log << "Finished)" << std::flush;
919 
920  // bn_inf = new LazyPropagation<double>( *m_bn );
921  bn_inf = new VariableElimination< double >(m_bn);
922 
923  auto grd_inf = new GroundedInference< double >(*(prm()), sys);
924  grd_inf->setBNInference(bn_inf);
925  m_inf = grd_inf;
926  }
927 
928  m_inf_map.insert(&sys, m_inf);
929  if (m_verbose) m_log << "Finished." << std::endl;
930  }
const gum::prm::PRM< double > * prm() const
Retrieve prm object.
gum::prm::PRMInference< double > * m_inf
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian Network of this system.
Definition: PRMSystem_tpl.h:81
HashTable< const PRMSystem< double > *, PRMInference< double > * > m_inf_map

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Getter and setter for the context.

Getter for the context.

Definition at line 72 of file O3prmrInterpreter.cpp.

References m_context.

72  {
73  return m_context;
74  }
O3prmrContext< double > * 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 88 of file O3prmrInterpreter.cpp.

References m_paths.

88  {
89  return m_paths;
90  }
std::vector< std::string > m_paths
bool gum::prm::o3prmr::O3prmrInterpreter::import ( O3prmrContext< double > *  context,
std::string  import 
)
private

Definition at line 531 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().

532  {
533  try {
534  if (m_verbose) {
535  m_log << "# Loading system '" << import_name << "' => '" << std::flush;
536  }
537 
538  size_t last_dot = import_name.find_last_of('.');
539  std::string import_package = import_name;
540 
541  std::replace(import_name.begin(), import_name.end(), '.', '/');
542  import_name += ".o3prm";
543 
544  if (m_verbose) {
545  m_log << import_name << "' ... " << std::endl << std::flush;
546  }
547 
548  std::ifstream file_test;
549  bool found = false;
550  std::string import_abs_filename;
551 
552  // Search in o3prmr file dir.
553  std::string o3prmrFilename = context->filename();
554 
555  if (!o3prmrFilename.empty()) {
556  size_t index = o3prmrFilename.find_last_of('/');
557 
558  if (index != std::string::npos) {
559  std::string dir = o3prmrFilename.substr(0, index + 1);
560  import_abs_filename = dir + import_name;
561 
562  if (m_verbose) {
563  m_log << "# Search from filedir '" << import_abs_filename
564  << "' ... " << std::flush;
565  }
566 
567  file_test.open(import_abs_filename.c_str());
568 
569  if (file_test.is_open()) {
570  if (m_verbose) { m_log << "found !" << std::endl << std::flush; }
571 
572  file_test.close();
573  found = true;
574  } else if (m_verbose) {
575  m_log << "not found." << std::endl << std::flush;
576  }
577  }
578  }
579 
580  // Deduce root path from package name.
581  std::string package = context->package();
582 
583  if (!found && !package.empty()) {
584  std::string root;
585 
586  // if filename is not empty, start from it.
587  std::string filename = context->filename();
588 
589  if (!filename.empty()) {
590  size_t size = filename.find_last_of('/');
591 
592  if (size != std::string::npos) {
593  root += filename.substr(0, size + 1); // take with the '/'
594  }
595  }
596 
597  //
598  root += "../";
599  int count = (int)std::count(package.begin(), package.end(), '.');
600 
601  for (int i = 0; i < count; i++)
602  root += "../";
603 
604  import_abs_filename = Directory(root).absolutePath() + import_name;
605 
606  if (m_verbose) {
607  m_log << "# Search from package '" << package << "' => '"
608  << import_abs_filename << "' ... " << std::flush;
609  }
610 
611  file_test.open(import_abs_filename.c_str());
612 
613  if (file_test.is_open()) {
614  if (m_verbose) { m_log << "found !" << std::endl << std::flush; }
615 
616  file_test.close();
617  found = true;
618  } else if (m_verbose) {
619  m_log << "not found." << std::endl << std::flush;
620  }
621  }
622 
623  // Search import in all paths.
624  for (const auto& path : m_paths) {
625  import_abs_filename = path + import_name;
626 
627  if (m_verbose) {
628  m_log << "# Search from classpath '" << import_abs_filename
629  << "' ... " << std::flush;
630  }
631 
632  file_test.open(import_abs_filename.c_str());
633 
634  if (file_test.is_open()) {
635  if (m_verbose) { m_log << " found !" << std::endl << std::flush; }
636 
637  file_test.close();
638  found = true;
639  break;
640  } else if (m_verbose) {
641  m_log << " not found." << std::endl << std::flush;
642  }
643  }
644 
645  if (!found) {
646  if (m_verbose) { m_log << "Finished with errors." << std::endl; }
647 
648  addError("import not found.");
649  return false;
650  }
651 
652  // May throw std::IOError if file does't exist
653  Size previousO3prmError = m_reader->errors();
654  Size previousO3prmrError = errors();
655 
656  try {
657  m_reader->readFile(import_abs_filename, import_package);
658 
659  // Show errors and warning
660  if (m_verbose
661  && (m_reader->errors() > (unsigned int)previousO3prmError
662  || errors() > previousO3prmrError)) {
663  m_log << "Finished with errors." << std::endl;
664  } else if (m_verbose) {
665  m_log << "Finished." << std::endl;
666  }
667 
668  } catch (const IOError& err) {
669  if (m_verbose) { m_log << "Finished with errors." << std::endl; }
670 
671  addError(err.errorContent());
672  }
673 
674  // Add o3prm errors and warnings to o3prmr errors
675  for (; previousO3prmError < m_reader->errorsContainer().count();
676  previousO3prmError++) {
677  m_errors.add(m_reader->errorsContainer().error(previousO3prmError));
678  }
679 
680  return errors() == previousO3prmrError;
681 
682  } catch (const Exception& err) {
683  if (m_verbose) { m_log << "Finished with exceptions." << std::endl; }
684 
685  addError(err.errorContent());
686  return false;
687  }
688  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Size readFile(const std::string &file, const std::string &module="")
Read file and load its content using a PRMFactory. The package parameter set the file&#39;s content packa...
void add(ParseError error)
Add an error object to the container.
gum::prm::o3prm::O3prmReader< double > * m_reader
const ErrorsContainer & errorsContainer() const
publishing Errors API
Size errors() const
publishing Errors API
Size count() const
En cas d&#39;échec, l&#39;API de gestion d&#39;erreurs est présente.
std::vector< std::string > m_paths
ParseError error(Idx i) const
Returns the i-th error.
Size count() const
Returns the number of errors and warnings.
std::string replace(const std::string &s, const std::string &val, const std::string &new_val)
not usable for gcc 4.8 std::vector<std::string> split( const std::string& orig, const std::string& de...

+ Here is the call graph for this function:

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

Retrieve inference motor object.

Definition at line 125 of file O3prmrInterpreter.cpp.

References m_inf.

125  {
126  return m_inf;
127  }
gum::prm::PRMInference< double > * m_inf
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 234 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().

234  {
235  if (isVerboseMode())
236  m_log << "## Start interpretation." << std::endl << std::flush;
237 
238  // Don't parse if any syntax errors.
239  if (errors() > 0) return false;
240 
241  // For each session
242  std::vector< O3prmrSession< double >* > sessions = c->sessions();
243 
244  for (const auto session : sessions)
245  for (auto command : session->commands()) {
246  // We process it.
247  bool result = true;
248 
249  try {
250  switch (command->type()) {
252  result = observe((ObserveCommand< double >*)command);
253  break;
254 
256  result = unobserve((UnobserveCommand< double >*)command);
257  break;
258 
260  setEngine((SetEngineCommand*)command);
261  break;
262 
264  setGndEngine((SetGndEngineCommand*)command);
265  break;
266 
268  query((QueryCommand< double >*)command);
269  break;
270  }
271  } catch (Exception& err) {
272  result = false;
273  addError(err.errorContent());
274  } catch (std::string& err) {
275  result = false;
276  addError(err);
277  }
278 
279  // If there was a problem, skip the rest of this session,
280  // unless syntax mode is activated.
281  if (!result) {
282  if (m_verbose)
283  m_log << "Errors : skip the rest of this session." << std::endl;
284 
285  break;
286  }
287  }
288 
289  if (isVerboseMode())
290  m_log << "## End interpretation." << std::endl << std::flush;
291 
292  return errors() == 0;
293  }
bool observe(const ObserveCommand< double > *command)
void query(const QueryCommand< double > *command)
void setGndEngine(const SetGndEngineCommand *command)
void setEngine(const SetEngineCommand *command)
bool isVerboseMode() const
verbose mode show more details on the program execution. Default is false.
bool unobserve(const UnobserveCommand< double > *command)
std::vector< O3prmrSession< GUM_SCALAR > * > sessions() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

143  {
144  m_results.clear();
145 
146  try {
147  std::string file_content = __readFile(filename);
148 
149  delete m_context;
150  m_context = new O3prmrContext< double >(filename);
151  O3prmrContext< double > c(filename);
152 
153  // On vérifie la syntaxe
154  unsigned char* buffer = new unsigned char[file_content.length() + 1];
155  strcpy((char*)buffer, file_content.c_str());
156  Scanner s(buffer, int(file_content.length() + 1));
157  Parser p(&s);
158  p.setO3prmrContext(&c);
159  p.Parse();
160 
161  m_errors = p.errors();
162 
163  if (errors() > 0) { return false; }
164 
165  // Set paths to search from.
166  delete m_reader->prm();
167  delete m_reader;
168  m_reader = new o3prm::O3prmReader< double >();
169 
170  for (size_t i = 0; i < m_paths.size(); i++) {
172  }
173 
174  // On vérifie la sémantique.
175  if (!checkSemantic(&c)) { return false; }
176 
177  if (isInSyntaxMode()) {
178  return true;
179  } else {
180  return interpret(&c);
181  }
182  } catch (gum::Exception&) { return false; }
183  }
bool isInSyntaxMode() const
syntax mode don&#39;t process anything, just check syntax. Default is false.
std::vector< ParseError > errors
The list of gum::ParseError contained in this gum::ErrorsContainer.
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:108
bool checkSemantic(O3prmrContext< double > *context)
Check semantic validity of context.
gum::prm::o3prm::O3prmReader< double > * m_reader
bool interpret(O3prmrContext< double > *c)
Crée le prm correspondant au contexte courant.
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:103
std::vector< std::string > m_paths
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
std::string __readFile(const std::string &file)
std::vector< QueryResult > m_results
O3prmrContext< double > * m_context

+ Here is the call graph for this function:

bool gum::prm::o3prmr::O3prmrInterpreter::interpretLine ( const std::string &  line)

Definition at line 206 of file O3prmrInterpreter.cpp.

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

206  {
207  m_results.clear();
208 
209  // On vérifie la syntaxe
211  Scanner s((unsigned char*)line.c_str(), (int)line.length());
212  Parser p(&s);
213  p.setO3prmrContext(&c);
214  p.Parse();
215  m_errors = p.errors();
216 
217  if (errors() > 0) return false;
218 
219  // On vérifie la sémantique.
220  if (!checkSemantic(&c)) return false;
221 
222  if (isInSyntaxMode())
223  return true;
224  else
225  return interpret(&c);
226  }
bool isInSyntaxMode() const
syntax mode don&#39;t process anything, just check syntax. Default is false.
std::vector< ParseError > errors
The list of gum::ParseError contained in this gum::ErrorsContainer.
bool checkSemantic(O3prmrContext< double > *context)
Check semantic validity of context.
bool interpret(O3prmrContext< double > *c)
Crée le prm correspondant au contexte courant.
std::vector< QueryResult > m_results

+ Here is the call graph for this function:

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

References m_syntax_flag.

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

+ Here is the caller graph for this function:

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

References m_verbose.

Referenced by checkSemantic(), and interpret().

+ Here is the caller graph for this function:

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

Definition at line 759 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().

759  {
760  const typename PRMInference< double >::Chain& chain = command->chain;
761 
762  // Generate the inference engine if it doesn't exist.
763  if (!m_inf) { generateInfEngine(*(command->system)); }
764 
765  // Prevent from something
766  if (m_inf->hasEvidence(chain))
767  addWarning(command->leftValue + " is already observed");
768 
769  m_inf->addEvidence(chain, command->potentiel);
770 
771  if (m_verbose)
772  m_log << "# Added evidence " << command->rightValue << " over attribute "
773  << command->leftValue << std::endl;
774 
775  return true;
776 
777  } catch (OperationNotAllowed& ex) {
778  addError("something went wrong when adding evidence " + command->rightValue
779  + " over " + command->leftValue + " : " + ex.errorContent());
780  return false;
781 
782  } catch (const std::string& msg) {
783  addError(msg);
784  return false;
785  }
void generateInfEngine(const gum::prm::PRMSystem< double > &sys)
bool hasEvidence(const PRMInstance< GUM_SCALAR > &i) const
Returns true if i has evidence.
gum::prm::PRMInference< double > * m_inf
std::pair< const PRMInstance< double > *, const PRMAttribute< double > * > Chain
Code alias.
Definition: PRMInference.h:54
void addEvidence(const Chain &chain, const Potential< GUM_SCALAR > &p)
Add an evidence to the given instance&#39;s elt.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Retrieve prm object.

Definition at line 120 of file O3prmrInterpreter.cpp.

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

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

120  {
121  return m_reader->prm();
122  }
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:108
gum::prm::o3prm::O3prmReader< double > * m_reader

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 812 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< GUM_SCALAR >::variable().

Referenced by interpret().

812  {
813  const std::string& query = command->value;
814 
815  if (m_inf_map.exists(command->system)) {
816  m_inf = m_inf_map[command->system];
817  } else {
818  m_inf = nullptr;
819  }
820 
821  // Create inference engine if it has not been already created.
822  if (!m_inf) { generateInfEngine(*(command->system)); }
823 
824  // Inference
825  if (m_verbose) {
826  m_log << "# Starting inference over query: " << query << "... "
827  << std::endl;
828  }
829 
830  Timer timer;
831  timer.reset();
832 
833  Potential< double > m;
834  m_inf->marginal(command->chain, m);
835 
836  // Compute spent time
837  double t = timer.step();
838 
839  if (m_verbose) { m_log << "Finished." << std::endl; }
840 
841  if (m_verbose) {
842  m_log << "# Time in seconds (accuracy ~0.001): " << t << std::endl;
843  }
844 
845  // Show results
846 
847  if (m_verbose) { m_log << std::endl; }
848 
849  QueryResult result;
850  result.command = query;
851  result.time = t;
852 
853  Instantiation j(m);
854  const PRMAttribute< double >& attr = *(command->chain.second);
855 
856  for (j.setFirst(); !j.end(); j.inc()) {
857  // auto label_value = j.val ( attr.type().variable() );
858  auto label_value = j.val(0);
859  std::string label = attr.type().variable().label(label_value);
860  float value = float(m.get(j));
861 
862  SingleResult singleResult;
863  singleResult.label = label;
864  singleResult.p = value;
865 
866  result.values.push_back(singleResult);
867 
868  if (m_verbose) { m_log << label << " : " << value << std::endl; }
869  }
870 
871  m_results.push_back(result);
872 
873  if (m_verbose) { m_log << std::endl; }
874 
875  } catch (Exception& e) {
876  GUM_SHOWERROR(e);
877  throw "something went wrong while infering: " + e.errorContent();
878 
879  } catch (const std::string& msg) { addError(msg); }
void generateInfEngine(const gum::prm::PRMSystem< double > &sys)
void query(const QueryCommand< double > *command)
#define GUM_SHOWERROR(e)
Definition: exceptions.h:73
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
Definition: PRMType_tpl.h:135
void marginal(const Chain &chain, Potential< GUM_SCALAR > &m)
Compute the marginal of the formal attribute pointed by chain and stores it in m. ...
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
gum::prm::PRMInference< double > * m_inf
virtual PRMType< GUM_SCALAR > & type()=0
See gum::PRMClassElement::type().
HashTable< const PRMSystem< double > *, PRMInference< double > * > m_inf_map
std::vector< QueryResult > m_results

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References m_results.

132  {
133  return m_results;
134  }
std::vector< QueryResult > m_results
void gum::prm::o3prmr::O3prmrInterpreter::setContext ( O3prmrContext< double > *  context)

Setter for the context.

Definition at line 77 of file O3prmrInterpreter.cpp.

References m_context.

77  {
78  delete m_context;
79 
80  if (context == 0)
82  else
83  m_context = context;
84  }
O3prmrContext< double > * m_context
void gum::prm::o3prmr::O3prmrInterpreter::setEngine ( const SetEngineCommand command)
private

Definition at line 882 of file O3prmrInterpreter.cpp.

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

Referenced by interpret().

882  {
883  m_engine = command->value;
884  }

+ Here is the caller graph for this function:

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

Definition at line 887 of file O3prmrInterpreter.cpp.

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

Referenced by interpret().

887  {
888  m_bn_engine = command->value;
889  }

+ Here is the caller graph for this function:

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

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

Definition at line 111 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 117 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 957 of file O3prmrInterpreter.cpp.

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

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

+ Here is the call graph for this function:

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

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

962  {
964  }
void elegantErrorsAndWarnings(std::ostream &o) const
Print errors on output stream.

+ Here is the call graph for this function:

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

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

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

+ Here is the call graph for this function:

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

Definition at line 743 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().

743  {
744  try {
745  return prm()->getSystem(findSystemName(ident));
746  } catch (const std::string&) {}
747 
748  if ((m_context->mainImport() != 0)
750  return prm()->getSystem(m_context->mainImport()->value);
751 
752  throw "could not find any system or alias in '" + ident
753  + "' and no default alias has been set.";
754  }
bool isSystem(const std::string &name) const
Definition: PRM_tpl.h:86
const ImportCommand * mainImport() const
const gum::prm::PRM< double > * prm() const
Retrieve prm object.
std::string findSystemName(std::string &s)
PRMSystem< GUM_SCALAR > & getSystem(const std::string &name)
Returns a constant reference on a PRMSystem<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:145
O3prmrContext< double > * m_context

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 789 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().

790  {
791  std::string name = command->value;
792  typename PRMInference< double >::Chain chain = command->chain;
793 
794  // Prevent from something
795  if (!m_inf || !m_inf->hasEvidence(chain)) {
796  addWarning(name + " was not observed");
797  } else {
798  m_inf->removeEvidence(chain);
799 
800  if (m_verbose)
801  m_log << "# Removed evidence over attribute " << name << std::endl;
802  }
803 
804  return true;
805 
806  } catch (const std::string& msg) {
807  addError(msg);
808  return false;
809  }
bool hasEvidence(const PRMInstance< GUM_SCALAR > &i) const
Returns true if i has evidence.
gum::prm::PRMInference< double > * m_inf
std::pair< const PRMInstance< double > *, const PRMAttribute< double > * > Chain
Code alias.
Definition: PRMInference.h:54
void removeEvidence(const Chain &chain)
Remove evidence on the given instance&#39;s elt.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

of warnings

Definition at line 942 of file O3prmrInterpreter.cpp.

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

Member Data Documentation

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

Definition at line 169 of file O3prmrInterpreter.h.

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

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

Definition at line 174 of file O3prmrInterpreter.h.

Referenced by checkSetGndEngine(), and setGndEngine().

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

Definition at line 180 of file O3prmrInterpreter.h.

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

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

Definition at line 173 of file O3prmrInterpreter.h.

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

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

Definition at line 171 of file O3prmrInterpreter.h.

Referenced by generateInfEngine(), inference(), observe(), query(), and unobserve().

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

Definition at line 172 of file O3prmrInterpreter.h.

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

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

Definition at line 168 of file O3prmrInterpreter.h.

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

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

Definition at line 167 of file O3prmrInterpreter.h.

Referenced by import(), interpretFile(), prm(), and ~O3prmrInterpreter().

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

Definition at line 175 of file O3prmrInterpreter.h.

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

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

Definition at line 177 of file O3prmrInterpreter.h.

Referenced by isInSyntaxMode(), and setSyntaxMode().

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

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