diff options
author | László Németh <nemeth@numbertext.org> | 2023-05-17 10:33:30 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2023-05-17 20:06:18 +0200 |
commit | ad7a84e41b50e6221634307112f00baf2b549dcd (patch) | |
tree | 41e5fc086242f22dc537b323c87b07ebe37bca2f /external | |
parent | 45229e679aead3c1b5f91069d2a87e9597eb93b5 (diff) |
tdf#92824 spell checking: limit suggestions only for the best ones
Apply Hunspell fix to keep only the best suggestions, if they
exist to avoid of overgenerating worse suggestions especially
for short bad words.
See Hunspell commit b88f9ea57bdb9b219f3c1d2c67f4f882f1f23194
"Keep only REP, ph: or 2-word dictionary phrase suggestions
These are the best suggestions, no need to search other
ones to avoid annoying redundant and long list.
For example to suggest only "a lot" to the bad form "alot",
add the 2-word phrase "a lot" to the dic file.
Or for a very typical spelling mistake, enough to specify the
bad form with a ph: in the dictionary file to remove the other
suggestions."
Change-Id: I0272bb9ed2dd493aa372feb68d1937e359910e0a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151868
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'external')
-rw-r--r-- | external/hunspell/0001-Keep-only-REP-ph-or-2-word-dictionary-phrase-suggest.patch | 149 | ||||
-rw-r--r-- | external/hunspell/UnpackedTarball_hunspell.mk | 1 |
2 files changed, 150 insertions, 0 deletions
diff --git a/external/hunspell/0001-Keep-only-REP-ph-or-2-word-dictionary-phrase-suggest.patch b/external/hunspell/0001-Keep-only-REP-ph-or-2-word-dictionary-phrase-suggest.patch new file mode 100644 index 000000000000..2e903a34e42a --- /dev/null +++ b/external/hunspell/0001-Keep-only-REP-ph-or-2-word-dictionary-phrase-suggest.patch @@ -0,0 +1,149 @@ +From b88f9ea57bdb9b219f3c1d2c67f4f882f1f23194 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?L=C3=A1szl=C3=B3=20N=C3=A9meth?= <nemeth@numbertext.org> +Date: Sun, 14 May 2023 22:15:15 +0200 +Subject: [PATCH] Keep only REP, ph: or 2-word dictionary phrase suggestions + +These are the best suggestions, no need to search other +ones to avoid annoying redundant and long list. + +For example to suggest only "a lot" to the bad form "alot", +add the 2-word phrase "a lot" to the dic file. + +Or for a very typical spelling mistake, enough to specify the +bad form with a ph: in the dictionary file to remove the other +suggestions. + +Note: partial revert of commit de9fe28008eb0761c33bd83847f282602c599fda +"fix up some warnings seen with -Wall -Wextra". +--- + src/hunspell/atypes.hxx | 1 + + src/hunspell/suggestmgr.cxx | 31 ++++++++++++++++++++++++++----- + src/hunspell/suggestmgr.hxx | 2 +- + tests/ph.sug | 4 ++-- + tests/rep.sug | 2 +- + 5 files changed, 31 insertions(+), 9 deletions(-) + +diff --git a/src/hunspell/atypes.hxx b/src/hunspell/atypes.hxx +index 7e5a5c0..6e3ed1b 100644 +--- a/src/hunspell/atypes.hxx ++++ b/src/hunspell/atypes.hxx +@@ -82,6 +82,7 @@ static inline void HUNSPELL_WARNING(FILE*, const char*, ...) {} + #define SPELL_ORIGCAP (1 << 5) + #define SPELL_WARN (1 << 6) + #define SPELL_COMPOUND_2 (1 << 7) // permit only 2 dictionary words in the compound ++#define SPELL_BEST_SUG (1 << 8) // limit suggestions for the best ones, i.e. ph: + + #define MINCPDLEN 3 + #define MAXCOMPOUND 10 +diff --git a/src/hunspell/suggestmgr.cxx b/src/hunspell/suggestmgr.cxx +index 19a24f8..ba688aa 100644 +--- a/src/hunspell/suggestmgr.cxx ++++ b/src/hunspell/suggestmgr.cxx +@@ -242,8 +242,11 @@ bool SuggestMgr::suggest(std::vector<std::string>& slst, + if ((slst.size() < maxSug) && (!cpdsuggest || (slst.size() < oldSug + maxcpdsugs))) { + size_t i = slst.size(); + replchars(slst, word, cpdsuggest, info); +- if (slst.size() > i) ++ if (slst.size() > i) { + good_suggestion = true; ++ if (info & SPELL_BEST_SUG) ++ return true; ++ } + } + if (clock() > timelimit + TIMELIMIT_SUGGESTION) + return good_suggestion; +@@ -365,7 +368,10 @@ bool SuggestMgr::suggest(std::vector<std::string>& slst, + // we always suggest them, in despite of nosplitsugs, and + // drop compound word and other suggestions) + if (!cpdsuggest || (!nosplitsugs && slst.size() < oldSug + maxcpdsugs)) { +- good_suggestion = twowords(slst, word, cpdsuggest, good_suggestion, info); ++ good_suggestion = twowords(slst, word, cpdsuggest, good_suggestion, info); ++ ++ if (info & SPELL_BEST_SUG) ++ return true; + } + if (clock() > timelimit + TIMELIMIT_SUGGESTION) + return good_suggestion; +@@ -506,15 +512,23 @@ int SuggestMgr::replchars(std::vector<std::string>& wlst, + candidate.assign(word, 0, r); + candidate.append(entry.outstrings[type]); + candidate.append(word, r + entry.pattern.size(), std::string::npos); ++ size_t sp = candidate.find(' '); ++ size_t oldns = wlst.size(); + testsug(wlst, candidate, cpdsuggest, NULL, NULL, info); ++ if (oldns < wlst.size()) { ++ int patlen = entry.pattern.size(); ++ int replen = entry.outstrings[type].size(); ++ // REP suggestions are the best, don't search other type of suggestions ++ info |= SPELL_BEST_SUG; ++ } ++ + // check REP suggestions with space +- size_t sp = candidate.find(' '); + if (sp != std::string::npos) { + size_t prev = 0; + while (sp != std::string::npos) { + std::string prev_chunk = candidate.substr(prev, sp - prev); + if (checkword(prev_chunk, 0, NULL, NULL)) { +- size_t oldns = wlst.size(); ++ oldns = wlst.size(); + std::string post_chunk = candidate.substr(sp + 1); + testsug(wlst, post_chunk, cpdsuggest, NULL, NULL, info); + if (oldns < wlst.size()) { +@@ -854,11 +868,15 @@ bool SuggestMgr::twowords(std::vector<std::string>& wlst, + // alot -> a lot, alto, slot... + *p = ' '; + if (!cpdsuggest && checkword(candidate, cpdsuggest, NULL, NULL)) { ++ // best solution ++ info |= SPELL_BEST_SUG; ++ + // remove not word pair suggestions + if (!good) { + good = true; + wlst.clear(); + } ++ + wlst.insert(wlst.begin(), candidate); + } + +@@ -867,6 +885,9 @@ bool SuggestMgr::twowords(std::vector<std::string>& wlst, + *p = '-'; + + if (!cpdsuggest && checkword(candidate, cpdsuggest, NULL, NULL)) { ++ // best solution ++ info |= SPELL_BEST_SUG; ++ + // remove not word pair suggestions + if (!good) { + good = true; +diff --git a/tests/ph.sug b/tests/ph.sug +index 8daee56..ccd936e 100644 +--- a/tests/ph.sug ++++ b/tests/ph.sug +@@ -1,11 +1,11 @@ + a lot +-in spite, inspire ++in spite + what + what + Wednesday + Wednesday + Wednesday + Wednesday +-which, witch, winch, wish ++which, witch + Oh, my gosh! + OH, MY GOSH! +diff --git a/tests/rep.sug b/tests/rep.sug +index b48a5b8..424731c 100644 +--- a/tests/rep.sug ++++ b/tests/rep.sug +@@ -5,4 +5,4 @@ a lot, lot + un alunno + bar + vinte e un +-auto's, auto ++auto's +-- +2.25.1 + diff --git a/external/hunspell/UnpackedTarball_hunspell.mk b/external/hunspell/UnpackedTarball_hunspell.mk index 4667a3642bcc..9da05b966b4e 100644 --- a/external/hunspell/UnpackedTarball_hunspell.mk +++ b/external/hunspell/UnpackedTarball_hunspell.mk @@ -24,6 +24,7 @@ $(eval $(call gb_UnpackedTarball_set_patchlevel,hunspell,1)) $(eval $(call gb_UnpackedTarball_add_patches,hunspell, \ external/hunspell/0001-fix-LibreOffice-build-problem-with-basic_string-appe.patch \ external/hunspell/0001-Resolves-rhbz-2158548-allow-longer-words-for-hunspel.patch \ + external/hunspell/0001-Keep-only-REP-ph-or-2-word-dictionary-phrase-suggest.patch \ )) # vim: set noet sw=4 ts=4: |