From e1da66bf8655477112091dea6b70f80efc2b0ed7 Mon Sep 17 00:00:00 2001 From: Kevin Brubeck Unhammer Date: Wed, 16 Oct 2024 11:38:21 +0200 Subject: [PATCH] =?UTF-8?q?Support=20multiple=20targets=20of=20$2=E2=80=93?= =?UTF-8?q?9=20relations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #81 --- src/suggest.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/suggest.cpp b/src/suggest.cpp index 60f44c4..2a41758 100644 --- a/src/suggest.cpp +++ b/src/suggest.cpp @@ -741,11 +741,21 @@ variant Suggest::cohort_errs(const ErrId& err_id, size_t i_c, r.errtypes.find(err_id) == r.errtypes.end()) { continue; // there is some other error on this reading } + // Since we can have multiple relation targets, we first collect them, then apply them: + std::unordered_map msg_replacements; rel_on_match(r.rels, MSG_TEMPLATE_REL, sentence, [&](const string& relname, size_t i_t, const Cohort& trg) { - replaceAll(msg.first, fromUtf8(relname.c_str()), trg.form); - replaceAll(msg.second, fromUtf8(relname.c_str()), trg.form); + if(msg_replacements.find(relname) == msg_replacements.end()) { + msg_replacements[relname] = trg.form; + } + else { + msg_replacements[relname] = msg_replacements[relname] + u", " + trg.form; + } }); + for(const auto& rep : msg_replacements) { + replaceAll(msg.first, fromUtf8(rep.first), rep.second); + replaceAll(msg.second, fromUtf8(rep.first), rep.second); + } } // End set msg // Begin set beg, end, form, rep: