blob: 5c5fcb9319eb809ea7f3d986fa2b484f568481ec (
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
|
//
// C++ Interface: chunk
//
// Description:
//
//
// Author: Andrea Rizzi <rizzi@kde.org>, (C) 2003
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef DBSE2_CHUNK_H
#define DBSE2_CHUNK_H
#include <qstring.h>
#include <qvaluelist.h>
#include "database.h"
/**
* Abstract class for text chunks.
* Examples of chunks are "Words" or "Sentences"
* This abstraction allow to use generic algorithm on chunks,
* like chunkByChunk translation or chunk indexing.
*/
class AbstractChunk
{
public:
AbstractChunk(DataBaseInterface *_di) {di=_di;}
virtual ~AbstractChunk();
/**
* This function should return a list of translation for the current chunk.
*/
virtual QValueList<QueryResult> translations()=0;
//FIXME: is this in the right place, better in factory? check that stuff
//virtual QValueList<QueryResult> translationsFromReference(uint reference)=0;
virtual QValueList<uint> locationReferences()=0;
virtual void setLocationReferences(QValueList<uint>)=0;
virtual QString chunkString()=0;
protected:
DataBaseInterface *di;
};
/**
* Concrete impl of Chunk, in this case chunks are words.
*/
class WordChunk : public AbstractChunk
{
public:
WordChunk(DataBaseInterface *di,QString _word);
virtual QValueList<QueryResult> translations();
//virtual QValueList<QueryResult> translationsFromReference(uint reference);
virtual QValueList<uint> locationReferences();
virtual void setLocationReferences(QValueList<uint>);
virtual QString chunkString(){return word;}
//static QValueList<WordChunk> divide(QString);
private:
QString word;
};
/**
* Concrete impl of Chunk, in this case chunks are sentences.
*/
class SentenceChunk : public AbstractChunk
{
public:
SentenceChunk(DataBaseInterface *di,QString _sentence);
virtual QValueList<QueryResult> translations();
//virtual QValueList<QueryResult> translationsFromReference(uint reference);
virtual QValueList<uint> locationReferences();
virtual void setLocationReferences(QValueList<uint>);
virtual QString chunkString(){return sentence;}
// static QValueList<SentenceChunk> divide(QString);
private:
QString sentence;
};
/**********************************
CHUNK FACTORIES
**********************************/
class AbstractChunkFactory
{
public:
AbstractChunkFactory(DataBaseInterface *_di)
{
di=_di;
}
virtual ~AbstractChunkFactory(){}
virtual QPtrList<AbstractChunk> chunks()=0;
/**
Change th string and return the chunks
*/
virtual QPtrList<AbstractChunk> chunks(const QString& s)
{
string=s;
return chunks();
}
/**
* Returns the list of separators of last @ref chunks() call
*/
virtual QStringList separators(){ return _separators;}
void setQuery(const QString& s)
{
string=s;
}
protected:
QString string;
QStringList _separators;
DataBaseInterface *di;
};
class WordChunkFactory : public AbstractChunkFactory
{
public:
WordChunkFactory(DataBaseInterface *_di);
/**
YOU SHOULD DELETE THE CHUNKS!!
*/
virtual QPtrList<AbstractChunk> chunks();
};
class CaseBasedWordChunkFactory : public AbstractChunkFactory
{
public:
CaseBasedWordChunkFactory(DataBaseInterface *_di);
/**
YOU SHOULD DELETE THE CHUNKS!!
*/
virtual QPtrList<AbstractChunk> chunks();
};
class SentenceChunkFactory : public AbstractChunkFactory
{
public:
SentenceChunkFactory(DataBaseInterface *_di);
/**
YOU SHOULD DELETE THE CHUNKS!!
*/
virtual QPtrList<AbstractChunk> chunks();
};
#endif //_CHUNK_H_
|