54 template <
typename GUM_SCALAR >
56 const std::string& type,
57 const std::string& name,
58 const std::string& toRemove) {
59 auto res = path + name;
61 if (res.substr(0, toRemove.size()) == toRemove) { res = res.substr(toRemove.size()); }
66 template <
typename GUM_SCALAR >
68 auto res = classname.substr(0, 4);
69 std::transform(res.begin(), res.end(), res.begin(), ::tolower);
73 template <
typename GUM_SCALAR >
75 auto b = filename.find_last_of(
"/\\");
76 auto e = filename.find_last_of(
".") - 1;
78 return filename.substr(b + 1, e - b);
81 template <
typename GUM_SCALAR >
83 const std::string& filename,
84 const std::string& entityName,
85 const std::string& classpath) :
86 BNReader< GUM_SCALAR >(bn, filename) {
94 template <
typename GUM_SCALAR >
102 template <
typename GUM_SCALAR >
112 std::string instanceName =
"";
118 +
"' found but class found. Generating unnamed instance.",
128 }
else if (
prm->classes().size() == 1) {
129 const std::string& entityName = (*
prm->classes().begin())->name();
131 "Unique class '" + entityName +
"' found. Generating unnamed instance.",
144 _bn_->setProperty(
"name", entityName);
148 "Neither system nor class '" +
_entityName_ +
"' and more than one class.",
156 for (
auto node:
_bn_->nodes()) {
158 const std::string& nn =
_bn_->variable(node).name();
159 _bn_->variable(node).setDescription(nn);
162 auto start = nn.find_first_of(
'(');
163 auto end = nn.find_first_of(
')');
164 if (0 < start && start < end && end < nn.size()) {
165 auto path = nn.substr(0, start);
166 auto type = nn.substr(start + 1, end - start - 1);
167 auto name = nn.substr(end + 1, std::string::npos);
171 std::string newName = newNameRadical;
175 newName = newNameRadical + std::to_string(++num);
179 _bn_->changeVariableName(node, newName);
192 template <
typename GUM_SCALAR >
Inline implementation of O3prBNmReader : reader for BN using o3prm syntaxt.
BNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
A factory class to ease BayesNet construction.
Size errors()
publishing Errors API
static std::string _getInstanceName_(const std::string &classname)
O3prmBNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename, const std::string &entityName="", const std::string &classPath="")
void _generateBN_(prm::PRMSystem< GUM_SCALAR > &system)
BayesNet< GUM_SCALAR > * _bn_
static std::string _getVariableName_(const std::string &path, const std::string &type, const std::string &name, const std::string &toRemove="")
static std::string _getEntityName_(const std::string &filename)
Size proceed()
parse the file
This class is used to represent parsing errors for the different parser implemented in aGrUM.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian network of this system.
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
This class read O3PRM files and creates the corresponding gum::prm::PRM.
const ErrorsContainer & errorsContainer() const
publishing Errors API
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
gum::prm::PRM< GUM_SCALAR > * prm()
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...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities