00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "keduvockvtmlcompability.h"
00025
00026 #include "keduvocwordtype.h"
00027 #include <KDebug>
00028
00029 const QString KEduVocKvtmlCompability::KVTML_1_USER_DEFINED = QString( "#" );
00030 const QString KEduVocKvtmlCompability::KVTML_1_SEPERATOR = QString( ":" );
00031
00032
00033 KEduVocKvtmlCompability::KEduVocKvtmlCompability()
00034 {
00035 m_userdefinedTenseCounter = 0;
00036 m_userdefinedTypeCounter = 0;
00037
00038 initOldTypeLists();
00039 initOldTenses();
00040 }
00041
00042
00044 void KEduVocKvtmlCompability::initOldTypeLists()
00045 {
00046 m_oldMainTypeNames.clear();
00047 m_oldMainTypeNames.insert( "v", i18nc( "@item:inlistbox The grammatical type of a word", "Verb" ) );
00048 m_oldMainTypeNames.insert( "n", i18nc( "@item:inlistbox The grammatical type of a word", "Noun" ) );
00049 m_oldMainTypeNames.insert( "nm", i18nc( "@item:inlistbox The grammatical type of a word", "Name" ) );
00050 m_oldMainTypeNames.insert( "ar", i18nc( "@item:inlistbox The grammatical type of a word", "Article" ) );
00051 m_oldMainTypeNames.insert( "aj", i18nc( "@item:inlistbox The grammatical type of a word", "Adjective" ) );
00052 m_oldMainTypeNames.insert( "av", i18nc( "@item:inlistbox The grammatical type of a word", "Adverb" ) );
00053 m_oldMainTypeNames.insert( "pr", i18nc( "@item:inlistbox The grammatical type of a word", "Pronoun" ) );
00054 m_oldMainTypeNames.insert( "ph", i18nc( "@item:inlistbox The grammatical type of an entry", "Phrase" ) );
00055 m_oldMainTypeNames.insert( "num", i18nc( "@item:inlistbox The grammatical type of a word", "Numeral" ) );
00056 m_oldMainTypeNames.insert( "con", i18nc( "@item:inlistbox The grammatical type of a word", "Conjunction" ) );
00057 m_oldMainTypeNames.insert( "pre", i18nc( "@item:inlistbox The grammatical type of a word", "Preposition" ) );
00058 m_oldMainTypeNames.insert( "qu", i18nc( "@item:inlistbox The grammatical type of an entry", "Question" ) );
00059
00060
00061 m_oldSubTypeNames.clear();
00062 m_oldSubTypeNames.insert( "ord", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (first, second, third, ...)","Ordinal" ) );
00063 m_oldSubTypeNames.insert( "crd", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (one, two, three, ...)","Cardinal" ) );
00064 m_oldSubTypeNames.insert( "def", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ) );
00065 m_oldSubTypeNames.insert( "ind", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ) );
00066 m_oldSubTypeNames.insert( "re", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ) );
00067 m_oldSubTypeNames.insert( "ir", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ) );
00068 m_oldSubTypeNames.insert( "pos", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ) );
00069 m_oldSubTypeNames.insert( "per", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ) );
00070 m_oldSubTypeNames.insert( "m", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ) );
00071 m_oldSubTypeNames.insert( "f", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ) );
00072 m_oldSubTypeNames.insert( "s", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ) );
00073 }
00074
00075
00076 KEduVocWordType* KEduVocKvtmlCompability::typeFromOldFormat(KEduVocWordType* parent, const QString & typeSubtypeString ) const
00077 {
00078
00079 if ( typeSubtypeString.length() >= 2 && typeSubtypeString.left( 1 ) == QM_USER_TYPE ) {
00080
00081 int selfDefinedTypeIndex = typeSubtypeString.right( typeSubtypeString.count()-1 ).toInt() -1;
00082 return static_cast<KEduVocWordType*>(parent->childContainer(selfDefinedTypeIndex));
00083 }
00084
00085
00086 QString mainType;
00087 QString subType;
00088 int i;
00089
00090 if (( i = typeSubtypeString.indexOf( KVTML_1_SEPERATOR ) ) >= 0 ) {
00091 mainType = typeSubtypeString.left( i );
00092 subType = typeSubtypeString.right( i+1 );
00093 } else {
00094 mainType = typeSubtypeString;
00095 }
00096
00097
00098
00099 if ( mainType == "1" ) {
00100 mainType = QM_VERB;
00101 } else if ( mainType == "2" ) {
00102 mainType = QM_NOUN;
00103 } else if ( mainType == "3" ) {
00104 mainType = QM_NAME;
00105 }
00106
00107 QString typeName = m_oldMainTypeNames.value( mainType );
00108 if ( typeName.isEmpty() ) {
00109 kDebug() << "Unknown old maintype: " << typeSubtypeString;
00110 return 0;
00111 }
00112
00113 QString subTypeName = m_oldSubTypeNames.value( subType );
00114
00115 foreach (KEduVocContainer* wordType, parent->childContainers()) {
00116 if (wordType->name() == typeName) {
00117 if (subType.isEmpty()) {
00118 return static_cast<KEduVocWordType*>(wordType);
00119 } else {
00120 foreach (KEduVocContainer* subWordType, wordType->childContainers()) {
00121 if (subWordType->name() == subTypeName) {
00122 return static_cast<KEduVocWordType*>(subWordType);
00123 }
00124 }
00125 }
00126 }
00127 }
00128
00129 return 0;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 void KEduVocKvtmlCompability::initOldTenses()
00175 {
00176 m_oldTenses["PrSi"] = i18n( "Simple Present" );
00177 m_oldTenses["PrPr"] = i18n( "Present Progressive" );
00178 m_oldTenses["PrPe"] = i18n( "Present Perfect" );
00179 m_oldTenses["PaSi"] = i18n( "Simple Past" );
00180 m_oldTenses["PaPr"] = i18n( "Past Progressive" );
00181 m_oldTenses["PaPa"] = i18n( "Past Participle" );
00182 m_oldTenses["FuSi"] = i18n( "Future" );
00183 }
00184
00185
00186 void KEduVocKvtmlCompability::addUserdefinedTense(const QString & tense)
00187 {
00188 m_userdefinedTenseCounter++;
00189 m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
00190 m_tenses.insert(tense);
00191
00192 kDebug() << " Add tense: " << KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter ) << " - " << tense;
00193 }
00194
00195
00196 QString KEduVocKvtmlCompability::tenseFromKvtml1(const QString & oldTense)
00197 {
00198
00199 if (!m_oldTenses.keys().contains(oldTense)) {
00200 m_oldTenses[oldTense] = oldTense;
00201 kDebug() << "Warning, tense " << oldTense << " not found in document!";
00202 }
00203 m_tenses.insert(m_oldTenses.value(oldTense));
00204 return m_oldTenses.value(oldTense);
00205 }
00206
00207
00208 QStringList KEduVocKvtmlCompability::documentTenses() const
00209 {
00210 return m_tenses.values();
00211 }
00212
00213
00214 QString KEduVocKvtmlCompability::oldTense(const QString & tense)
00215 {
00217 if ( !m_oldTenses.values().contains(tense) ) {
00218 m_userdefinedTenseCounter++;
00219 m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
00220 }
00221 return m_oldTenses.key(tense);
00222 }
00223
00224 void KEduVocKvtmlCompability::setupWordTypes(KEduVocWordType * parent)
00225 {
00226 QStringList wordTypeNames;
00227 wordTypeNames
00228 << i18nc( "The grammatical type of a word", "Verb" )
00229 << i18nc( "The grammatical type of a word", "Noun" )
00230 << i18nc( "The grammatical type of a word", "Name" )
00231 << i18nc( "The grammatical type of a word", "Article" )
00232 << i18nc( "The grammatical type of a word", "Adjective" )
00233 << i18nc( "The grammatical type of a word", "Adverb" )
00234 << i18nc( "The grammatical type of a word", "Pronoun" )
00235 << i18nc( "The grammatical type of an entry", "Phrase" )
00236 << i18nc( "The grammatical type of a word", "Numeral" )
00237 << i18nc( "The grammatical type of a word", "Conjunction" )
00238 << i18nc( "The grammatical type of a word", "Preposition" )
00239 << i18nc( "The grammatical type of an entry", "Question" );
00240
00241 foreach (const QString &typeName, wordTypeNames) {
00242 KEduVocWordType* wordType = new KEduVocWordType(typeName, parent);
00243 parent->appendChildContainer(wordType);
00244 m_userdefinedTypeCounter++;
00245 }
00246 static_cast<KEduVocWordType*>(parent->childContainer(4))->setWordType(KEduVocWordFlag::Adjective);
00247 static_cast<KEduVocWordType*>(parent->childContainer(5))->setWordType(KEduVocWordFlag::Adverb);
00248
00249 KEduVocWordType* numeral = static_cast<KEduVocWordType*>(parent->childContainer(8));
00250 KEduVocWordType* wordType = new KEduVocWordType(
00251 i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (first, second, third, ...)","Ordinal" ), numeral);
00252 wordType->setWordType(KEduVocWordFlag::Adjective);
00253 numeral->appendChildContainer(wordType);
00254 wordType = new KEduVocWordType(
00255 i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (one, two, three, ...)","Cardinal" ), numeral);
00256
00257 wordType->setWordType(KEduVocWordFlag::Adjective);
00258 numeral->appendChildContainer(wordType);
00259
00260 KEduVocWordType* article = static_cast<KEduVocWordType*>(parent->childContainer(3));
00261 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ), article);
00262 wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Definite);
00263 article->appendChildContainer(wordType);
00264 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ), article);
00265 wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Indefinite);
00266 article->appendChildContainer(wordType);
00267
00268 KEduVocWordType* verb = static_cast<KEduVocWordType*>(parent->childContainer(0));
00269 verb->setWordType(KEduVocWordFlag::Verb);
00270 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ), verb);
00271 wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Regular);
00272 verb->appendChildContainer(wordType);
00273 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ), verb);
00274 verb->appendChildContainer(wordType);
00275 wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Irregular);
00276
00277 KEduVocWordType* noun = static_cast<KEduVocWordType*>(parent->childContainer(1));
00278 noun->setWordType(KEduVocWordFlag::Noun);
00279 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ), noun);
00280 noun->appendChildContainer(wordType);
00281 wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine);
00282 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ), noun);
00283 noun->appendChildContainer(wordType);
00284 wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine);
00285 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ), noun);
00286 noun->appendChildContainer(wordType);
00287 wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Neuter);
00288
00289
00290 KEduVocWordType* pronoun = static_cast<KEduVocWordType*>(parent->childContainer(6));
00291 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ), pronoun);
00292 wordType->setWordType(KEduVocWordFlag::Pronoun);
00293 pronoun->appendChildContainer(wordType);
00294 wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ), pronoun);
00295 wordType->setWordType(KEduVocWordFlag::Pronoun);
00296 pronoun->appendChildContainer(wordType);
00297 }
00298