summaryrefslogtreecommitdiff
path: root/lingucomponent
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2022-12-30 10:26:07 +0100
committerLászló Németh <nemeth@numbertext.org>2022-12-30 11:03:39 +0000
commit57d79744c77eef96b4c2bd3b16e0a04317ffcf9e (patch)
tree7945482864b5be38eb2b88ba2c3fd38a1c21e293 /lingucomponent
parentb22bbfa25ab1f0b9cfa1dedc85b8f9874f0a5e5b (diff)
tdf#136306 offapi linguistic: add options to disable rule-based compounding
Add two new spell checking options to disable rule-based closed and hyphenated compound word recognition with Hunspell dictionaries: com::sun::star::linguistic2::XLinguProperties::IsSpellClosedCompound com::sun::star::linguistic2::XLinguProperties::IsSpellHyphenatedCompound For professional proofreaders, it can be more important to avoid of the mistakes of the rule-based compound word recognition, than to speed up proofreading. Disabling the following two new options will report all rule-based closed compound words (default in Dutch, German, Hungarian etc. dictionaries) and rule-based hyphenated compound words (all languages with BREAK usage in their Hunspell dictionaries): - "Accept possible closed compound words" - "Accept possible hyphenated compound words" For example, disabling the second one, dictionary word "scot-free" will be still correct word in English spell checking, but not the previously accepted compound "arbitrary-word-with-hyphen". Note: the second option works with the update to Hunspell 1.7.2. Change-Id: Id879610927d5e8269fda5ad207c1c2fe1f57a0b6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144875 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'lingucomponent')
-rw-r--r--lingucomponent/source/spellcheck/spell/sspellimp.cxx25
-rw-r--r--lingucomponent/source/spellcheck/spell/sspellimp.hxx2
2 files changed, 20 insertions, 7 deletions
diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.cxx b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
index 95b264157533..506d2c9dd014 100644
--- a/lingucomponent/source/spellcheck/spell/sspellimp.cxx
+++ b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
@@ -243,7 +243,7 @@ sal_Bool SAL_CALL SpellChecker::hasLocale(const Locale& rLocale)
return bRes;
}
-sal_Int16 SpellChecker::GetSpellFailure(const OUString &rWord, const Locale &rLocale)
+sal_Int16 SpellChecker::GetSpellFailure(const OUString &rWord, const Locale &rLocale, int& rInfo)
{
if (rWord.getLength() > MAXWORDLEN)
return -1;
@@ -332,9 +332,9 @@ sal_Int16 SpellChecker::GetSpellFailure(const OUString &rWord, const Locale &rLo
OString aWrd(OU2ENC(nWord,eEnc));
#if defined(H_DEPRECATED)
- bool bVal = pMS->spell(std::string(aWrd.getStr()));
+ bool bVal = pMS->spell(std::string(aWrd.getStr()), &rInfo);
#else
- bool bVal = pMS->spell(aWrd.getStr()) != 0;
+ bool bVal = pMS->spell(aWrd.getStr(), &rInfo) != 0;
#endif
if (!bVal) {
if (extrachar && (eEnc != RTL_TEXTENCODING_UTF8)) {
@@ -355,9 +355,9 @@ sal_Int16 SpellChecker::GetSpellFailure(const OUString &rWord, const Locale &rLo
OUString aWord(aBuf.makeStringAndClear());
OString bWrd(OU2ENC(aWord, eEnc));
#if defined(H_DEPRECATED)
- bVal = pMS->spell(std::string(bWrd.getStr()));
+ bVal = pMS->spell(std::string(bWrd.getStr()), &rInfo);
#else
- bVal = pMS->spell(bWrd.getStr()) != 0;
+ bVal = pMS->spell(bWrd.getStr(), &rInfo) != 0;
#endif
if (bVal) return -1;
}
@@ -396,7 +396,8 @@ sal_Bool SAL_CALL SpellChecker::isValid( const OUString& rWord, const Locale& rL
PropertyHelper_Spelling& rHelper = GetPropHelper();
rHelper.SetTmpPropVals( rProperties );
- sal_Int16 nFailure = GetSpellFailure( rWord, rLocale );
+ int nInfo = 0;
+ sal_Int16 nFailure = GetSpellFailure( rWord, rLocale, nInfo );
if (nFailure != -1 && !rWord.match(SPELL_XML, 0))
{
LanguageType nLang = LinguLocaleToLanguage( rLocale );
@@ -408,6 +409,18 @@ sal_Bool SAL_CALL SpellChecker::isValid( const OUString& rWord, const Locale& rL
if (bIgnoreError)
nFailure = -1;
}
+//#define SPELL_COMPOUND 1 << 0
+
+ // valid word, but it's a rule-based compound word
+ if ( nFailure == -1 && (nInfo & SPELL_COMPOUND) )
+ {
+ bool bHasHyphen = rWord.indexOf('-') > -1;
+ if ( (bHasHyphen && !rHelper.IsSpellHyphenatedCompound()) ||
+ (!bHasHyphen && !rHelper.IsSpellClosedCompound()) )
+ {
+ return false;
+ }
+ }
return (nFailure == -1);
}
diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.hxx b/lingucomponent/source/spellcheck/spell/sspellimp.hxx
index 000f1756f5bc..68ddc69b3c56 100644
--- a/lingucomponent/source/spellcheck/spell/sspellimp.hxx
+++ b/lingucomponent/source/spellcheck/spell/sspellimp.hxx
@@ -79,7 +79,7 @@ class SpellChecker :
return m_pPropHelper ? *m_pPropHelper : GetPropHelper_Impl();
}
- sal_Int16 GetSpellFailure( const OUString &rWord, const Locale &rLocale );
+ sal_Int16 GetSpellFailure( const OUString &rWord, const Locale &rLocale, int& rInfo );
Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
public: