55 template < GUM_Numeric GUM_SCALAR >
57 std::string_view type,
58 std::string_view name,
59 std::string_view toRemove) {
60 std::string res(path);
62 if (!toRemove.empty()) {
63 if (res.substr(0, toRemove.size()) == toRemove) { res = res.substr(toRemove.size()); }
68 template < GUM_Numeric GUM_SCALAR >
70 std::string res{classname.substr(0, 4)};
71 std::transform(res.begin(), res.end(), res.begin(), ::tolower);
75 template < GUM_Numeric GUM_SCALAR >
77 auto b = filename.find_last_of(
"/\\");
78 auto e = filename.find_last_of(
".") - 1;
80 return std::string{filename.substr(b + 1, e - b)};
83 template < GUM_Numeric GUM_SCALAR >
85 const std::string& filename,
86 const std::string& entityName,
87 const std::string& classpath) :
88 BNReader< GUM_SCALAR >(bn, filename) {
96 template < GUM_Numeric GUM_SCALAR >
104 template < GUM_Numeric GUM_SCALAR >
114 std::string instanceName =
"";
119 +
"' found but class found. Generating unnamed instance.",
129 }
else if (
prm->classes().size() == 1) {
130 const std::string& entityName = (*
prm->classes().begin())->name();
132 "Unique class '" + entityName +
"' found. Generating unnamed instance.",
145 _bn_->setProperty(
"name", entityName);
149 +
"' and more than one class.",
157 for (
auto node:
_bn_->nodes()) {
159 const std::string& nn =
_bn_->variable(node).name();
160 _bn_->variable(node).setDescription(nn);
163 auto start = nn.find_first_of(
'(');
164 auto end = nn.find_first_of(
')');
165 if (0 < start && start < end && end < nn.size()) {
166 auto path = nn.substr(0, start);
167 auto type = nn.substr(start + 1, end - start - 1);
168 auto name = nn.substr(end + 1, std::string::npos);
172 std::string newName = newNameRadical;
176 newName = newNameRadical + std::to_string(++num);
180 _bn_->changeVariableName(node, newName);
192 template < GUM_Numeric GUM_SCALAR >
200 template < GUM_Numeric GUM_SCALAR >
205 template < GUM_Numeric GUM_SCALAR >
210 template < GUM_Numeric GUM_SCALAR >
215 template < GUM_Numeric GUM_SCALAR >
220 template < GUM_Numeric GUM_SCALAR >
225 template < GUM_Numeric GUM_SCALAR >
230 template < GUM_Numeric GUM_SCALAR >
235 template < GUM_Numeric GUM_SCALAR >
237 _errors_.elegantErrorsAndWarnings(o);
240 template < GUM_Numeric GUM_SCALAR >
Inline implementation of O3prBNmReader : reader for BN using o3prm syntaxt.
BNReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
A factory class to ease BayesNet construction.
Size errors()
publishing Errors API
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
Size proceed() override
parse the file
static std::string _getInstanceName_(std::string_view classname)
static std::string _getVariableName_(std::string_view path, std::string_view type, std::string_view name, std::string_view toRemove="")
Idx errLine(Idx i)
publishing Errors API
O3prmBNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename, const std::string &entityName="", const std::string &classPath="")
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errors
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
static std::string _getEntityName_(std::string_view filename)
~O3prmBNReader() override
bool errIsError(Idx i)
type of ith error or warning
void _generateBN_(prm::PRMSystem< GUM_SCALAR > &system)
BayesNet< GUM_SCALAR > * _bn_
std::string errMsg(Idx i)
message of ith error or warning
Idx errCol(Idx i)
col of ith error or warning
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 groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian network of this system.
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
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.
gum::prm::PRM< GUM_SCALAR > * prm()
const ErrorsContainer & errorsContainer() const
publishing Errors API
Size readFile(std::string_view file, std::string_view module="")
Read file and load its content using a PRMFactory. The package parameter set the file's content packa...
void addClassPath(std::string_view class_path)
Add a list of paths to look for o3prm files.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities