45#ifndef DOXYGEN_SHOULD_SKIP_THIS
56 template < GUM_Numeric GUM_SCALAR >
58 BNReader< GUM_SCALAR >(bn, filePath) {
59 GUM_CONSTRUCTOR(XDSLBNReader);
61 _filePath_ = filePath;
67 template < GUM_Numeric GUM_SCALAR >
68 XDSLBNReader< GUM_SCALAR >::~XDSLBNReader() {
69 GUM_DESTRUCTOR(XDSLBNReader);
78 template < GUM_Numeric GUM_SCALAR >
79 Size XDSLBNReader< GUM_SCALAR >::proceed() {
82 std::string status =
"Loading File ...";
88 if (xmlDoc.NoChildren()) {
89 GUM_ERROR(
IOError,
": Loading fail, please check the file for any syntax error.")
93 status =
"File loaded. Now looking for DSL element ...";
97 std::string netName =
"unnamedBN";
99 _bn_->setProperty(
"name", netName);
102 status =
"smile Element reached. Now searching network ...";
108 status =
"Network found. Now proceeding variables instantiation...";
111 _parsingCpts_(nodesElement);
114 status =
"All variables have been instantiated. Now filling up diagram...";
121 _parsingExtension_(extensionsElement);
122 status =
"All variables have been renamed. Now filling up diagram...";
126 status =
"Instantiation of network completed";
133 template < GUM_Numeric GUM_SCALAR >
134 Size XDSLBNReader< GUM_SCALAR >::_parsingCpts_(
ticpp::Element* cptsNetwork) {
136 Size nbVar = Size(0);
139 for (varIte = varIte.begin(cptsNetwork); varIte != varIte.end(); ++varIte)
142 std::string status =
"Network found. Now proceeding variables instantiation...";
148 for (varIte = varIte.begin(cptsNetwork); varIte != varIte.end(); ++varIte) {
153 std::string varDescription = varName;
156 auto newVar =
new LabelizedVariable(varName, varDescription, 0);
161 for (varOutComesIte = varOutComesIte.begin(currentVar);
162 varOutComesIte != varOutComesIte.end();
164 newVar->addLabel(varOutComesIte->GetAttribute(
"id"));
171 int progress = (int)((
float)nbIte / (
float)nbVar * 45) + 10;
177 for (varIte = varIte.begin(cptsNetwork); varIte != varIte.end(); ++varIte) {
182 if (elt !=
nullptr) {
184 const auto& strvec =
split(elt->GetTextOrDefault(
""),
" ");
185 for (
auto rit = strvec.begin(); rit != strvec.end(); ++rit)
186 _bn_->addArc(*rit, varName);
189 std::istringstream issTableString(
191 std::vector< GUM_SCALAR > tablevector;
194 while (!issTableString.eof()) {
195 issTableString >> value;
196 tablevector.push_back(value);
200 _bn_->cpt(varName).fillWith(tablevector);
207 template < GUM_Numeric GUM_SCALAR >
208 void XDSLBNReader< GUM_SCALAR >::_parsingExtension_(
ticpp::Element* nodesNetwork) {
210 for (varIte = varIte.begin(nodesNetwork); varIte != varIte.end(); ++varIte) {
214 if (descName != varName) _bn_->changeVariableName(varName, descName);
classe for import of bayes net from a XML file written with BIF Format
Pure virtual class for reading a BN from a file.
Class representing a Bayesian network.
Exception : input/output problem.
XDSLBNReader(BayesNet< GUM_SCALAR > *bn, std::string_view filePath)
Constructor A reader is created to reading a defined file.
Wrapper around TiXmlDocument.
Wrapper around TiXmlElement.
std::string GetTextOrDefault(const std::string &defaultValue) const
Gets the text of an Element, if it doesn't exist it will return the defaultValue.
T GetAttribute(const std::string &name, bool throwIfNotFound=true) const
Returns an attribute of name from an element.
This is a ticpp exception class.
const char * what() const
Override std::exception::what() to return m_details.
Iterator for conveniently stepping through Nodes and Attributes.
Element * FirstChildElement(bool throwIfNoChildren=true) const
The first child element of this node.
#define GUM_ERROR(type, msg)
std::vector< std::string > split(std::string_view str, std::string_view delim)
Split str using the delimiter.
gum is the global namespace for all aGrUM entities
#define GUM_EMIT2(signal, arg1, arg2)
Utilities for manipulating strings.