Several dictionnaries may be defined for Spell checking feature. Patch from Semen Panevin 2:5025/121

This commit is contained in:
Stas Degteff 2011-03-14 02:56:12 +00:00
parent 16dc90cfd8
commit 39bccb92ba
6 changed files with 184 additions and 23 deletions

View File

@ -402,7 +402,7 @@ public:
gstrarray robotname; gstrarray robotname;
#if defined(GCFG_SPELL_INCLUDED) #if defined(GCFG_SPELL_INCLUDED)
int scheckerenabled; int scheckerenabled;
char scheckerdeflang[100]; char scheckerdeflang[10240];
Path scheckeruserdic; Path scheckeruserdic;
Path scheckerdicpath; Path scheckerdicpath;
#endif #endif

View File

@ -2094,7 +2094,7 @@ void IEclass::SaveMsg() {
#if defined(GCFG_SPELL_INCLUDED) #if defined(GCFG_SPELL_INCLUDED)
void IEclass::SCheckerMenu() void IEclass::SCheckerMenu()
{ {
if (!schecker.IsLoaded()) if (!schecker.IsInited())
return; return;
const char *txt = currline->txt.c_str(); const char *txt = currline->txt.c_str();
@ -2852,7 +2852,15 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg) {
if (CFG->scheckerenabled) if (CFG->scheckerenabled)
{ {
schecker.Init(CFG->xlatlocalset, CFG->scheckerdicpath); schecker.Init(CFG->xlatlocalset, CFG->scheckerdicpath);
schecker.Load(AA->adat->scheckerdeflang, CFG->scheckeruserdic); char str[sizeof(AA->adat->scheckerdeflang)];
strncpy(str, AA->adat->scheckerdeflang, sizeof(str));
char *token = strtok(str, " ");
while(token != NULL)
{
schecker.Load(token, CFG->scheckeruserdic);
/* Get next token: */
token = strtok(NULL, " ");
}
} }
#endif #endif

View File

@ -1113,7 +1113,7 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word)
size_t numrows = 7; size_t numrows = 7;
CSpellLangV &langs = schecker.GetLangs(); CSpellLangV &langs = schecker.GetLangs();
const char *lcode = schecker.GetLangCode(); std::vector<const char*> lcodes = schecker.GetLangCodes();
std::vector<std::string> langstr; std::vector<std::string> langstr;
size_t langcount = langs.size(); size_t langcount = langs.size();
@ -1126,7 +1126,19 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word)
const char *code = langs[idx]->GetLangCode(); const char *code = langs[idx]->GetLangCode();
std::string buff = " "; std::string buff = " ";
buff += streql(lcode, code) ? '\x10' : ' ';
bool loaded = false;
std::vector<const char*>::iterator langit;
for (langit = lcodes.begin(); langit != lcodes.end(); langit++)
{
if (streql(*langit, code))
{
loaded = true;
break;
}
}
buff += loaded ? '\x10' : ' ';
#if !(defined(GCFG_NO_MSSPELL) || defined(GCFG_NO_MYSPELL)) #if !(defined(GCFG_NO_MSSPELL) || defined(GCFG_NO_MYSPELL))
if (type == SCHECKET_TYPE_MSSPELL) if (type == SCHECKET_TYPE_MSSPELL)
@ -1224,7 +1236,14 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word)
} }
else if ((finaltag > TAG_LANG) && (finaltag < TAG_MORE)) else if ((finaltag > TAG_LANG) && (finaltag < TAG_MORE))
{ {
schecker.Load(langs[finaltag-TAG_LANG-1]->GetLangCode(), CFG->scheckeruserdic); if (!schecker.IsLoaded(langs[finaltag-TAG_LANG-1]->GetLangCode()))
{
schecker.Load(langs[finaltag-TAG_LANG-1]->GetLangCode(), CFG->scheckeruserdic);
}
else
{
schecker.UnLoad(langs[finaltag-TAG_LANG-1]->GetLangCode());
}
return -2; return -2;
} }

View File

@ -384,7 +384,7 @@ struct AreaData
GPlay play; GPlay play;
int replyre; int replyre;
#if defined(GCFG_SPELL_INCLUDED) #if defined(GCFG_SPELL_INCLUDED)
char scheckerdeflang[100]; char scheckerdeflang[10240];
#endif #endif
char tagline[76]; char tagline[76];
char taglinechar; char taglinechar;

View File

@ -583,7 +583,6 @@ void CSpellLang::RecodeText(const char *srcText, char *dstText, bool flag)
CSpellChecker::CSpellChecker() CSpellChecker::CSpellChecker()
{ {
mInited = false; mInited = false;
mLang = NULL;
mText[0] = 0; mText[0] = 0;
} }
@ -671,20 +670,22 @@ bool CSpellChecker::Load(const char *langId, const char *userDic)
{ {
if (!IsInited()) return false; if (!IsInited()) return false;
if (IsLoaded() && streql(mLang->GetLangCode(), langId)) return true; if (IsLoaded(langId))
{
return true;
}
CSpellLangV::iterator it; CSpellLangV::iterator it;
for (it = mLangs.begin(); it != mLangs.end(); it++) for (it = mLangs.begin(); it != mLangs.end(); it++)
{ {
if (streql((*it)->GetLangCode(), langId) && (*it)->Load(mXlatLocalset, userDic)) if (streql((*it)->GetLangCode(), langId) && (*it)->Load(mXlatLocalset, userDic))
{ {
UnLoad(); mLangsLoaded.push_back(*it);
mLang = *it; return true;
break;
} }
} }
return IsLoaded(); return false;
} }
@ -693,8 +694,32 @@ bool CSpellChecker::Load(const char *langId, const char *userDic)
void CSpellChecker::UnLoad() void CSpellChecker::UnLoad()
{ {
if (!IsLoaded()) return; if (!IsLoaded()) return;
mLang->UnLoad();
mLang = NULL; CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
(*it)->UnLoad();
}
mLangsLoaded.clear();
}
// ------------------------------------------------------------------
void CSpellChecker::UnLoad(const char *langId)
{
if (!IsLoaded()) return;
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if (streql((*it)->GetLangCode(), langId))
{
(*it)->UnLoad();
mLangsLoaded.erase(it);
return;
}
}
} }
@ -704,8 +729,16 @@ bool CSpellChecker::Check(const char *text)
{ {
if (!IsLoaded()) return true; if (!IsLoaded()) return true;
mLang->RecodeText(text, mText, true); CSpellLangV::iterator it;
return mLang->SpellCheck(mText); for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
(*it)->RecodeText(text, mText, true);
if ((*it)->SpellCheck(mText))
{
return true;
}
}
return false;
} }
@ -716,12 +749,110 @@ CSpellSuggestV &CSpellChecker::Suggest()
mSuggest.clear(); mSuggest.clear();
if (!IsLoaded()) return mSuggest; if (!IsLoaded()) return mSuggest;
mLang->BuildSuggest(mText, mSuggest); CSpellSuggestV allSuggests;
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
(*it)->BuildSuggest(mText, allSuggests);
}
CSpellSuggestV::iterator all;
for (all = allSuggests.begin(); all != allSuggests.end(); all++)
{
CSpellSuggestV::iterator distinct;
bool exists = false;
for (distinct = mSuggest.begin(); distinct != mSuggest.end(); distinct++)
{
if ((*distinct).second.compare((*all).second) == 0)
{
exists = true;
break;
}
}
if (!exists)
{
mSuggest.push_back(*all);
}
}
return mSuggest; return mSuggest;
} }
// ------------------------------------------------------------------
bool CSpellChecker::AddWord()
{
if (IsLoaded())
{
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if ((*it)->GetSpellType() == SCHECKET_TYPE_MSSPELL)
{
return (*it)->AddWord(mText);
}
}
}
return false;
}
// ------------------------------------------------------------------
const std::vector<const char*> CSpellChecker::GetLangCodes()
{
std::vector<const char*> codes;
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
codes.push_back((*it)->GetLangCode());
}
return codes;
}
// ------------------------------------------------------------------
bool CSpellChecker::IsUdrLoaded()
{
if (IsLoaded())
{
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if ((*it)->GetSpellType() == SCHECKET_TYPE_MSSPELL)
{
return (*it)->IsUdrLoaded();
}
}
}
return false;
}
// ------------------------------------------------------------------
bool CSpellChecker::IsLoaded(const char *langId)
{
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if (streql((*it)->GetLangCode(), langId))
{
return true;
}
}
return false;
}
// ------------------------------------------------------------------ // ------------------------------------------------------------------
#if !defined(GCFG_NO_MSSPELL) #if !defined(GCFG_NO_MSSPELL)

View File

@ -291,7 +291,7 @@ private:
char mXlatLocalset[256]; char mXlatLocalset[256];
CSpellLang *mLang; CSpellLangV mLangsLoaded;
CSpellLangV mLangs; CSpellLangV mLangs;
CSpellSuggestV mSuggest; CSpellSuggestV mSuggest;
@ -303,22 +303,25 @@ public:
void Close(); void Close();
bool Load(const char *langId, const char *userDic); bool Load(const char *langId, const char *userDic);
void UnLoad(const char *langId);
void UnLoad(); void UnLoad();
bool Check(const char *text); bool Check(const char *text);
CSpellSuggestV &Suggest(); CSpellSuggestV &Suggest();
bool Check(std::string &text) { return Check(text.c_str()); } bool Check(std::string &text) { return Check(text.c_str()); }
bool AddWord() { return IsLoaded() ? mLang->AddWord(mText) : false; }; bool AddWord();
CSpellSuggestV &GetSuggest() { return mSuggest; } CSpellSuggestV &GetSuggest() { return mSuggest; }
CSpellLangV &GetLangs() { return mLangs; } CSpellLangV &GetLangs() { return mLangs; }
CSpellLangV &GetLangsLoaded() { return mLangsLoaded; }
const std::vector<const char*> GetLangCodes();
const char *GetLangCode() { return IsLoaded() ? mLang->GetLangCode() : "?*N/A*?"; } bool IsUdrLoaded();
bool IsUdrLoaded() { return IsLoaded() ? mLang->IsUdrLoaded() : false; }
bool IsInited() { return mInited; } bool IsInited() { return mInited; }
bool IsLoaded() { return mLang != NULL; } bool IsLoaded() { return !mLangsLoaded.empty(); }
bool IsLoaded(const char *langId);
}; };