summaryrefslogtreecommitdiff
path: root/linguistic
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2003-03-26 11:51:42 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2003-03-26 11:51:42 +0000
commit61bb4875c0b442030b649d9be22a724af17b8b4b (patch)
tree63a1c348b178517ebc58d0d1ff460f9464108418 /linguistic
parentc0e233b373dc27605943a235ea18eded55ffaafe (diff)
MWS_SRX644: migrate branch mws_srx644 -> HEAD
Diffstat (limited to 'linguistic')
-rw-r--r--linguistic/inc/spelldta.hxx36
-rw-r--r--linguistic/source/dlistimp.cxx28
-rw-r--r--linguistic/source/spelldsp.cxx87
-rw-r--r--linguistic/source/spelldta.cxx102
4 files changed, 192 insertions, 61 deletions
diff --git a/linguistic/inc/spelldta.hxx b/linguistic/inc/spelldta.hxx
index 48201d8b530d..52701e42c3a3 100644
--- a/linguistic/inc/spelldta.hxx
+++ b/linguistic/inc/spelldta.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: spelldta.hxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-11-17 12:37:30 $
+ * last change: $Author: hr $ $Date: 2003-03-26 12:51:39 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -72,6 +72,12 @@
#include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
#include <cppuhelper/implbase1.hxx> // helper for implementations
+namespace com { namespace sun { namespace star {
+ namespace linguistic2 {
+ class XDictionaryList;
+ }
+} } }
+
namespace linguistic
{
@@ -81,10 +87,26 @@ namespace linguistic
::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XSpellAlternatives >
MergeProposals(
- ::com::sun::star::uno::Reference<
- ::com::sun::star::linguistic2::XSpellAlternatives > &rxAlt1,
- ::com::sun::star::uno::Reference<
- ::com::sun::star::linguistic2::XSpellAlternatives > &rxAlt2 );
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::linguistic2::XSpellAlternatives > &rxAlt1,
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::linguistic2::XSpellAlternatives > &rxAlt2 );
+
+::com::sun::star::uno::Sequence< ::rtl::OUString >
+ MergeProposalSeqs(
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > &rAlt1,
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > &rAlt2,
+ BOOL bAllowDuplicates );
+
+void SeqRemoveNegEntries(
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > &rSeq,
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::linguistic2::XDictionaryList > &rxDicList,
+ INT16 nLanguage );
+
+BOOL SeqHasEntry(
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString > &rSeq,
+ const ::rtl::OUString &rTxt);
///////////////////////////////////////////////////////////////////////////
@@ -108,6 +130,8 @@ public:
SpellAlternatives();
SpellAlternatives(const ::rtl::OUString &rWord, INT16 nLang, INT16 nFailureType,
const ::rtl::OUString &rRplcWord );
+ SpellAlternatives(const ::rtl::OUString &rWord, INT16 nLang, INT16 nFailureType,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString > &rAlternatives );
virtual ~SpellAlternatives();
// XSpellAlternatives
diff --git a/linguistic/source/dlistimp.cxx b/linguistic/source/dlistimp.cxx
index 8236cb534aa6..eb61bc172987 100644
--- a/linguistic/source/dlistimp.cxx
+++ b/linguistic/source/dlistimp.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: dlistimp.cxx,v $
*
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: tl $ $Date: 2001-07-25 10:08:30 $
+ * last change: $Author: hr $ $Date: 2003-03-26 12:51:41 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -385,7 +385,7 @@ void DicList::searchForDictionaries( ActDicArray &rDicList,
{
MutexGuard aGuard( GetLinguMutex() );
- const Sequence< OUString > aDirCnt( utl::LocalFileHelper().
+ const Sequence< OUString > aDirCnt( utl::LocalFileHelper::
GetFolderContents( rDicDir, FALSE ) );
const OUString *pDirCnt = aDirCnt.getConstArray();
INT32 nEntries = aDirCnt.getLength();
@@ -394,15 +394,15 @@ void DicList::searchForDictionaries( ActDicArray &rDicList,
String aDCP( String::CreateFromAscii( "dcp" ) );
for (INT32 i = 0; i < nEntries; ++i)
{
- String aName( pDirCnt[i] );
+ String aURL( pDirCnt[i] );
USHORT nLang = LANGUAGE_NONE;
BOOL bNeg = FALSE;
- if(!::IsVers2OrNewer( aName, nLang, bNeg, aBuf ))
+ if(!::IsVers2OrNewer( aURL, nLang, bNeg, aBuf ))
{
// Wenn kein
- xub_StrLen nPos = aName.Search('.');
- String aExt(aName.Copy(nPos + 1));
+ xub_StrLen nPos = aURL.Search('.');
+ String aExt(aURL.Copy(nPos + 1));
aExt.ToLowerAscii();
if(aExt == aDCN) // negativ
@@ -417,7 +417,7 @@ void DicList::searchForDictionaries( ActDicArray &rDicList,
// Wenn existent nicht aufnehmen
//
INT16 nSystemLanguage = ::GetSystemLanguage();
- String aTmp1 = ToLower( aName, nSystemLanguage );
+ String aTmp1 = ToLower( aURL, nSystemLanguage );
xub_StrLen nPos = aTmp1.SearchBackward( '/' );
if (STRING_NOTFOUND != nPos)
aTmp1 = aTmp1.Copy( nPos + 1 );
@@ -433,15 +433,15 @@ void DicList::searchForDictionaries( ActDicArray &rDicList,
}
if(j >= nCount) // dictionary not yet in DicList
{
- String rDicURL( aName );
- xub_StrLen nPos = aName.SearchBackward( '/' );
- if (STRING_NOTFOUND != nPos)
- aName = aName.Copy( nPos + 1 );
+ // get decoded dictionary file name
+ INetURLObject aURLObj( aURL );
+ String aDicName = aURLObj.getName( INetURLObject::LAST_SEGMENT,
+ true, INetURLObject::DECODE_WITH_CHARSET,
+ RTL_TEXTENCODING_UTF8 );
DictionaryType eType = bNeg ? DictionaryType_NEGATIVE : DictionaryType_POSITIVE;
Reference< XDictionary > xDic =
- new DictionaryNeo( aName, nLang, eType,
- rDicURL );
+ new DictionaryNeo( aDicName, nLang, eType, aURL );
addDictionary( xDic );
nCount++;
diff --git a/linguistic/source/spelldsp.cxx b/linguistic/source/spelldsp.cxx
index 074d89b678b1..96d7914a3d1d 100644
--- a/linguistic/source/spelldsp.cxx
+++ b/linguistic/source/spelldsp.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: spelldsp.cxx,v $
*
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: tl $ $Date: 2001-06-21 09:00:49 $
+ * last change: $Author: hr $ $Date: 2003-03-26 12:51:41 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -443,13 +443,18 @@ BOOL SpellCheckerDispatcher::isValid_Impl(
if (bCheckDics &&
GetDicList().is() && IsUseDicList( rProperties, GetPropSet() ))
{
- BOOL bIsWordOk = bRes;
-
Reference< XDictionaryList > xDicList( GetDicList(), UNO_QUERY );
- Reference< XDictionaryEntry > xEntry( SearchDicList( xDicList,
- aChkWord, nLanguage, !bIsWordOk, TRUE ) );
- if (xEntry.is())
- bRes = !bIsWordOk;
+ Reference< XDictionaryEntry > xPosEntry( SearchDicList( xDicList,
+ aChkWord, nLanguage, TRUE, TRUE ) );
+ if (xPosEntry.is())
+ bRes = TRUE;
+ else
+ {
+ Reference< XDictionaryEntry > xNegEntry( SearchDicList( xDicList,
+ aChkWord, nLanguage, FALSE, TRUE ) );
+ if (xNegEntry.is())
+ bRes = FALSE;
+ }
}
}
@@ -693,44 +698,48 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl(
if (bCheckDics &&
GetDicList().is() && IsUseDicList( rProperties, GetPropSet() ))
{
- BOOL bIsWordOk = !xRes.is();
-
Reference< XDictionaryList > xDicList( GetDicList(), UNO_QUERY );
- Reference< XDictionaryEntry > xEntry( SearchDicList( xDicList,
- aChkWord, nLanguage, !bIsWordOk, TRUE ) );
-
- OUString aRplcTxt;
- BOOL bAddAlternative = FALSE;
+ Reference< XDictionaryEntry > xPosEntry( SearchDicList( xDicList,
+ aChkWord, nLanguage, TRUE, TRUE ) );
- if (bIsWordOk && xEntry.is()) // negative entry found
+ if (xPosEntry.is())
+ xRes = NULL; // positive dictionaries have precedence over negative ones
+ else
{
- aRplcTxt = xEntry->getReplacementText();
- bAddAlternative = TRUE;
- }
- else if (!bIsWordOk)
- {
- if (xEntry.is()) // positive entry found
- xRes = NULL;
- else
+ Reference< XDictionaryEntry > xNegEntry( SearchDicList( xDicList,
+ aChkWord, nLanguage, FALSE, TRUE ) );
+ if (xNegEntry.is())
{
- // search for negative entry to provide additional alternative
- xEntry = SearchDicList( xDicList,
- aChkWord, nLanguage, FALSE, TRUE );
- if (xEntry.is())
+ INT16 eFailureType = SpellFailure::IS_NEGATIVE_WORD;
+ Sequence< OUString > aProposals;
+ if (xRes.is())
{
- aRplcTxt = xEntry->getReplacementText();
- bAddAlternative = TRUE;
+ eFailureType = xRes->getFailureType();
+ aProposals = xRes->getAlternatives();
}
- }
- }
- // (additional) alternative found?
- if (bAddAlternative)
- {
- Reference< XSpellAlternatives > xAlt(
- new SpellAlternatives( aChkWord, nLanguage,
- SpellFailure::IS_NEGATIVE_WORD, aRplcTxt ) );
- xRes = MergeProposals( xAlt, xRes );
+ // replacement text to be added to suggestions, if not empty
+ OUString aAddRplcTxt( xNegEntry->getReplacementText() );
+
+ // replacement text must not be in negative dictionary itself
+ if (aAddRplcTxt.getLength() &&
+ !SearchDicList( xDicList, aAddRplcTxt, nLanguage, FALSE, TRUE ).is())
+ {
+ // add suggestion if not already part of proposals
+ if (!SeqHasEntry( aProposals, aAddRplcTxt))
+ {
+ INT32 nLen = aProposals.getLength();
+ aProposals.realloc( nLen + 1);
+ aProposals.getArray()[ nLen ] = aAddRplcTxt;
+ }
+ }
+
+ // remove entries listed in negative dictionaries
+ SeqRemoveNegEntries( aProposals, xDicList, nLanguage );
+
+ xRes = new SpellAlternatives( aChkWord, nLanguage,
+ eFailureType, aProposals );
+ }
}
}
}
diff --git a/linguistic/source/spelldta.cxx b/linguistic/source/spelldta.cxx
index 43d403d18c8c..15977792e9c8 100644
--- a/linguistic/source/spelldta.cxx
+++ b/linguistic/source/spelldta.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: spelldta.cxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-11-17 12:37:42 $
+ * last change: $Author: hr $ $Date: 2003-03-26 12:51:42 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -64,6 +64,7 @@
#endif
#include <com/sun/star/linguistic2/SpellFailure.hpp>
+#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
#ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT
#include <tools/debug.hxx>
@@ -146,6 +147,92 @@ Reference< XSpellAlternatives > MergeProposals(
}
+BOOL SeqHasEntry(
+ const Sequence< OUString > &rSeq,
+ const OUString &rTxt)
+{
+ BOOL bRes = FALSE;
+ INT32 nLen = rSeq.getLength();
+ const OUString *pEntry = rSeq.getConstArray();
+ for (INT32 i = 0; i < nLen && !bRes; ++i)
+ {
+ if (rTxt == pEntry[i])
+ bRes = TRUE;
+ }
+ return bRes;
+}
+
+
+void SeqRemoveNegEntries( Sequence< OUString > &rSeq,
+ Reference< XDictionaryList > &rxDicList,
+ INT16 nLanguage )
+{
+ static const OUString aEmpty;
+ BOOL bSthRemoved = FALSE;
+ INT32 nLen = rSeq.getLength();
+ OUString *pEntries = rSeq.getArray();
+ for (INT32 i = 0; i < nLen; ++i)
+ {
+ Reference< XDictionaryEntry > xNegEntry( SearchDicList( rxDicList,
+ pEntries[i], nLanguage, FALSE, TRUE ) );
+ if (xNegEntry.is())
+ {
+ pEntries[i] = aEmpty;
+ bSthRemoved = TRUE;
+ }
+ }
+ if (bSthRemoved)
+ {
+ Sequence< OUString > aNew;
+ // merge sequence without duplicates and empty strings in new empty sequence
+ aNew = MergeProposalSeqs( aNew, rSeq, FALSE );
+ rSeq = aNew;
+ }
+}
+
+
+Sequence< OUString > MergeProposalSeqs(
+ Sequence< OUString > &rAlt1,
+ Sequence< OUString > &rAlt2,
+ BOOL bAllowDuplicates )
+{
+ Sequence< OUString > aMerged;
+
+ if (0 == rAlt1.getLength() && bAllowDuplicates)
+ aMerged = rAlt2;
+ else if (0 == rAlt2.getLength() && bAllowDuplicates)
+ aMerged = rAlt1;
+ else
+ {
+ INT32 nAltCount1 = rAlt1.getLength();
+ const OUString *pAlt1 = rAlt1.getConstArray();
+ INT32 nAltCount2 = rAlt2.getLength();
+ const OUString *pAlt2 = rAlt2.getConstArray();
+
+ INT32 nCountNew = Min( nAltCount1 + nAltCount2, (INT32) MAX_PROPOSALS );
+ aMerged.realloc( nCountNew );
+ OUString *pMerged = aMerged.getArray();
+
+ INT32 nIndex = 0;
+ INT32 i = 0;
+ for (int j = 0; j < 2; j++)
+ {
+ INT32 nCount = j == 0 ? nAltCount1 : nAltCount2;
+ const OUString *pAlt = j == 0 ? pAlt1 : pAlt2;
+ for (i = 0; i < nCount && nIndex < MAX_PROPOSALS; i++)
+ {
+ if (pAlt[i].getLength() &&
+ (bAllowDuplicates || !SeqHasEntry(aMerged, pAlt[i] )))
+ pMerged[ nIndex++ ] = pAlt[ i ];
+ }
+ }
+ //DBG_ASSERT(nIndex == nCountNew, "wrong number of proposals");
+ aMerged.realloc( nIndex );
+ }
+
+ return aMerged;
+}
+
///////////////////////////////////////////////////////////////////////////
@@ -171,6 +258,17 @@ SpellAlternatives::SpellAlternatives(
}
+SpellAlternatives::SpellAlternatives(
+ const OUString &rWord, INT16 nLang, INT16 nFailureType,
+ const Sequence< OUString > &rAlternatives ) :
+ aWord (rWord),
+ nLanguage (nLang),
+ nType (nFailureType),
+ aAlt (rAlternatives)
+{
+}
+
+
SpellAlternatives::~SpellAlternatives()
{
}