31 template <
typename GUM_SCALAR >
34 const std::string& type,
35 const std::string& name,
36 const std::string& toRemove) {
37 auto res = path + name;
39 if (res.substr(0, toRemove.size()) == toRemove) {
40 res = res.substr(toRemove.size());
46 template <
typename GUM_SCALAR >
49 auto res = classname.substr(0, 4);
50 std::transform(res.begin(), res.end(), res.begin(), ::tolower);
54 template <
typename GUM_SCALAR >
57 auto b = filename.find_last_of(
"/\\");
58 auto e = filename.find_last_of(
".") - 1;
60 return filename.substr(b + 1, e - b);
63 template <
typename GUM_SCALAR >
65 const std::string& filename,
66 const std::string& entityName,
67 const std::string& classpath) :
68 BNReader< GUM_SCALAR >(bn, filename) {
76 template <
typename GUM_SCALAR >
84 template <
typename GUM_SCALAR >
94 std::string instanceName =
"";
102 +
"' found but class found. Generating unnamed instance.",
125 for (
auto node :
__bn->nodes()) {
127 const std::string& nn =
__bn->variable(node).name();
128 __bn->variable(node).setDescription(nn);
131 auto start = nn.find_first_of(
'(');
132 auto end = nn.find_first_of(
')');
133 if (0 < start && start < end && end < nn.size()) {
134 auto path = nn.substr(0, start);
135 auto type = nn.substr(start + 1, end - start - 1);
136 auto name = nn.substr(end + 1, std::string::npos);
138 std::string newNameRadical =
141 std::string newName = newNameRadical;
149 __bn->changeVariableName(node, newName);
152 false,
"Name " + nn +
" cannot be simplified.",
__filename, 0);
164 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...
Inline implementation of O3prBNmReader : reader for BN using o3prm syntaxt.
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.
gum is the global namespace for all aGrUM entities
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