From 1e14721a50e3dfc852ec89eee1efbd314b223001 Mon Sep 17 00:00:00 2001 From: fxliang Date: Tue, 18 Jun 2024 19:56:17 +0800 Subject: [PATCH] chore: log dict file info and line number info when deploying warning (#874) --- src/rime/dict/entry_collector.cc | 18 ++++++++++++++---- src/rime/dict/entry_collector.h | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/rime/dict/entry_collector.cc b/src/rime/dict/entry_collector.cc index e9fa7404a9..48d9402753 100644 --- a/src/rime/dict/entry_collector.cc +++ b/src/rime/dict/entry_collector.cc @@ -56,6 +56,8 @@ void EntryCollector::LoadPresetVocabulary(DictSettings* settings) { void EntryCollector::Collect(const path& dict_file) { LOG(INFO) << "collecting entries from " << dict_file; + current_dict_file = dict_file.u8string(); + line_number = 0; // read table std::ifstream fin(dict_file.c_str()); DictSettings settings; @@ -69,13 +71,15 @@ void EntryCollector::Collect(const path& dict_file) { int weight_column = settings.GetColumnIndex("weight"); int stem_column = settings.GetColumnIndex("stem"); if (text_column == -1) { - LOG(ERROR) << "missing text column definition."; + LOG(ERROR) << "missing text column definition in file: " << dict_file + << "."; return; } bool enable_comment = true; string line; while (getline(fin, line)) { boost::algorithm::trim_right(line); + line_number++; // skip empty lines and comments if (line.empty()) continue; @@ -90,7 +94,9 @@ void EntryCollector::Collect(const path& dict_file) { auto row = strings::split(line, "\t"); int num_columns = static_cast(row.size()); if (num_columns <= text_column || row[text_column].empty()) { - LOG(WARNING) << "Missing entry text at #" << num_entries << "."; + LOG(WARNING) << "Missing entry text at #" << num_entries + << ", line: " << line_number + << " of file: " << current_dict_file << "."; continue; } const auto& word(row[text_column]); @@ -168,7 +174,9 @@ void EntryCollector::CreateEntry(const string& word, try { percentage = std::stod(weight_str.substr(0, weight_str.length() - 1)); } catch (...) { - LOG(WARNING) << "invalid entry definition at #" << num_entries << "."; + LOG(WARNING) << "invalid entry definition at #" << num_entries + << ", line: " << line_number + << " of file: " << current_dict_file << "."; percentage = 100.0; } e->weight *= percentage / 100.0; @@ -176,7 +184,9 @@ void EntryCollector::CreateEntry(const string& word, try { e->weight = std::stod(weight_str); } catch (...) { - LOG(WARNING) << "invalid entry definition at #" << num_entries << "."; + LOG(WARNING) << "invalid entry definition at #" << num_entries + << ", line: " << line_number + << " of file: " << current_dict_file << "."; e->weight = 0.0; } } diff --git a/src/rime/dict/entry_collector.h b/src/rime/dict/entry_collector.h index d79cc51d75..dc39cb799c 100644 --- a/src/rime/dict/entry_collector.h +++ b/src/rime/dict/entry_collector.h @@ -71,6 +71,10 @@ class EntryCollector : public PhraseCollector { set collection; WordMap words; WeightMap total_weight; + + private: + string current_dict_file; + size_t line_number; }; } // namespace rime