• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

libkdeedu/keduvocdocument

keduvockvtmlcompability.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003     C++ Implementation: keduvockvtml1compability_p
00004 
00005     -----------------------------------------------------------------------
00006 
00007     begin         : Di Aug 28 2007
00008 
00009     copyright     : (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00010 
00011     -----------------------------------------------------------------------
00012 
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
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     // check if it's user defined
00079     if ( typeSubtypeString.length() >= 2 && typeSubtypeString.left( 1 ) == QM_USER_TYPE ) {
00080         // they started counting at 1, we need to know which index we are dealing with:
00081         int selfDefinedTypeIndex = typeSubtypeString.right( typeSubtypeString.count()-1 ).toInt() -1;
00082         return static_cast<KEduVocWordType*>(parent->childContainer(selfDefinedTypeIndex));
00083     }
00084 
00085     // assume the parent is set up to contain the old types correctly
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     // convert from pre-0.5 versions (I guess we can just leave that in here.
00098     // I seriously doubt that any such documents exist...
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 if ( type.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
00139                 // they started counting at 1, we need to know which index we are dealing with:
00140                 int selfDefinedTypeIndex = type.right( type.count()-1 ).toInt() -1;
00141 
00142                 // append invented types (do we not trust our own writer?)
00143                 if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
00144                     while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
00145                         m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
00146                     }
00147                 }
00148                 type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
00149             } else {
00150                 type = m_compability.mainTypeFromOldFormat( oldType );
00151                 subType = m_compability.subTypeFromOldFormat( oldType );
00152             } // not user defined - preset types
00153 
00154 
00155 if ( oldType.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
00156             // they started counting at 1
00157             int selfDefinedTypeIndex = oldType.right( type.count()-1 ).toInt() -1;
00158             // append invented types (do we not trust our own writer?)
00159             if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
00160                 while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
00161                     m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
00162                 }
00163             }
00164             type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
00165         } else {
00166             type = m_compability.mainTypeFromOldFormat( oldType );
00167             subType = m_compability.subTypeFromOldFormat( oldType );
00168         } // not user defined - preset types
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     // in case the document got chaged, at least make up something as tense
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" ) // 0
00229         << i18nc( "The grammatical type of a word", "Noun" ) // 1
00230         << i18nc( "The grammatical type of a word", "Name" )
00231         << i18nc( "The grammatical type of a word", "Article" ) // 3
00232         << i18nc( "The grammatical type of a word", "Adjective" ) // 4
00233         << i18nc( "The grammatical type of a word", "Adverb" ) // 5
00234         << i18nc( "The grammatical type of a word", "Pronoun" ) // 6
00235         << i18nc( "The grammatical type of an entry", "Phrase" )
00236         << i18nc( "The grammatical type of a word", "Numeral" ) // 8
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 

libkdeedu/keduvocdocument

Skip menu "libkdeedu/keduvocdocument"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal