summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabeldict/modules/dbsearchengine/KDBSearchEngine.h
blob: 058444db2769eb997648d729e3c17177c6099d1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

/***************************************************************************
                          KDBSearchEngine.h  -  description
                             -------------------
    begin                : Fri Sep 8 2000
    copyright            : (C) 2000 by Andrea Rizzi
    email                : rizzi@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; version 2 of the License.               *
 *                                                                         *
 *   In addition, as a special exception, the copyright holders give       *
 *   permission to link the code of this program with any edition of       *
 *   the Qt library by Trolltech AS, Norway (or with modified versions     *
 *   of Qt that use the same license as Qt), and distribute linked         *
 *   combinations including the two.  You must obey the GNU General        *
 *   Public License in all respects for all of the code used other than    *
 *   Qt. If you modify this file, you may extend this exception to         *
 *   your version of the file, but you are not obligated to do so.  If     *
 *   you do not wish to do so, delete this exception statement from        *
 *   your version.                                                         *
 ***************************************************************************/
/*
 Translation search engine


  Copyright  2000
  Andrea Rizzi rizzi@kde.org

*/


/*
 * This is a database engine specific
 * structure, I think I must found a way to
 * make it more "standard"
 */

#ifndef _KDBSEARCH_ENGINE_
#define _KDBSEARCH_ENGINE_
#include <qobject.h>
#include <qptrlist.h>
#include <qstring.h>
#include <qmemarray.h>
#include <qvaluelist.h>


#include "database.h"
#include "searchengine.h"
#include "preferenceswidget.h"


//value of mode
#define MD_ALL_DB          1
#define MD_GOOD_KEYS	   2
#define MD_ALL_GOOD_KEYS   3
#define MD_IN_TRANSLATION  4

class SearchEntry
{
  public:
  QString string;
  int rules;
};

class KeyAndScore : public QString
{
 public:
   KeyAndScore(); 
   KeyAndScore(const QString &a,int sc);
   int score;
};

typedef QValueList<SearchEntry> SearchList;

/*  USE searchengine.h structure
class CatalogDescription
{
 public:
  char language[6];     // How many character  chinese language needs?
                        // QString is better ?
  QString filename;
  QString dateOfScan;   //When you add this to database (last time)
  QString authorOfScan;
  QString fileHeader;   //msgid ""
};

  */

class KDBSearchEngine : public SearchEngine
{
 Q_OBJECT

public:


 KDBSearchEngine(QObject *parent=0,const char *name=0);
 ~KDBSearchEngine();
 enum Rules {Equal = 1, Contains = 2, Contained = 4, RegExp = 8};
 enum FormatRules { Dots = 1, Ampersand = 2, FirstWordUpper =  4,   //Not yet used
	  AllWordUpper = 8, AmpersanAlwaysFirst = 16 };

 /*
   Set the directory where db file are located
 */
 
 void setDBName(QString filename); 
	  
 /*
   Set if the research have to consider multiple spaces as a single one.
 */
 
 void setNormalizeSpace(bool normalize); 

 /*
   Set if the research have to be Case Sensitive or not
 */
 
 void setCaseSensitive(bool sensitive); 


 /*
	 ignore ":_  bla bla  \n" in msgid

 */

 void setRemoveInternalComment(bool internalcomment);

 /*
   Set the a string containing all char that must be ignored
   during the search.
 */


 void setRemoveCharString(QString chartoremove);

 /*
	 Enable an output filter that format Uppercase/lowercase
	 method could be;
   0 = Disabled;
   1 = English pattern;
   2 = Only first;
 */

 void enableCapitalFilter(int method);

 /*
	 Enable an output filter that format special characters
	 method could be;
   0 = Disabled;
   1 = Put ... at the end if needed (remove if present but no needed);
   2 = Put an accelerator (or remove);
   4 = Remove %* if not present in msgid.
   8 = Change %d,%s etc with %1 %2 etc if needed.
 */

 void enableCharFilter(int method);

 /*
	  Sets the rules to decide when 2 string match (Uppercase and remove char
    are not set here)
   1 = EQUAL
   2 = SEARCH STRING IS CONTAINED IN DATABASE STRING (use with care, if you search nothing
			  it will produce a dangerouse output)
   4 = DATABASE STRING IS CONTAINED IN SEARCH STRING (it exclude msgid "")
   8 = String is a regexp. (exclude 1 2 4)
 */

 void setMatchingRules(int rules);

 /*
   Search Engine methods reimplemented
 */



 virtual bool messagesForFilter(const SearchFilter* filter
                         , QValueList<SearchResult>& resultList, QString& error);


 virtual void setLanguageCode(const QString& lang);
 virtual void setLanguage(const QString& languageCode, const QString& languageName);

 virtual void setEditedFile(const QString& file);
    
 virtual bool isReady() const ;
 virtual bool isSearching() const;

 virtual void saveSettings(KConfigBase *config);
 virtual void readSettings(KConfigBase *config);

 virtual PrefWidget *preferencesWidget(QWidget *parent);

 virtual const KAboutData *about() const;

 virtual QString name() const;

 virtual QString id() const;

 virtual QString lastError();

 virtual QString translate(const QString& text, uint pluralForm);

 virtual void stringChanged( const QStringList& orig, const QString& translated
        , const uint translationPluralForm, const QString& description);

 
public slots:

 void scan();
 void scanRecur();
 void scanFile();
 /*
   Add a search string in the list of the string to search for.
   Returns the ID of the string in the list.
   Returns -1 if there is a problem (may be search in 
   progress)
  */ 
 
 int addSearchString(QString searchString, int rule=Equal);

 /*
   Start the research in the database of all the string in the list    
   search mode -1 means use global mode;
  */
 bool startSearchNow(int searchmode=-1);   

 /* 
  Start a search for a single string
  If the number of word of your string is less than patternXlimit
  the KDBSearchEngine will search for all string with X * substituted to
	X word.
  For example if pattern1limit is 4 and you search "My name is Andrea"
  This string will also match with:
  "Your name is Andrea", "My dog is Andrea", "My name was Andrea", "My name is Joe"

	Do not set pattern2limit too high.

  If a patternlimit is > 0 rules 8 (* means any word) is added.

 */

 bool startSingleSearch(QString searchString,unsigned int pattern1Limit,unsigned int pattern2Limit,
                         bool inTranslation=false);

 /* 
  Start a search for a list of string
 */
 
// bool startListSearch(QPtrList<QString> searchStrList); 

/* 
 *  Return a list of key in database that contains some
 *  words of the given string phrase.
 *  thresholdin is a number from 0 to 100 a key is good 
 *  if at least the threshold% of words are found
 *  thresholdout a key is good if the found words represnt
 *  at least the thresholdorig% of the words in the key
 *  max is the maximum number of results
 */

QValueList<KeyAndScore> searchWords(QString phrase,int threshold,
				int thresholdorig ,uint32 max);

 
 /* 
  Stop the current search
  */

 virtual void stopSearch();
 virtual bool startSearch(const QString& text, uint pluralForm, const SearchFilter* filter);
 virtual bool startSearchInTranslation(QString s);

 void clearList();
signals:
 void found(SearchResult *);
private slots: 
  void updateSettings();  //Use widget settings
  void setSettings();  //Fill widget with actual settings
  void prefDestr();
  void setLastError(const QString&);
  void repeat();    
private:
 /*
   Reload database info (and keep the dbase opened).
  */
  bool loadDatabase(QString database,bool);

 bool openDb(bool);
  
 PreferencesWidget *pw;
 bool IAmReady;
 int methodFilterChar;
 int methodFilterCapital;
 int defRule;
 int defLimit1;
 int defLimit2;
 int thre;
 int threorig;
 int commonthre;
 int listmax;
 int mode;
 bool retnot;
 bool defSub1;
 bool defSub2;
 bool stopNow;
 bool searching;
 bool norm,sens,comm;
 int numofresult;
 char * filename;
 QString remchar;
 QString regaddchar;
 QString dbname;
 bool dbOpened;
// GDBM_FILE db;
 DataBaseManager * dm;
// datum key, value;
// QMemArray<CatalogDescription *> catinfo;
 SearchList searchStringList;
 int totalRecord;
 QString lasterror;
 QString lang;
 bool scanInProgress;
 QString edited;
 bool autoup;
 QString autoauthor;
};

#endif