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
|
/*
DBSE 3
(c) 2000-2003 Andrea Rizzi
License: GPLv2
*/
#ifndef DATABASE_2_H
#define DATABASE_2_H
#include <qstring.h>
#include <qvaluelist.h>
#include <db4/db_cxx.h>
#include <qobject.h>
#include <qregexp.h>
#include "dbentries.h"
class DBSESettings
{
public:
//DatabaseInterface Settings
uint scoreWordByWord;
uint scoreGlossary;
uint scoreDivide;
uint scoreExact;
uint scoreSentence;
uint scoreAlpha;
uint scoreDynamic;
uint scoreChunkByChunk;
uint minScore;
bool firstCapital;
bool allCapital;
bool accelerator;
bool sameLetter;
};
class DataBase : Db
{
public:
DataBase(QString dbpath, QString dbname, QString dblang);
int open(DBTYPE type,unsigned int flags=0);
//Standard access (overload std functions)
int del(DBItem * key){
key->set();
int r = Db::del(0,key,0);
key->get();
return r;
}
int get(DBItem * key,DBItem *data){
key->set();
data->set();
int r = Db::get(0,key,data,0);
key->get();
data->get();
return r;
}
int put(DBItem * key,DBItem *data,int fl=0){
key->set();
data->set();
int r= Db::put(0,key,data,0);
key->get();
data->get();
return r;
}
int del(DBItemNum * key){
int r = Db::del(0,key,0);
return r;
}
int get(DBItemNum * key,DBItem *data){
data->set();
int r = Db::get(0,key,data,0);
data->get();
return r;
}
int put(DBItemNum * key,DBItem *data)
{
data->set();
int r= Db::put(0,key,data,0);
data->get();
return r;
}
//Overload, using this you loose the Key!!
int del(int i){DBItemNum n(i); return del(&n);}
int get(int i,DBItem *data){DBItemNum n(i); return get(&n,data);}
int put(int i,DBItem *data){DBItemNum n(i); return put(&n,data);}
unsigned int getLast();
int close(unsigned int i) {return Db::close( i); }
//For scrolling
// int getFirst(DBItem *key,DBItem *data,QString table);
// int getNext(DBItem *key,DBItem *data,QString table);
// bool isEnd(QString table);
private:
QString filename;
QString database;
DBTYPE mytype;
};
class QueryResult //from DBInterface to KDBSearchEngine
{
public:
QueryResult();
QueryResult(QString r);
QueryResult(QString r,QString o,int s);
void setRichResult(QString r) { richr=r; }
void setRichOriginal(QString r) { richo=r; }
QString richResult() {return richr;}
QString richOriginal() {return richo;}
QString result(){ return res; }
QString original() {return orig; }
int score() {return sco;}
//info contains originalkey,catalog,date,author etc...
ResultInfo info(){ResultInfo i; i.info="no info"; return i;}
private:
QString res;
QString orig;
QString richr;
QString richo;
int sco;
};
class SearchFilter
{
int filter; //placeholder
};
class DataBaseInterface : public QObject
{
public:
//move result list typedef to AbstractAlgorthm or somewhere else
typedef QValueList<QueryResult> ResultList;
typedef QPair<DBItemMainKey,DBItemMainData> MainEntry;
DataBaseInterface( QString dir, DBSESettings *sets);
~DataBaseInterface();
//Ask the Database to stop now.
void stop(bool b=true) {_stopNow=b;}
//Search words
ResultList wordsMatch(QString query,SearchFilter *filter=0,bool notify=true);
//Edit database functions.
//addEntry and sync all the tables
bool addEntry(QString original,QString translated,InputInfo *info);
//FIXME:implement me!
bool removeEntry(QString original);
//FIXME: go persistent!
QMap<QString,float> correlation(QString word,SearchFilter *filter=0,bool notify=true,float minSign=0.2);
// Read the database
MainEntry get(const QString& query,SearchFilter *filter=0);
MainEntry getFromIndex(uint i);
DBItemMultiIndex::IndexList getAlpha(const QString& query);
DBItemMultiIndex::IndexList getWordIndex(const QString& query);
MainEntry getSentence(const QString& query);
//Database status check functions
bool mainOk() {return main!=0;}
bool catalogOk() {return catalog!=0;}
bool alphaOk() {return alpha!=0;}
bool sentenceOk() {return sentence!=0;}
bool numindexOk() {return numindex!=0;}
bool wordsindexOk() {return wordsindex!=0;}
bool externalOk() {return external!=0;}
bool wordOk() {return word!=0;}
bool transwordOk() {return transword!=0;}
bool correlationOk() {return corr!=0;}
bool stopNow() {return _stopNow;}
// signals:
// void newResult(QueryResult);
DBSESettings *getSettings() {return settings;}
private:
DataBase * openMyDataBase(const QString& prefix,const QString& name,const QString& l,DBTYPE tt);
DataBase *main;
DataBase *numindex;
DataBase *wordsindex;
DataBase *catalog;
DataBase *alpha;
DataBase *sentence;
DataBase *word;
DataBase *external;
DataBase *transword;
DataBase *corr;
bool _stopNow;
DBSESettings *settings;
//FIXME:Move to KBabel common library.
public:
QString format( QString _s,QString t);
QString formatRegExp(QString _s, QString t, QString tre,QString stringSearch,QString stringReplace);
static QStringList words(QString s);
static QStringList sentences(QString s);
static QStringList sentencesSeparator(QString s);
static QString simple(QString str,bool ck=false);
static bool isUpper(QChar s);
static bool isLower(QChar s);
};
#endif
|