Add a utility function to FeatureData for debugging.

This commit is contained in:
Tetsuo Kiso 2012-02-17 07:27:07 +09:00
parent 0ae4ad810f
commit 47b535ee0a
2 changed files with 32 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include <limits>
#include "FileStream.h"
#include "Util.h"
#include <cstdio>
static const float MIN_FLOAT=-1.0*numeric_limits<float>::max();
static const float MAX_FLOAT=numeric_limits<float>::max();
@ -146,3 +147,31 @@ void FeatureData::setFeatureMap(const std::string& feat)
number_of_features++;
}
}
string FeatureData::ToString() const {
string res;
char buf[100];
snprintf(buf, sizeof(buf), "number of features: %lu, ", number_of_features);
res.append(buf);
snprintf(buf, sizeof(buf), "features: ");
res.append(buf);
res.append(features);
snprintf(buf, sizeof(buf), ", sparse flag: %s, ", (_sparse_flag) ? "yes" : "no");
res.append(buf);
snprintf(buf, sizeof(buf), "feature_id_map = { ");
res.append(buf);
for (map<string, size_t>::const_iterator it = featname2idx_.begin();
it != featname2idx_.end(); ++it) {
snprintf(buf, sizeof(buf), "%s => %lu, ",
it->first.c_str(), it->second);
res.append(buf);
}
snprintf(buf, sizeof(buf), "}");
res.append(buf);
return res;
}

View File

@ -136,6 +136,9 @@ public:
}
void setFeatureMap(const std::string& feat);
/* For debugging */
std::string ToString() const;
};
#endif // FEATURE_DATA_H