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(BIFXMLBNReader);
60 _filePath_ = filePath;
66 template <
typename GUM_SCALAR >
67 INLINE BIFXMLBNReader< GUM_SCALAR >::~BIFXMLBNReader() {
68 GUM_DESTRUCTOR(BIFXMLBNReader);
77 template <
typename GUM_SCALAR >
78 Size BIFXMLBNReader< 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 BIF element ...";
98 status =
"BIF Element reached. Now searching network ...";
104 status =
"Network found. Now proceeding variables instantiation...";
107 _parsingVariables_(networkElement);
110 status =
"All variables have been instantiated. Now filling up diagram...";
113 _fillingBN_(networkElement);
115 status =
"Instantiation of network completed";
122 template <
typename GUM_SCALAR >
123 void BIFXMLBNReader< GUM_SCALAR >::_parsingVariables_(
ticpp::Element* parentNetwork) {
127 for (varIte = varIte.begin(parentNetwork); varIte != varIte.end(); ++varIte)
133 for (varIte = varIte.begin(parentNetwork); varIte != varIte.end(); ++varIte) {
140 std::string description =
"";
141 std::string fast =
"";
144 for (varPropertiesIte = varPropertiesIte.begin(currentVar);
145 varPropertiesIte != varPropertiesIte.end();
146 ++varPropertiesIte) {
147 const auto pair =
gum::split(varPropertiesIte->GetTextOrDefault(
""),
"=");
148 if (pair.size() == 2) {
152 if (property ==
"description") {
154 }
else if (property ==
"fast") {
163 auto newVar =
new LabelizedVariable(varName, description, 0);
168 for (varOutComesIte = varOutComesIte.begin(currentVar);
169 varOutComesIte != varOutComesIte.end();
171 newVar->addLabel(varOutComesIte->GetTextOrDefault(
""));
178 newVar->setDescription(description);
180 if (newVar->name() != varName) {
182 "Variable name (" << varName <<
") and fast syntax (" << fast
183 <<
") are not compatible. Please check the syntax.")
190 std::string status =
"Network found. Now proceedind variables instanciation...";
191 int progress = (int)((
float)nbIte / (
float)nbVar * 45) + 10;
197 template <
typename GUM_SCALAR >
200 void BIFXMLBNReader< GUM_SCALAR >::_fillingBN_(
ticpp::Element* parentNetwork) {
205 for (definitionIte = definitionIte.begin(parentNetwork); definitionIte != definitionIte.end();
212 for (definitionIte = definitionIte.begin(parentNetwork); definitionIte != definitionIte.end();
218 NodeId currentVarId = _bn_->idFromName(currentVarName);
222 List< NodeId > parentList;
224 for (givenIte = givenIte.begin(currentVar); givenIte != givenIte.end(); ++givenIte) {
225 std::string parentNode = givenIte->GetTextOrDefault(
"");
226 NodeId parentId = _bn_->idFromName(parentNode);
227 parentList.pushBack(parentId);
230 for (List< NodeId >::iterator_safe parentListIte = parentList.rbeginSafe();
231 parentListIte != parentList.rendSafe();
233 _bn_->addArc(*parentListIte, currentVarId);
238 std::list< GUM_SCALAR > tablelist;
241 while (!issTableString.eof()) {
242 issTableString >> value;
243 tablelist.push_back(value);
246 std::vector< GUM_SCALAR > tablevector(tablelist.begin(), tablelist.end());
249 _bn_->cpt(currentVarId).fillWith(tablevector);
252 std::string status =
"All variables have been instancied. Now filling up diagram...";
253 int progress = (int)((
float)nbIte / (
float)nbDef * 45) + 55;
classe for import of bayes net from a XML file written with BIF Format
BIFXMLBNReader(BayesNet< GUM_SCALAR > *bn, const std::string &filePath)
Constructor A reader is created to reading a defined file.
Pure virtual class for reading a BN from a file.
Class representing a Bayesian network.
Exception : input/output problem.
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.
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::string toLower(std::string str)
Returns the lowercase version of str.
std::vector< std::string > split(const std::string &str, const std::string &delim)
Split str using the delimiter.
std::string trim_copy(const std::string &s)
trim from both ends (copying)
gum is the global namespace for all aGrUM entities
std::unique_ptr< DiscreteVariable > fastVariable(std::string var_description, Size default_domain_size)
Create a pointer on a Discrete Variable from a "fast" syntax.
#define GUM_EMIT2(signal, arg1, arg2)
Utilities for manipulating strings.