summaryrefslogtreecommitdiffstats
path: root/kvoctrain/kvoctrain/kvt-core/QueryManager.h
blob: 52019689b13c3aef30a8c05922d64cfd3e54454a (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
/***************************************************************************

                            manage queries

    -----------------------------------------------------------------------

    begin          : Sat Jul 11 20:50:53 MET 1999

    copyright      : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
                     (C) 2001 The KDE-EDU team
                     (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net>

    -----------------------------------------------------------------------

 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef QueryManager_included
#define QueryManager_included

#include <vector>
using namespace std;

#include "kvoctraindoc.h"
#include "prefs.h"

class kvoctrainDoc;
class TDEConfig;
class kvoctrainExpr;
class Prefs;

// internal types, indented are subtypes

#define TQM_VERB           "v"    // go
#define   TQM_VERB_IRR     "ir"
#define   TQM_VERB_REG     "re"
#define TQM_NOUN           "n"    // table, coffee
#define   TQM_NOUN_F       "f"
#define   TQM_NOUN_M       "m"
#define   TQM_NOUN_S       "s"
#define TQM_NAME           "nm"
#define TQM_ART            "ar"   // article
#define   TQM_ART_DEF      "def"  // definite    a/an
#define   TQM_ART_IND      "ind"  // indefinite  the
#define TQM_ADJ            "aj"   // adjective   expensive, good
#define TQM_ADV            "av"   // adverb      today, strongly
#define TQM_PRON           "pr"   // pronoun     you, she
#define   TQM_PRON_POS     "pos"  // possessive  my, your
#define   TQM_PRON_PER     "per"  // personal
#define TQM_PHRASE         "ph"
#define TQM_NUM            "num"  // numeral
#define   TQM_NUM_ORD      "ord"  // ordinal     first, second
#define   TQM_NUM_CARD     "crd"  // cardinal    one, two
#define TQM_INFORMAL       "ifm"
#define TQM_FIG            "fig"
#define TQM_CON            "con"  // conjuncton  and, but
#define TQM_PREP           "pre"  // preposition behind, between
#define TQM_QUEST          "qu"   // question    who, what

// type delimiters

#define TQM_USER_TYPE  "#"   // designates number of user type
#define TQM_TYPE_DIV   ":"   // divide main from subtype

//enum kvq_timeout_t { kvq_notimeout, kvq_show, kvq_cont };

enum QueryType  { TQT_Random, TQT_Multiple,
                  TQT_Articles, TQT_Conjugation, TQT_Comparison,
                  TQT_Synonym, TQT_Antonym, TQT_Example, TQT_Paraphrase };


class TypeRelation
{
 public:

  TypeRelation (const TQString & _short, const TQString & _long)
    : shortId (_short), longId(_long) {}

  TQString shortStr() const { return shortId; }
  TQString longStr()  const { return longId;  }

 protected:

  TQString  shortId, longId;
};


struct QueryEntryRef {
 QueryEntryRef (kvoctrainExpr *_exp,
                int            _nr)
     : exp(_exp), nr(_nr) {}


   kvoctrainExpr *exp;
   int            nr;
};

typedef vector<vector<QueryEntryRef> > QuerySelection;

class QueryManager
{
 public:
                // don´t change the order/remove one of these,
                // just APPEND new types
 enum CompType { DontCare,
                  MoreEqThan, MoreThan,
                  Before, Within,
                  WorseThan, WorseEqThan,
                  EqualTo, NotEqual,
                  LessEqThan, LessThan,
                  BetterThan, BetterEqThan,
                  Current, NotAssigned, NotQueried,
                  Auto_Time, Auto_Count,
                  OneOf, NotOneOf
                };

  QueryManager ();

  //void loadConfig (TDEConfig *);
  //void saveConfig (TDEConfig *);

  static vector<TypeRelation> getRelation (bool only_maintypes);
  static void setTypeNames (vector<TQString> names);
  static TQString getSubType (const TQString & type);
  static TQString getMainType (const TQString & type);

  static TQString compStr(Prefs::EnumCompType::type type);
  static TQString gradeStr(int i);
  static TQString typeStr(const TQString id);

  void setLessonItems(vector<int> indices) { lessonitems = indices; }
  void setLessonItemStr(const TQString & indices);
  //void setDateItem (time_t time) { dateitem = time; }
  //void setQueryItem (int query) { queryitem = query; }
  //void setBadItem (int bad) { baditem = bad; }
  //void setTypeItem (const TQString & type) { typeitem = type; }
  //void setGradeItem (grade_t grade) { gradeitem = grade; }
  //void setBlockItem (int item, int grade);
  //void setExpireItem (int item, int grade);

  vector<int> lessonItems() const { return lessonitems; }
  TQString lessonItemStr() const;
  //time_t dateItem () const { return dateitem; }
  //int queryItem () const { return queryitem; }
  //int badItem () const { return baditem; }
  //TQString typeItem () const { return typeitem; }
  //grade_t gradeItem () const { return gradeitem; }
  //int blockItem (int grade) const;
  //int expireItem (int grade) const;

  //void setDateComp (CompType time) { datecomp = time; }
  //void setLessonComp (CompType less) { lessoncomp = less; }
  //void setQueryComp (CompType query) { querycomp = query; }
  //void setBadComp (CompType bad) { badcomp = bad; }
  //void setTypeComp (CompType type) { typecomp = type; }
  //void setGradeComp (CompType grade) { gradecomp = grade; }

  //CompType dateComp () const { return datecomp; }
  //CompType lessonComp () const { return lessoncomp; }
  //CompType queryComp () const { return querycomp; }
  //CompType badComp () const { return badcomp; }
  //CompType typeComp () const { return typecomp; }
  //CompType gradeComp () const { return gradecomp; }

  bool validate(kvoctrainExpr *expr, int act_lesson,
                int oindex, int tindex);

  QuerySelection select(kvoctrainDoc*, int act_lesson,
                        int oindex, int tindex);

  bool validate(kvoctrainExpr *expr, int act_lesson,
                int index, TQString type);

  QuerySelection select(kvoctrainDoc*, int act_lesson,
                        int index, TQString type);

  bool validate(kvoctrainExpr *expr, int act_lesson,
                int index, QueryType type);

  QuerySelection select(kvoctrainDoc*, int act_lesson,
                        int index, QueryType type);

 protected:

  bool compareBlocking (int grade, int limit, bool use_it);
  bool compareExpiring (int grade, int limit, bool use_it);
  bool compareDate (CompType, time_t, time_t);
  bool compareQuery (CompType, int, int);
  bool compareBad (CompType, int, int);
  bool compareGrade (CompType, grade_t, grade_t);
  bool compareType (CompType, const TQString &, const TQString &);
  bool compareLesson (CompType type, int less, const vector<int> &limit, int current);

 /* CompType    typecomp,
              querycomp,
              badcomp,
              gradecomp,
              lessoncomp,
              datecomp;*/

  //time_t      dateitem;
  //int         queryitem,
  //            baditem;
  //TQString     typeitem;
  //grade_t     gradeitem;
  vector<int> lessonitems;

  //vector<int> blockItems,
  //            expireItems;

 private:
  static vector<TQString> userTypes;
};

#endif // QueryManager_included