00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SOMDATAXMLREADER_H
00021 #define SOMDATAXMLREADER_H
00022
00023 #include "xmlsomreader.h"
00024 #include "Data.h"
00025
00026
00032 class SOMDataXMLReader : public xmlsom::XMLSOMReader {
00033
00034 public:
00035
00036 SOMDataXMLReader(std::string filename);
00037
00038 virtual SOMData* load() throw(std::exception);
00039
00040 virtual ~SOMDataXMLReader() {};
00041
00042 protected:
00043
00044 virtual void processElement(const std::string& name,
00045 const std::string& value,
00046 const std::map<std::string,std::string>& attrs)
00047 throw(std::exception);
00048
00049 private:
00050
00051 SOMData* data;
00052
00053 TMatrix entries;
00054
00055 TvecLabel labels;
00056
00057 int dimension;
00058
00059 int size;
00060
00061 int actualNode;
00062
00063 int actualWeight;
00064 };
00065
00066
00067
00068
00069 SOMDataXMLReader::SOMDataXMLReader(std::string filename)
00070 : xmlsom::XMLSOMReader(filename) {
00071
00072 dimension = 1;
00073 size = 1;
00074 actualNode = 0;
00075 actualWeight = 0;
00076 };
00077
00078
00079
00080
00081 SOMData* SOMDataXMLReader::load() throw(std::exception) {
00082
00083 doParse();
00084
00085 data = new SOMData();
00086 data->setEntries(entries);
00087 data->setLabel(labels);
00088 data->setDataSize(size);
00089 data->setDimension(dimension);
00090
00091 return data;
00092 };
00093
00094
00095
00096
00097 void SOMDataXMLReader::processElement( const std::string& name,
00098 const std::string& value,
00099 const std::map<std::string,std::string>& attrs )
00100 throw(std::exception) {
00101
00102 if(name == "size")
00103 size = atoi(value.c_str());
00104
00105 else if(name == "dimension")
00106 dimension = atoi(value.c_str());
00107
00108 else if(name == "data") {
00109 entries = create_matrix( 1, size, 1, dimension );
00110
00111 } else if(name == "row") {
00112 ++actualNode;
00113 actualWeight = 0;
00114
00115 } else if(name == "label")
00116 labels.push_back(value);
00117
00118 else if(name == "weight")
00119 entries[actualNode][actualWeight] = atof(value.c_str());
00120 };
00121
00122
00123
00124 #endif
00125