summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabeldict/modules/dbsearchengine2/chunk.h
blob: 2578e59ee9f4a83d1ee9dcc65d45717ee559e35d (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 <tqstring.h>
#include <tqvaluelist.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 TQValueList<QueryResult> translations()=0;
    
    //FIXME: is this in the right place, better in factory? check that stuff
    //virtual TQValueList<QueryResult> translationsFromReference(uint reference)=0;
    virtual TQValueList<uint> locationReferences()=0;
    virtual void setLocationReferences(TQValueList<uint>)=0;
    virtual TQString chunkString()=0;
    
    protected:
    DataBaseInterface *di;
};

/**
  * Concrete impl of Chunk, in this case chunks are words.
  */
class WordChunk : public AbstractChunk
{
    public:
    WordChunk(DataBaseInterface *di,TQString _word);
    virtual TQValueList<QueryResult> translations();
    //virtual TQValueList<QueryResult> translationsFromReference(uint reference);
    virtual TQValueList<uint> locationReferences();
    virtual void setLocationReferences(TQValueList<uint>);
    virtual TQString chunkString(){return word;}

    //static TQValueList<WordChunk> divide(TQString);
    private:
    TQString word;
};

/**
  * Concrete impl of Chunk, in this case chunks are sentences.
  */
class SentenceChunk : public AbstractChunk
{
    public:
    SentenceChunk(DataBaseInterface *di,TQString _sentence);
    virtual TQValueList<QueryResult> translations();
    //virtual TQValueList<QueryResult> translationsFromReference(uint reference);
    virtual TQValueList<uint> locationReferences();
    virtual void setLocationReferences(TQValueList<uint>);
    virtual TQString chunkString(){return sentence;}

   // static TQValueList<SentenceChunk> divide(TQString);
    
    private:
    TQString sentence;    
};


/**********************************
  CHUNK FACTORIES
**********************************/


class AbstractChunkFactory 
{
  public:
    AbstractChunkFactory(DataBaseInterface *_di)
    {
	di=_di;
    }
    virtual ~AbstractChunkFactory(){}
    virtual  TQPtrList<AbstractChunk> chunks()=0;
    /**
      Change th string and return the chunks
      */
    virtual  TQPtrList<AbstractChunk> chunks(const TQString& s)
    {
	string=s;
	return chunks();
    }
    /**
      * Returns the list of separators of last @ref chunks() call
      */
    
    virtual  TQStringList separators(){ return _separators;}
    void setQuery(const TQString& s)
    {
	string=s;
    }
  protected:
    TQString string;
    TQStringList _separators;
    DataBaseInterface *di;
};

class WordChunkFactory : public AbstractChunkFactory
{
  public:
    WordChunkFactory(DataBaseInterface *_di);
    /**
      YOU SHOULD DELETE THE CHUNKS!!
      */
    virtual  TQPtrList<AbstractChunk> chunks();
};

class CaseBasedWordChunkFactory : public AbstractChunkFactory
{
  public:
    CaseBasedWordChunkFactory(DataBaseInterface *_di);
    /**
      YOU SHOULD DELETE THE CHUNKS!!
      */
    virtual  TQPtrList<AbstractChunk> chunks();
};

class SentenceChunkFactory : public AbstractChunkFactory
{
  public:
    SentenceChunkFactory(DataBaseInterface *_di);
    
    /**
      YOU SHOULD DELETE THE CHUNKS!!
      */
    virtual  TQPtrList<AbstractChunk> chunks();
};


#endif //_CHUNK_H_