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
|
//
// C++ Implementation: chunk
//
// Description:
//
//
// Author: Andrea Rizzi <rizzi@kde.org>, (C) 2003
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "chunk.h"
#include "algorithms.h"
#include <kdebug.h>
AbstractChunk::~AbstractChunk( )
{
}
WordChunk::WordChunk( DataBaseInterface * di, QString _word ) : AbstractChunk(di)
{
word=_word;
}
QValueList<QueryResult> WordChunk::translations( )
{
DataBaseInterface::ResultList r;
SingleWordSearchAlgorithm sa(di,di->getSettings());
r=sa.exec(word);
return r;
}
//QValueList<QueryResult> WordChunk::translationsFromReference( uint reference )
//{
//}
QValueList< uint > WordChunk::locationReferences( )
{
QValueList<uint> res=di->getWordIndex(word);
kdDebug(0) << "Number of locations " << res.count() <<endl ;
return res;
/* DBItemMainKey *k = new DBItemMainKey(word);
DBItemMultiIndex *d = new DBItemMultiIndex();
if(wordsindex->get(k,d)!=DB_NOTFOUND)
return d->getList();
else
return QValueList<uint> tmpList;
*/
}
void WordChunk::setLocationReferences( QValueList< uint > )
{
}
SentenceChunk::SentenceChunk( DataBaseInterface * di, QString _sentence ): AbstractChunk(di)
{
sentence=_sentence;
}
QValueList<QueryResult> SentenceChunk::translations( )
{
GenericSearchAlgorithm g(di,di->getSettings());
ExactSearchAlgorithm e(di,di->getSettings());
AlphaSearchAlgorithm a(di,di->getSettings());
SentenceArchiveSearchAlgorithm s(di,di->getSettings());
g.addAlgorithm(&e);
g.addAlgorithm(&a);
g.addAlgorithm(&s);
return g.exec(sentence);
}
//QValueList<QueryResult> SentenceChunk::translationsFromReference( uint reference )
//{
//
//}
QValueList< uint > SentenceChunk::locationReferences( )
{
}
void SentenceChunk::setLocationReferences( QValueList< uint > )
{
}
QPtrList< AbstractChunk> WordChunkFactory::chunks()
{
QString str=di->simple(string);
QPtrList<AbstractChunk> list;
if(str.isEmpty()) return list;
_separators.clear();
kdDebug(0) << "Word chunks of:" <<str << endl;
int pos;
QString sep;
QRegExp r("(\\s)");
do {
pos=r.search(str);
sep=r.cap(1);
if(!str.left(pos).isEmpty()){
//WordChunk *c=new WordChunk(di,di->simple(str.left(pos)))
list.append(new WordChunk(di,str.left(pos)));
_separators.append(sep);
}
else
{
uint current=_separators.count()-1;
_separators[current]=_separators[current]+sep;
}
str=str.remove(0,pos+1);
} while(!str.isEmpty() && pos != -1);
return list;
}
QPtrList<AbstractChunk> SentenceChunkFactory::chunks()
{
QString str=string;
QPtrList<AbstractChunk> list;
if(str.isEmpty()) return list;
// kdDebug(0) << s << endl;
int pos;
do {
QRegExp re("((\\.|;|\\?|\\!|:)( |$|\\\\n\\n))");
pos=re.search(str);
QString sep=re.cap(1);
if(!str.left(pos).isEmpty())
{
list.append(new SentenceChunk(di,str.left(pos).stripWhiteSpace()));
_separators.append(sep);
}
else
{
uint current=_separators.count()-1;
_separators[current]=_separators[current]+sep;
}
str=str.remove(0,pos+re.cap(1).length());
} while(!str.isEmpty() && pos != -1);
return list;
}
QPtrList< AbstractChunk > CaseBasedWordChunkFactory::chunks( )
{
QString str=string;
QPtrList<AbstractChunk> list;
if(str.isEmpty()) return list;
uint slen=str.length();
kdDebug(0) << "CaseWordChunk string:" << str << endl;
QString tmpWord;
bool upcase;
for(uint i=0;i<=slen;i++)
{
bool tmpCase=(str[i]==str[i].upper());
if(upcase!=tmpCase)
{
if(!tmpWord.isEmpty() && !tmpWord.isNull()){
list.append(new WordChunk(di,tmpWord));
_separators.append("");
}
kdDebug(0) << "CaseWordChunk:" << tmpWord << endl;
tmpWord="";
}
tmpWord+=str[i];
upcase=tmpCase;
}
return list;
}
WordChunkFactory::WordChunkFactory( DataBaseInterface * _di ) : AbstractChunkFactory(_di)
{
}
SentenceChunkFactory::SentenceChunkFactory( DataBaseInterface * _di ): AbstractChunkFactory(_di)
{
}
CaseBasedWordChunkFactory::CaseBasedWordChunkFactory( DataBaseInterface * _di ): AbstractChunkFactory(_di)
{
}
|