43#ifndef DOXYGEN_SHOULD_SKIP_THIS
52 template <
typename GUM_SCALAR >
60 template <
typename GUM_SCALAR >
72 template <
typename GUM_SCALAR >
75 if (!output.good()) {
GUM_ERROR(IOError,
"Input/Output error : stream not writable.") }
77 _heading_(output, bn);
81 output <<
" <nodes>" << std::endl;
82 for (
auto node: bn.topologicalOrder())
83 _variableBloc_(output, node, bn);
84 output <<
" </nodes>" << std::endl;
87 _headingExtension_(output, bn);
88 for (
auto node: bn.topologicalOrder())
89 _variableExtension_(output, node, bn);
90 _endExtension_(output);
94 _documentEnd_(output);
98 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
110 template <
typename GUM_SCALAR >
113 std::ofstream output(filePath.c_str(), std::ios_base::trunc);
115 _doWrite(output, bn);
118 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
124 template <
typename GUM_SCALAR >
128 output <<
"<?xml version=\"1.0\" ?>" << std::endl;
129 output <<
"<!-- This network was created by pyAgrum " << GUM_VERSION
130 <<
" for any purpose you want -->" << std::endl;
132 output <<
"<smile version=\"1.0\" id=\"" << bn.propertyWithDefault(
"name",
"unnamedBN") <<
"\">"
139 template <
typename GUM_SCALAR >
143 output <<
" <extensions>" << std::endl;
144 output <<
" <genie version=\"1.0\" app=\"aGrUM " << GUM_VERSION <<
"\" name=\""
145 << bn.propertyWithDefault(
"name",
"unnamedBN") <<
"\">" << std::endl;
151 template <
typename GUM_SCALAR >
162 const auto& var = bn.variable(varNodeId);
164 output <<
" <cpt id=\"" << this->_buildNameWithOnlyValidChars(var.name()) <<
"\">"
168 for (
const auto& lab: var.labels()) {
169 output <<
" <state id=\"" << lab <<
"\" />" << std::endl;
175 const auto& cpt = bn.cpt(varNodeId);
176 const auto nd = cpt.nbrDim();
178 output <<
" <parents>";
180 for (
Idx i = 1; i < nd; i++) {
181 if (first) first =
false;
184 output << this->_buildNameWithOnlyValidChars(cpt.variable(i).name());
186 output <<
"</parents>" << std::endl;
189 output <<
" <probabilities>";
190 gum::Instantiation I(cpt);
194 if (first) first =
false;
199 output <<
"</probabilities>" << std::endl;
202 output <<
" </cpt>" << std::endl;
208 template <
typename GUM_SCALAR >
215 const std::string& name = bn.variable(varNodeId).name();
216 output <<
" <node id=\"" << this->_buildNameWithOnlyValidChars(name) <<
"\">" << std::endl;
217 output <<
" <name>" << name <<
"</name>" << std::endl;
218 output <<
" </node>" << std::endl;
224 template <
typename GUM_SCALAR >
226 output <<
" </genie>" << std::endl;
227 output <<
" </extensions>" << std::endl;
233 template <
typename GUM_SCALAR >
235 output <<
"</smile>" << std::endl;
Definition file for XDSL XML exportation class.
Class representing the minimal interface for Bayesian network with no numerical data.
<agrum/BN/io/XDSLXML/XDSLBNWriter.h>
void _endExtension_(std::ostream &output)
void _documentEnd_(std::ostream &output)
send to output the end of the XDSL file.
XDSLBNWriter()
Default constructor.
void _variableBloc_(std::ostream &output, const NodeId &varNodeId, const IBayesNet< GUM_SCALAR > &bn)
send to output a bloc defining a variable in the XDSL format.
void _variableExtension_(std::ostream &output, const NodeId &varNodeId, const IBayesNet< GUM_SCALAR > &bn)
send to output a bloc defining a variable's extensoion in the XDSL
void _heading_(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn)
send to output the header of the XDSL file.
void _doWrite(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn) final
Writes an bayes net in the given ouput stream.
void _headingExtension_(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn)
~XDSLBNWriter() override
Destructor.
#define GUM_ERROR(type, msg)
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities