tdf#40277 linguistic: recognize compounds from custom dictionary words

Accept compounds separated by hyphens, when some (or all) constituents
of the compound come from the custom dictionaries.

For example, when "CustomWord" added by the user to one of the custom
dictionaries, now "CustomWord-based", "CustomWord-CustomWord",
"CustomWord-based-CustomWord-like" etc. compounds are accepted.

Note: the recursion used by the algorithm is limited by the maximum
allowed word length during spell checking (100 characters).

Change-Id: Ie2e19714ad10b3c7436a442ca8c8775e673da579
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196271
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: Jenkins
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196285
This commit is contained in:
László Németh
2025-12-29 17:25:01 +01:00
committed by Xisco Fauli
parent 54b1474289
commit 5348f86429
2 changed files with 37 additions and 0 deletions
+12
View File
@@ -204,6 +204,18 @@ sal_Bool SAL_CALL
// fallback: convert the apostrophes
bRet = isValid_Impl( rWord, LinguLocaleToLanguage( rLocale ), rProperties, bConvert );
}
if (!bRet)
{
// accept compounds combined from custom and default dictionary words
// separated by a hyphen
sal_Int32 nHyphenPos = rWord.indexOf("-");
if (nHyphenPos > -1)
{
return isValid(rWord.copy(0, nHyphenPos), rLocale, rProperties) &&
isValid(rWord.copy(nHyphenPos + 1, rWord.getLength() - nHyphenPos - 1),
rLocale, rProperties);
}
}
return bRet;
}
+25
View File
@@ -1295,6 +1295,31 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf170140)
CPPUNIT_ASSERT(!xSpell->isValid(sWord2, static_cast<sal_uInt16>(eLang), aProperties));
}
// TODO: move this test to the linguistic project
CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf40277)
{
uno::Reference<linguistic2::XSpellChecker1> xSpell = LinguMgr::GetSpellChecker();
auto aLocale = lang::Locale(u"en"_ustr, u"US"_ustr, OUString());
LanguageType eLang = LanguageTag::convertToLanguageType(aLocale);
if (!xSpell.is() || !xSpell->hasLanguage(static_cast<sal_uInt16>(eLang)))
return;
uno::Sequence<beans::PropertyValue> aProperties;
// check Hunspell dictionary
OUString sWord(u"based"_ustr);
CPPUNIT_ASSERT(xSpell->isValid(sWord, static_cast<sal_uInt16>(eLang), aProperties));
// check custom dictionary support (a word which is stored only in technical.dic)
OUString sWord2(u"SunHSI"_ustr);
CPPUNIT_ASSERT(xSpell->isValid(sWord2, static_cast<sal_uInt16>(eLang), aProperties));
OUString sWord3(u"SunHSI-based"_ustr);
// This was false (missing recognition of compounds formed from Hunspell
// dictionary words and custom dictionary words)
CPPUNIT_ASSERT(xSpell->isValid(sWord3, static_cast<sal_uInt16>(eLang), aProperties));
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testRedlineNumberInFootnote)
{
createSwDoc("tdf85610.fodt");