From c77d53758aed96a6ca85cf460083872649fbeb36 Mon Sep 17 00:00:00 2001 From: graphemecluster Date: Sat, 16 Nov 2024 00:23:15 +0800 Subject: [PATCH] Improve correction of monosyllabic candidates --- src/rime/algo/syllabifier.cc | 4 ++-- src/rime/dict/prism.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rime/algo/syllabifier.cc b/src/rime/algo/syllabifier.cc index 75437f6332..9fb9b7a689 100644 --- a/src/rime/algo/syllabifier.cc +++ b/src/rime/algo/syllabifier.cc @@ -67,7 +67,7 @@ int Syllabifier::BuildSyllableGraph(const string& input, for (auto accessor = prism.QuerySpelling(m.first); !accessor.exhausted(); accessor.Next()) { if (accessor.properties().type == kNormalSpelling) { - matches.push_back({m.first, m.second.length}); + matches.push_back({m.first, m.second.length, m.second.distance}); break; } } @@ -110,7 +110,7 @@ int Syllabifier::BuildSyllableGraph(const string& input, continue; } props.is_correction = true; - props.credibility = kCorrectionCredibility; + props.credibility = kCorrectionCredibility * m.distance; } auto it = spellings.find(syllable_id); if (it == spellings.end()) { diff --git a/src/rime/dict/prism.h b/src/rime/dict/prism.h index 7839b5f58d..ac18f83f3b 100644 --- a/src/rime/dict/prism.h +++ b/src/rime/dict/prism.h @@ -65,7 +65,9 @@ class Script; class Prism : public MappedFile { public: - using Match = Darts::DoubleArray::result_pair_type; + struct Match : Darts::DoubleArray::result_pair_type { + size_t distance = 0; + }; RIME_API explicit Prism(const path& file_path);