From 2c766562e2e11044783ea83ee7d2fdc6a8405ca0 Mon Sep 17 00:00:00 2001 From: Nishchal Bhandari Date: Thu, 18 Apr 2024 14:15:52 +0000 Subject: [PATCH] fix log json missing unigram bigram info if output sbs not set --- src/fstalign.cpp | 1 + src/wer.cpp | 6 ++++-- src/wer.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fstalign.cpp b/src/fstalign.cpp index 96fb33f..37ee686 100644 --- a/src/fstalign.cpp +++ b/src/fstalign.cpp @@ -695,6 +695,7 @@ void HandleWer(FstLoader& refLoader, FstLoader& hypLoader, SynonymEngine &engine } } + JsonLogUnigramBigramStats(topAlignment); if (!output_sbs.empty()) { logger->info("output_sbs = {}", output_sbs); WriteSbs(topAlignment, stitches, output_sbs); diff --git a/src/wer.cpp b/src/wer.cpp index 94b1b3c..1b2f066 100644 --- a/src/wer.cpp +++ b/src/wer.cpp @@ -603,6 +603,10 @@ void WriteSbs(wer_alignment &topAlignment, const vector& stitches, st myfile << fmt::format("{0:>20}\t{1}", group.first, group.second) << endl; } + myfile.close(); +} + +void JsonLogUnigramBigramStats(wer_alignment &topAlignment) { for (const auto &a : topAlignment.unigram_stats) { string word = a.first; gram_error_counter u = a.second; @@ -626,6 +630,4 @@ void WriteSbs(wer_alignment &topAlignment, const vector& stitches, st jsonLogger::JsonLogger::getLogger().root["wer"]["bigrams"][word]["precision"] = u.precision; jsonLogger::JsonLogger::getLogger().root["wer"]["bigrams"][word]["recall"] = u.recall; } - - myfile.close(); } diff --git a/src/wer.h b/src/wer.h index 8ccf674..f0e9f35 100644 --- a/src/wer.h +++ b/src/wer.h @@ -50,3 +50,4 @@ typedef vector> ErrorGroups; void AddErrorGroup(ErrorGroups &groups, size_t &line, string &ref, string &hyp); void WriteSbs(wer_alignment &topAlignment, const vector& stitches, string sbs_filename); +void JsonLogUnigramBigramStats(wer_alignment &topAlignment);