10 #include "dictziplib.hpp"
12 const int MAX_MATCH_ITEM_PER_LIB = 100;
13 const int MAX_FUZZY_DISTANCE = 3; // at most MAX_FUZZY_DISTANCE-1 differences allowed when find similar words
19 //write code here to make it inline
30 const int WORDDATA_CACHE_NUM = 10;
31 const int INVALID_INDEX = -100;
38 gchar * GetWordData(guint32 idxitem_offset, guint32 idxitem_size);
39 bool containSearchData();
40 bool SearchData(std::vector<std::string> &SearchWords, guint32 idxitem_offset, guint32 idxitem_size, gchar *origin_data);
42 std::string sametypesequence;
44 std::auto_ptr<dictData> dictdzfile;
46 cacheItem cache[WORDDATA_CACHE_NUM];
50 //this structure contain all information about dictionary
53 std::string ifo_file_name;
60 std::string description;
61 guint32 index_file_size;
62 std::string sametypesequence;
63 bool load_from_ifo_file(const std::string& ifofilename, bool istreedict);
69 guint32 wordentry_offset;
70 guint32 wordentry_size;
74 virtual bool load(const std::string& url, gulong wc, gulong fsize) = 0;
75 virtual const gchar *get_key(glong idx) = 0;
76 virtual void get_data(glong idx) = 0;
77 virtual const gchar *get_key_and_data(glong idx) = 0;
78 virtual bool lookup(const char *str, glong &idx) = 0;
81 class Dict : public DictBase
84 std::string ifo_file_name;
88 std::auto_ptr<index_file> idx_file;
90 bool load_ifofile(const std::string& ifofilename, gulong &idxfilesize);
94 bool load(const std::string& ifofilename);
100 const std::string& dict_name()
104 const std::string& ifofilename()
106 return ifo_file_name;
109 const gchar *get_key(glong index)
111 return idx_file->get_key(index);
113 gchar *get_data(glong index)
115 idx_file->get_data(index);
116 return DictBase::GetWordData(idx_file->wordentry_offset, idx_file->wordentry_size);
118 void get_key_and_data(glong index, const gchar **key, guint32 *offset, guint32 *size)
120 *key = idx_file->get_key_and_data(index);
121 *offset = idx_file->wordentry_offset;
122 *size = idx_file->wordentry_size;
124 bool Lookup(const char *str, glong &idx)
126 return idx_file->lookup(str, idx);
129 bool LookupWithRule(GPatternSpec *pspec, glong *aIndex, int iBuffLen);
132 typedef std::list<std::string> strlist_t;
137 typedef void (*progress_func_t)(void);
139 Libs(progress_func_t f = NULL);
141 void load_dict(const std::string& url);
142 void load(const strlist_t& dicts_dirs,
143 const strlist_t& order_list,
144 const strlist_t& disable_list);
145 void reload(const strlist_t& dicts_dirs,
146 const strlist_t& order_list,
147 const strlist_t& disable_list);
149 glong narticles(int idict)
151 return oLib[idict]->narticles();
153 const std::string& dict_name(int idict)
155 return oLib[idict]->dict_name();
162 const gchar * poGetWord(glong iIndex, int iLib)
164 return oLib[iLib]->get_key(iIndex);
166 gchar * poGetWordData(glong iIndex, int iLib)
168 if (iIndex == INVALID_INDEX)
170 return oLib[iLib]->get_data(iIndex);
172 const gchar *poGetCurrentWord(glong *iCurrent);
173 const gchar *poGetNextWord(const gchar *word, glong *iCurrent);
174 const gchar *poGetPreWord(glong *iCurrent);
175 bool LookupWord(const gchar* sWord, glong& iWordIndex, int iLib)
177 return oLib[iLib]->Lookup(sWord, iWordIndex);
179 bool LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib);
180 bool SimpleLookupWord(const gchar* sWord, glong & iWordIndex, int iLib);
183 bool LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_size, gint iLib);
184 gint LookupWithRule(const gchar *sWord, gchar *reslist[]);
185 bool LookupData(const gchar *sWord, std::vector<gchar *> *reslist);
187 std::vector<Dict *> oLib; // word Libs.
188 int iMaxFuzzyDistance;
189 progress_func_t progress_func;
194 qtSIMPLE, qtREGEXP, qtFUZZY, qtDATA
197 extern query_t analyze_query(const char *s, std::string& res);
199 #endif//!__SD_LIB_H__