mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
Add a utility function to FeatureData for debugging.
This commit is contained in:
parent
0ae4ad810f
commit
47b535ee0a
@ -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;
|
||||
}
|
||||
|
@ -136,6 +136,9 @@ public:
|
||||
}
|
||||
|
||||
void setFeatureMap(const std::string& feat);
|
||||
|
||||
/* For debugging */
|
||||
std::string ToString() const;
|
||||
};
|
||||
|
||||
#endif // FEATURE_DATA_H
|
||||
|
Loading…
Reference in New Issue
Block a user