diff --git a/common/include/util.hpp b/common/include/util.hpp index 49965fe9050e89f22ac292bd581b6f4d87cc7202..6b2d07710231546641fff3e19a7ee6ccabd4a3f6 100644 --- a/common/include/util.hpp +++ b/common/include/util.hpp @@ -43,6 +43,8 @@ std::string int2HumanStr(int number); std::string shrink(const std::string & s, int printedSize); +std::string strip(const std::string & s); + int printedLength(std::string_view s); bool isSeparator(utf8char c); diff --git a/common/src/util.cpp b/common/src/util.cpp index cc9a647cba59eddb561202fbc456d83b403cafbe..1e2501805b6f11b8fc404d37d8da2c748c125b5b 100644 --- a/common/src/util.cpp +++ b/common/src/util.cpp @@ -153,3 +153,22 @@ bool util::doIfNameMatch(const std::regex & reg, std::string_view name, const st return true; } +//TODO : test this +std::string util::strip(const std::string & s) +{ + std::string striped; + + if (s.empty()) + return striped; + + std::size_t first = 0; + while (first < s.size() and (s[first] == ' ' or s[first] == '\t')) + ++first; + + std::size_t last = s.size()-1; + while (last > first and (s[last] == ' ' or s[last] == '\t')) + --last; + + return std::string(s.begin()+first, s.begin()+last+1); +} + diff --git a/decoder/src/Decoder.cpp b/decoder/src/Decoder.cpp index 51e3ce16de2de78edde719eeb201a0a1ccc35f83..136a545c20be789d90566352be52aefc5b231201 100644 --- a/decoder/src/Decoder.cpp +++ b/decoder/src/Decoder.cpp @@ -97,17 +97,19 @@ void Decoder::evaluate(const Config & config, std::filesystem::path modelPath, c if (util::doIfNameMatch(std::regex("(.*)\\|(.*)\\|(.*)\\|(.*)\\|(.*)"), buffer, [this, buffer](auto sm) { - for (unsigned int i = 0; i < this->evaluation[sm[1]].size(); i++) + auto metric = util::strip(sm[1]); + for (unsigned int i = 0; i < this->evaluation[metric].size(); i++) { - if (std::string(sm[i+2]).empty()) + auto value = util::strip(sm[i+2]); + if (value.empty()) { - this->evaluation[sm[1]][i] = 0.0; + this->evaluation[metric][i] = 0.0; continue; } - try {this->evaluation[sm[1]][i] = std::stof(sm[i+2]);} + try {this->evaluation[metric][i] = std::stof(value);} catch (std::exception &) { - util::myThrow(fmt::format("score '{}' is not a number in line '{}'", std::string(sm[i+2]), buffer)); + util::myThrow(fmt::format("score '{}' is not a number in line '{}'", value, buffer)); } } })){} diff --git a/dev/src/dev.cpp b/dev/src/dev.cpp index 0ae5890b3243e7f4b9c182249d1aea0f33b2b142..51b1381aca77ef307afc5353bd78281abfe5b5af 100644 --- a/dev/src/dev.cpp +++ b/dev/src/dev.cpp @@ -35,7 +35,7 @@ int main(int argc, char * argv[]) Decoder decoder(machine); - int nbEpoch = 1; + int nbEpoch = 10; for (int i = 0; i < nbEpoch; i++) {