From 9d7a334b81ef3bfb2b7fcea0794506ffe453dcc4 Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Thu, 6 Feb 2020 20:46:33 +0100 Subject: [PATCH] Fixed Config's evaluation --- common/include/util.hpp | 2 ++ common/src/util.cpp | 19 +++++++++++++++++++ decoder/src/Decoder.cpp | 12 +++++++----- dev/src/dev.cpp | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/common/include/util.hpp b/common/include/util.hpp index 49965fe..6b2d077 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 cc9a647..1e25018 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 51e3ce1..136a545 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 0ae5890..51b1381 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++) { -- GitLab