From e663cfc6627f370e05f4ea1b5cb58c5b705dd74f Mon Sep 17 00:00:00 2001 From: Roman Moravcik Date: Thu, 18 Feb 2010 17:36:09 +0100 Subject: [PATCH] Imported version 0.2-5 --- debian/changelog | 6 ++++++ src/libwrapper.cpp | 48 ++++++++++++++++++++++++++++++------------------ src/libwrapper.hpp | 4 ++-- src/mstardict.cpp | 11 ++++++++--- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/debian/changelog b/debian/changelog index b84aade..58eefc0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +mstardict (0.2-5) unstable; urgency=low + + * Reimplemented lookup with Fuzzy and Rule (not working yet) + + -- Roman Moravcik Fri, 29 Jan 2010 18:22:29 +0100 + mstardict (0.2-4) unstable; urgency=low * sdcv search mechanism replaced by ported search from stardict. diff --git a/src/libwrapper.cpp b/src/libwrapper.cpp index 28b068e..fcb53fb 100644 --- a/src/libwrapper.cpp +++ b/src/libwrapper.cpp @@ -257,33 +257,45 @@ bool Library::SimpleLookup(const gchar* sWord, CurrentIndex* piIndex) return bFound; } -void Library::LookupWithFuzzy(const string &str, TSearchResultList& res_list) +void Library::LookupWithFuzzy(const gchar* sWord) { - static const int MAXFUZZY=10; + static const int MAX_FUZZY_MATCH_ITEM=100; + gchar *fuzzy_reslist[MAX_FUZZY_MATCH_ITEM]; + bool bFound = false; - gchar *fuzzy_res[MAXFUZZY]; - if (!Libs::LookupWithFuzzy(str.c_str(), fuzzy_res, MAXFUZZY, query_dictmask)) - return; - - for (gchar **p=fuzzy_res, **end=fuzzy_res+MAXFUZZY; - p!=end && *p; ++p) { -// SimpleLookup(*p, res_list); - g_free(*p); + pMStarDict->ResultsListClear(); + + bFound = Libs::LookupWithFuzzy(sWord, fuzzy_reslist, MAX_FUZZY_MATCH_ITEM, query_dictmask); + if (bFound) { + SimpleLookup(fuzzy_reslist[0], iCurrentIndex); + + for (int i=0; iResultsListInsertLast(fuzzy_reslist[i]); + g_free(fuzzy_reslist[i]); + } + pMStarDict->ReScroll(); } } -void Library::LookupWithRule(const string &str, TSearchResultList& res_list) +void Library::LookupWithRule(const gchar* sWord) { - std::vector match_res((MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size()); + gint iMatchCount=0; + gchar **ppMatchWord = (gchar **)g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size()); - gint nfound=Libs::LookupWithRule(str.c_str(), &match_res[0], query_dictmask); - if (!nfound) - return; + pMStarDict->ResultsListClear(); + + iMatchCount=Libs::LookupWithRule(sWord, ppMatchWord, query_dictmask); + if (iMatchCount) { + for (gint i=0; iResultsListInsertLast(ppMatchWord[i]); + + SimpleLookup(ppMatchWord[0], iCurrentIndex); + pMStarDict->ReScroll(); - for (gint i=0; i &dictmask, const char* sWord, CurrentIndex *iIndex, int iLib, TSearchResultList& res_list); bool SimpleLookup(const gchar* sWord, CurrentIndex* piIndex); + void LookupWithFuzzy(const gchar* sWord); + void LookupWithRule(const gchar* sWord); private: - void LookupWithFuzzy(const string &str, TSearchResultList& res_list); - void LookupWithRule(const string &str, TSearchResultList& res_lsit); void LookupData(const string &str, TSearchResultList& res_list); }; diff --git a/src/mstardict.cpp b/src/mstardict.cpp index 9a0d964..f52d81e 100644 --- a/src/mstardict.cpp +++ b/src/mstardict.cpp @@ -146,17 +146,22 @@ MStarDict::onSearchEntryChanged (GtkEditable *editable, switch (analyse_query(sWord, query)) { case qtFUZZY: g_debug ("FUZZY"); -// oLibs->LookupWithFuzzy(query, res_list); + mStarDict->oLibs->LookupWithFuzzy(sWord); break; case qtREGEX: g_debug ("REGEX"); -// oLibs->LookupWithRule(query, res_list); + mStarDict->oLibs->LookupWithRule(sWord); break; case qtSIMPLE: g_debug ("SIMPLE"); bFound = mStarDict->oLibs->SimpleLookup(sWord, mStarDict->oLibs->iCurrentIndex); if (!bFound) { - /* suggested */ + const gchar *sugWord = mStarDict->oLibs->GetSuggestWord(sWord, mStarDict->oLibs->iCurrentIndex, mStarDict->oLibs->query_dictmask, 0); + if (sugWord) { + gchar *sSugWord = g_strdup(sugWord); + bFound = mStarDict->oLibs->SimpleLookup(sSugWord, mStarDict->oLibs->iCurrentIndex); + g_free(sSugWord); + } } mStarDict->oLibs->ListWords(mStarDict->oLibs->iCurrentIndex); break; -- 1.7.9.5