34 template <
typename GUM_SCALAR >
37 const std::string& type,
38 const std::string& name,
39 const std::string& toRemove) {
40 auto res = path + name;
42 if (res.substr(0, toRemove.size()) == toRemove) {
43 res = res.substr(toRemove.size());
49 template <
typename GUM_SCALAR >
52 auto res = classname.substr(0, 4);
53 std::transform(res.begin(), res.end(), res.begin(), ::tolower);
57 template <
typename GUM_SCALAR >
60 auto b = filename.find_last_of(
"/\\");
61 auto e = filename.find_last_of(
".") - 1;
63 return filename.substr(b + 1, e - b);
66 template <
typename GUM_SCALAR >
68 const std::string& filename,
69 const std::string& entityName,
70 const std::string& classpath) :
71 BNReader< GUM_SCALAR >(bn, filename) {
79 template <
typename GUM_SCALAR >
87 template <
typename GUM_SCALAR >
97 std::string instanceName =
"";
105 +
"' found but class found. Generating unnamed instance.",
128 for (
auto node :
__bn->nodes()) {
130 const std::string& nn =
__bn->variable(node).name();
131 __bn->variable(node).setDescription(nn);
134 auto start = nn.find_first_of(
'(');
135 auto end = nn.find_first_of(
')');
136 if (0 < start && start < end && end < nn.size()) {
137 auto path = nn.substr(0, start);
138 auto type = nn.substr(start + 1, end - start - 1);
139 auto name = nn.substr(end + 1, std::string::npos);
141 std::string newNameRadical =
144 std::string newName = newNameRadical;
152 __bn->changeVariableName(node, newName);
155 false,
"Name " + nn +
" cannot be simplified.",
__filename, 0);
167 template <
typename GUM_SCALAR >
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Class representing a Bayesian Network.
bool isClass(const std::string &name) const
static std::string __getEntityName(const std::string &filename)
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's content packa...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
static std::string __getVariableName(const std::string &path, const std::string &type, const std::string &name, const std::string &toRemove="")
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
gum::prm::PRM< GUM_SCALAR > * prm()
This class is used to represent parsing errors for the different parser implemented in aGrUM...
O3prmBNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename, const std::string &entityName="", const std::string &classPath="")
const ErrorsContainer & errorsContainer() const
publishing Errors API
void add(ParseError error)
Add an error object to the container.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Pure virtual class for reading a BN from a file.
This class read O3PRM files and creates the corresponding gum::prm::PRM.
void __generateBN(prm::PRMSystem< GUM_SCALAR > &system)
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
std::string to_string(const Formula &f)
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian Network of this system.
bool isSystem(const std::string &name) const
PRMSystem< GUM_SCALAR > & getSystem(const std::string &name)
Returns a constant reference on a PRMSystem<GUM_SCALAR> given it's name.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
static std::string __getInstanceName(const std::string &classname)
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
PRMClass< GUM_SCALAR > & getClass(const std::string &name)
Returns a constant reference on a Class<GUM_SCALAR> given it's name.
Size errors()
publishing Errors API
std::size_t Size
In aGrUM, hashed values are unsigned long int.
void insert(const Key &k)
Inserts a new element into the set.
Read an O3PRM and transform the gum::prm::PRMSystem into gum::BayesNet.
Size proceed()
parse the file
A factory class to ease BayesNet construction.
BayesNet< GUM_SCALAR > * __bn