43#ifndef DOXYGEN_SHOULD_SKIP_THIS
54 template <
typename GUM_SCALAR >
56 const std::string& filePath) :
57 BNReader< GUM_SCALAR >(bn, filePath) {
58 GUM_CONSTRUCTOR(XDSLBNReader);
60 _filePath_ = filePath;
66 template <
typename GUM_SCALAR >
67 INLINE XDSLBNReader< GUM_SCALAR >::~XDSLBNReader() {
68 GUM_DESTRUCTOR(XDSLBNReader);
77 template <
typename GUM_SCALAR >
78 Size XDSLBNReader< GUM_SCALAR >::proceed() {
81 std::string status =
"Loading File ...";
87 if (xmlDoc.NoChildren()) {
88 GUM_ERROR(
IOError,
": Loading fail, please check the file for any syntax error.")
92 status =
"File loaded. Now looking for DSL element ...";
96 std::string netName =
"unnamedBN";
98 _bn_->setProperty(
"name", netName);
101 status =
"smile Element reached. Now searching network ...";
107 status =
"Network found. Now proceeding variables instantiation...";
110 _parsingCpts_(nodesElement);
113 status =
"All variables have been instantiated. Now filling up diagram...";
120 _parsingExtension_(extensionsElement);
121 status =
"All variables have been renamed. Now filling up diagram...";
125 status =
"Instantiation of network completed";
132 template <
typename GUM_SCALAR >
133 Size XDSLBNReader< GUM_SCALAR >::_parsingCpts_(
ticpp::Element* cptsNetwork) {
135 Size nbVar = Size(0);
138 for (varIte = varIte.begin(cptsNetwork); varIte != varIte.end(); ++varIte)
141 std::string status =
"Network found. Now proceeding variables instantiation...";
147 for (varIte = varIte.begin(cptsNetwork); varIte != varIte.end(); ++varIte) {
152 std::string varDescription = varName;
155 auto newVar =
new LabelizedVariable(varName, varDescription, 0);
160 for (varOutComesIte = varOutComesIte.begin(currentVar);
161 varOutComesIte != varOutComesIte.end();
163 newVar->addLabel(varOutComesIte->GetAttribute(
"id"));
170 int progress = (int)((
float)nbIte / (
float)nbVar * 45) + 10;
176 for (varIte = varIte.begin(cptsNetwork); varIte != varIte.end(); ++varIte) {
181 if (elt !=
nullptr) {
183 const auto& strvec =
split(elt->GetTextOrDefault(
""),
" ");
184 for (
auto rit = strvec.begin(); rit != strvec.end(); ++rit)
185 _bn_->addArc(*rit, varName);
188 std::istringstream issTableString(
190 std::vector< GUM_SCALAR > tablevector;
193 while (!issTableString.eof()) {
194 issTableString >> value;
195 tablevector.push_back(value);
199 _bn_->cpt(varName).fillWith(tablevector);
206 template <
typename GUM_SCALAR >
207 void XDSLBNReader< GUM_SCALAR >::_parsingExtension_(
ticpp::Element* nodesNetwork) {
209 for (varIte = varIte.begin(nodesNetwork); varIte != varIte.end(); ++varIte) {
213 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, const std::string &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(const std::string &str, const std::string &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.