1 /***************************************************************************
3 manage grammar parts (articles, conjugation)
5 -----------------------------------------------------------------------
7 begin : Sat Nov 27 09:50:53 MET 1999
9 copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
10 (C) 2001 The KDE-EDU team
11 (C) 2004-2005 Peter Hedlund <peter@peterandlinda.com>
13 -----------------------------------------------------------------------
15 ***************************************************************************/
17 /***************************************************************************
19 * This program is free software; you can redistribute it and/or modify *
20 * it under the terms of the GNU General Public License as published by *
21 * the Free Software Foundation; either version 2 of the License, or *
22 * (at your option) any later version. *
24 ***************************************************************************/
26 #include "GrammerManager.h"
30 Conjugation::conjug_name_t
31 Conjugation::names
[] =
33 { CONJ_SIMPLE_PRESENT
, I18N_NOOP("Simple Preset") },
34 { CONJ_PRESENT_PROGR
, I18N_NOOP("Preset Progressive") },
35 { CONJ_PRESENT_PERFECT
, I18N_NOOP("Preset Perfect") },
37 { CONJ_SIMPLE_PAST
, I18N_NOOP("Simple Past") },
38 { CONJ_PAST_PROGR
, I18N_NOOP("Past Progressive") },
39 { CONJ_PAST_PARTICIPLE
, I18N_NOOP("Past Participle") },
41 { CONJ_FUTURE
, I18N_NOOP("Future") }
45 vector
<QString
> Conjugation::userTenses
;
48 //================================================================
50 Comparison::Comparison (
62 bool Comparison::isEmpty() const
64 return ls1
.stripWhiteSpace().isEmpty()
65 && ls2
.stripWhiteSpace().isEmpty()
66 && ls3
.stripWhiteSpace().isEmpty();
70 void Comparison::clear()
78 //=================================================================
82 (const QString
&fem_def
, const QString
&fem_indef
,
83 const QString
&mal_def
, const QString
&mal_indef
,
84 const QString
&nat_def
, const QString
&nat_indef
87 setFemale (fem_def
, fem_indef
);
88 setMale (mal_def
, mal_indef
);
89 setNatural (nat_def
, nat_indef
);
93 void Article::setFemale
94 (const QString
&def
, const QString
&indef
)
101 void Article::setMale
102 (const QString
&def
, const QString
&indef
)
109 void Article::setNatural
110 (const QString
&def
, const QString
&indef
)
118 (QString
&def
, QString
&indef
) const
126 (QString
&def
, QString
&indef
) const
133 void Article::natural
134 (QString
&def
, QString
&indef
) const
142 //==============================================================
145 int Conjugation::numEntries() const
147 return conjugations
.size();
151 vector
<TenseRelation
> Conjugation::getRelation ()
153 vector
<TenseRelation
> vec
;
155 for (int i
= 0; i
< numInternalNames(); i
++) {
156 vec
.push_back(TenseRelation(names
[i
].abbrev
,
157 i18n(names
[i
].name
)));
160 for (int i
= 0; i
< (int) userTenses
.size(); i
++) {
163 s
.insert(0, UL_USER_TENSE
);
164 vec
.push_back(TenseRelation(s
, userTenses
[i
]));
171 void Conjugation::setTenseNames (vector
<QString
> names
)
177 QString
Conjugation::getName (const QString
&abbrev
)
179 if (abbrev
.length() >= 2 && abbrev
[0] == QString(UL_USER_TENSE
)) {
182 int i
= s
.toInt() - 1;
184 if (i
< (int) userTenses
.size() )
185 return userTenses
[i
];
190 for (int i
= 0; i
< (int) numInternalNames(); i
++)
191 if (names
[i
].abbrev
== abbrev
) {
192 return i18n(names
[i
].name
);
200 QString
Conjugation::getName (int idx
)
202 if (idx
< numInternalNames() )
203 return i18n(names
[idx
].name
);
205 else if (idx
< numTenses() )
206 return userTenses
[idx
-numInternalNames()];
213 QString
Conjugation::getAbbrev (const QString
&name
)
215 for (int i
= 0; i
< (int) userTenses
.size(); i
++)
216 if (userTenses
[i
] == name
) {
219 s
.insert(0, UL_USER_TENSE
);
223 for (int i
= 0; i
< (int) numInternalNames(); i
++)
224 if (names
[i
].name
== name
)
225 return names
[i
].abbrev
;
231 QString
Conjugation::getAbbrev (int idx
)
233 if (idx
< numInternalNames() )
234 return names
[idx
].abbrev
;
236 else if (idx
< numTenses() ) {
238 s
.setNum(idx
-numInternalNames()+1);
239 s
.insert(0, UL_USER_TENSE
);
248 int Conjugation::numInternalNames()
250 return sizeof(names
) / sizeof(names
[0]);
254 int Conjugation::numTenses()
256 return numInternalNames()+userTenses
.size();
260 QString
Conjugation::getType (int idx
)
262 if (idx
>= (int) conjugations
.size() )
265 return conjugations
[idx
].type
;
269 void Conjugation::setType (int idx
, const QString
& type
)
271 if (idx
>= (int) conjugations
.size() )
274 conjugations
[idx
].type
= type
;
278 void Conjugation::cleanUp ()
280 for (int i
= (int)conjugations
.size()-1; i
>= 0; i
--) {
281 const conjug_t
*ctp
= &conjugations
[i
];
282 if ( ctp
->pers1_sing
.stripWhiteSpace().isEmpty()
283 && ctp
->pers2_sing
.stripWhiteSpace().isEmpty()
284 && ctp
->pers3_m_sing
.stripWhiteSpace().isEmpty()
285 && ctp
->pers3_f_sing
.stripWhiteSpace().isEmpty()
286 && ctp
->pers3_n_sing
.stripWhiteSpace().isEmpty()
287 && ctp
->pers1_plur
.stripWhiteSpace().isEmpty()
288 && ctp
->pers2_plur
.stripWhiteSpace().isEmpty()
289 && ctp
->pers3_m_plur
.stripWhiteSpace().isEmpty()
290 && ctp
->pers3_f_plur
.stripWhiteSpace().isEmpty()
291 && ctp
->pers3_n_plur
.stripWhiteSpace().isEmpty()
293 conjugations
.erase(conjugations
.begin() + i
);
298 bool Conjugation::isEmpty (int idx
)
300 if (idx
< (int) conjugations
.size()) {
301 const conjug_t
*ctp
= &conjugations
[idx
];
302 return ctp
->pers1_sing
.stripWhiteSpace().isEmpty()
303 && ctp
->pers2_sing
.stripWhiteSpace().isEmpty()
304 && ctp
->pers3_m_sing
.stripWhiteSpace().isEmpty()
305 && ctp
->pers3_f_sing
.stripWhiteSpace().isEmpty()
306 && ctp
->pers3_n_sing
.stripWhiteSpace().isEmpty()
307 && ctp
->pers1_plur
.stripWhiteSpace().isEmpty()
308 && ctp
->pers2_plur
.stripWhiteSpace().isEmpty()
309 && ctp
->pers3_m_plur
.stripWhiteSpace().isEmpty()
310 && ctp
->pers3_f_plur
.stripWhiteSpace().isEmpty()
311 && ctp
->pers3_n_plur
.stripWhiteSpace().isEmpty();
317 #define _GET_CON_(elem, type, default) \
318 for (int i = 0; i < (int) conjugations.size(); i++) \
319 if (conjugations[i].type == type) \
320 return conjugations[i].elem; \
324 bool Conjugation::pers3SingularCommon(const QString
&type
) const
326 _GET_CON_(s3common
, type
, false);
330 bool Conjugation::pers3PluralCommon(const QString
&type
) const
332 _GET_CON_(p3common
, type
, false);
336 QString
Conjugation::pers1Singular
337 (const QString
&type
) const
339 _GET_CON_(pers1_sing
, type
, "");
343 QString
Conjugation::pers2Singular
344 (const QString
&type
) const
346 _GET_CON_(pers2_sing
, type
, "");
350 QString
Conjugation::pers3FemaleSingular
351 (const QString
&type
) const
353 _GET_CON_(pers3_f_sing
, type
, "");
357 QString
Conjugation::pers3MaleSingular
358 (const QString
&type
) const
360 _GET_CON_(pers3_m_sing
, type
, "");
364 QString
Conjugation::pers3NaturalSingular
365 (const QString
&type
) const
367 _GET_CON_(pers3_n_sing
, type
, "");
371 QString
Conjugation::pers1Plural
372 (const QString
&type
) const
374 _GET_CON_(pers1_plur
, type
, "");
378 QString
Conjugation::pers2Plural
379 (const QString
&type
) const
381 _GET_CON_(pers2_plur
, type
, "");
385 QString
Conjugation::pers3FemalePlural
386 (const QString
&type
) const
388 _GET_CON_(pers3_f_plur
, type
, "");
392 QString
Conjugation::pers3MalePlural
393 (const QString
&type
) const
395 _GET_CON_(pers3_m_plur
, type
, "");
399 QString
Conjugation::pers3NaturalPlural
400 (const QString
&type
) const
402 _GET_CON_(pers3_n_plur
, type
, "");
409 #define _SET_CON_(elem, type, str) \
410 for (int i = 0; i < (int) conjugations.size(); i++) \
411 if (conjugations[i].type == type) { \
412 conjugations[i].elem = str; \
418 conjugations.push_back(ct);
421 void Conjugation::setPers3PluralCommon(const QString
&type
, bool f
)
423 _SET_CON_(p3common
, type
, f
);
427 void Conjugation::setPers3SingularCommon(const QString
&type
, bool f
)
429 _SET_CON_(s3common
, type
, f
);
433 void Conjugation::setPers1Singular
434 (const QString
&type
, const QString
&str
)
436 _SET_CON_(pers1_sing
, type
, str
);
440 void Conjugation::setPers2Singular
441 (const QString
&type
, const QString
&str
)
443 _SET_CON_(pers2_sing
, type
, str
);
447 void Conjugation::setPers3FemaleSingular
448 (const QString
&type
, const QString
&str
)
450 _SET_CON_(pers3_f_sing
, type
, str
);
454 void Conjugation::setPers3MaleSingular
455 (const QString
&type
, const QString
&str
)
457 _SET_CON_(pers3_m_sing
, type
, str
);
461 void Conjugation::setPers3NaturalSingular
462 (const QString
&type
, const QString
&str
)
464 _SET_CON_(pers3_n_sing
, type
, str
);
468 void Conjugation::setPers1Plural
469 (const QString
&type
, const QString
&str
)
471 _SET_CON_(pers1_plur
, type
, str
);
475 void Conjugation::setPers2Plural
476 (const QString
&type
, const QString
&str
)
478 _SET_CON_(pers2_plur
, type
, str
);
482 void Conjugation::setPers3FemalePlural
483 (const QString
&type
, const QString
&str
)
485 _SET_CON_(pers3_f_plur
, type
, str
);
489 void Conjugation::setPers3MalePlural
490 (const QString
&type
, const QString
&str
)
492 _SET_CON_(pers3_m_plur
, type
, str
);
496 void Conjugation::setPers3NaturalPlural
497 (const QString
&type
, const QString
&str
)
499 _SET_CON_(pers3_n_plur
, type
, str
);