Skip to content
Snippets Groups Projects
Commit 9d7a334b authored by Franck Dary's avatar Franck Dary
Browse files

Fixed Config's evaluation

parent 5cd7a36f
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,8 @@ std::string int2HumanStr(int number); ...@@ -43,6 +43,8 @@ std::string int2HumanStr(int number);
std::string shrink(const std::string & s, int printedSize); std::string shrink(const std::string & s, int printedSize);
std::string strip(const std::string & s);
int printedLength(std::string_view s); int printedLength(std::string_view s);
bool isSeparator(utf8char c); bool isSeparator(utf8char c);
......
...@@ -153,3 +153,22 @@ bool util::doIfNameMatch(const std::regex & reg, std::string_view name, const st ...@@ -153,3 +153,22 @@ bool util::doIfNameMatch(const std::regex & reg, std::string_view name, const st
return true; 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);
}
...@@ -97,17 +97,19 @@ void Decoder::evaluate(const Config & config, std::filesystem::path modelPath, c ...@@ -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) 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; continue;
} }
try {this->evaluation[sm[1]][i] = std::stof(sm[i+2]);} try {this->evaluation[metric][i] = std::stof(value);}
catch (std::exception &) 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));
} }
} }
})){} })){}
......
...@@ -35,7 +35,7 @@ int main(int argc, char * argv[]) ...@@ -35,7 +35,7 @@ int main(int argc, char * argv[])
Decoder decoder(machine); Decoder decoder(machine);
int nbEpoch = 1; int nbEpoch = 10;
for (int i = 0; i < nbEpoch; i++) for (int i = 0; i < nbEpoch; i++)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment