]> Git trees. - libqmvoc.git/commitdiff
Add compability methods to read kvtml1 tenses.
authorFrederik Gladhorn <gladhorn@kde.org>
Fri, 31 Aug 2007 09:09:26 +0000 (09:09 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Fri, 31 Aug 2007 09:09:26 +0000 (09:09 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=706784

keduvocdocument/keduvocconjugation.h
keduvocdocument/keduvockvtmlcompability.cpp
keduvocdocument/keduvockvtmlcompability.h
keduvocdocument/keduvockvtmlreader.cpp

index 831ef487f3d7285b635cdaea71e2dc48635cd200..c73fa8b527225c2f948f81cd78591db7a032536f 100644 (file)
 
 #include <QtCore/QStringList>
 
-
+///@todo get rid of this old strange prefix thing: used to mark personal pronouns.
 #define CONJ_PREFIX            "--"   // definition of prefixes (I, you, ..)
 
-#define UL_USER_TENSE          "#"   // designates number of user tense
-
 
 class KEDUVOCDOCUMENT_EXPORT KEduVocTenseRelation
 {
@@ -72,14 +70,8 @@ public:
 
     ~KEduVocConjugation();
 
-    /**
-     * @return
-     */
     int entryCount() const;
 
-
-    QString getVerbName() const;
-
     QString getType( int index );
     void setType( int index, const QString & type );
     void cleanUp();
index 0728723540aaa4a6ef7a34a442380a883cc1d6c4..186daaf7559e036688cc8d754ac5b137246b458b 100644 (file)
 
 #include <KDebug>
 
-const QString KEduVocKvtmlCompability::KVTML_1_USAGE_USER_DEFINED = QString( "#" );
-const QString KEduVocKvtmlCompability::KVTML_1_USAGE_SEPERATOR = QString( ":" );
-
-const QString KEduVocKvtmlCompability::KVTML_1_TYPE_USER = QString( "#" );
-const QString KEduVocKvtmlCompability::KVTML_1_TYPE_DIV = QString( ":" );
+const QString KEduVocKvtmlCompability::KVTML_1_USER_DEFINED = QString( "#" );
+const QString KEduVocKvtmlCompability::KVTML_1_SEPERATOR = QString( ":" );
 
 
 KEduVocKvtmlCompability::KEduVocKvtmlCompability()
 {
     m_usages = usageMap();
     m_userdefinedUsageCounter = 0;
+    m_userdefinedTenseCounter = 0;
 
     initOldTypeLists();
-    initOldConjugations();
+    initOldTenses();
 }
 
 
 QSet<QString> KEduVocKvtmlCompability::usageFromKvtml1( const QString & oldUsage ) const
 {
     QSet<QString> usages;
-    foreach( QString usage , oldUsage.split( KVTML_1_USAGE_SEPERATOR, QString::SkipEmptyParts ) ) {
+    foreach( QString usage , oldUsage.split( KVTML_1_SEPERATOR, QString::SkipEmptyParts ) ) {
         usages.insert( m_usages[usage] );
     }
     return usages;
@@ -111,7 +109,7 @@ void KEduVocKvtmlCompability::addUserdefinedUsage( const QString & usage )
 {
     // start counting at 1 !!!
     m_userdefinedUsageCounter++;
-    m_usages[KVTML_1_USAGE_USER_DEFINED + QString::number( m_userdefinedUsageCounter )] = usage;
+    m_usages[KVTML_1_USER_DEFINED + QString::number( m_userdefinedUsageCounter )] = usage;
 }
 
 QSet< QString > KEduVocKvtmlCompability::documentUsages() const
@@ -161,7 +159,7 @@ QString KEduVocKvtmlCompability::mainTypeFromOldFormat( const QString & typeSubt
     QString mainType;
     int i;
 
-    if (( i = typeSubtypeString.indexOf( KVTML_1_TYPE_DIV ) ) >= 0 )
+    if (( i = typeSubtypeString.indexOf( KVTML_1_SEPERATOR ) ) >= 0 )
         mainType = typeSubtypeString.left( i );
     else
         mainType = typeSubtypeString;
@@ -189,7 +187,7 @@ QString KEduVocKvtmlCompability::subTypeFromOldFormat( const QString & typeSubty
 {
     int i;
     QString t = typeSubtypeString;
-    if (( i = t.indexOf( KVTML_1_TYPE_DIV ) ) >= 0 ) {
+    if (( i = t.indexOf( KVTML_1_SEPERATOR ) ) >= 0 ) {
         t.remove( 0, i+1 );
     } else {
         return QString();
@@ -210,13 +208,13 @@ QString KEduVocKvtmlCompability::oldType( const QString & mainType, const QStrin
     oldType = m_oldMainTypeNames.key( mainType );
     oldSubType = m_oldSubTypeNames.key( subType );
     if ( !oldSubType.isEmpty() ) {
-        return oldType + KVTML_1_TYPE_DIV + oldSubType;
+        return oldType + KVTML_1_SEPERATOR + oldSubType;
     }
     return oldType;
 
 }
 
-void KEduVocKvtmlCompability::initOldConjugations()
+void KEduVocKvtmlCompability::initOldTenses()
 {
     m_oldTenses["PrSi"] = i18n( "Simple Present" );
     m_oldTenses["PrPr"] = i18n( "Present Progressive" );
@@ -226,3 +224,32 @@ void KEduVocKvtmlCompability::initOldConjugations()
     m_oldTenses["PaPa"] = i18n( "Past Participle" );
     m_oldTenses["FuSi"] = i18n( "Future" );
 }
+
+
+void KEduVocKvtmlCompability::addUserdefinedTense(const QString & tense)
+{
+    m_userdefinedTenseCounter++;
+    m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
+    m_tenses.insert(tense);
+
+    kDebug() << " Add tense: " << KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter ) << " - " << tense;
+}
+
+
+QString KEduVocKvtmlCompability::tenseFromKvtml1(const QString & oldTense)
+{
+    // in case the document got chaged, at least make up something as tense
+    if (!m_oldTenses.keys().contains(oldTense)) {
+        m_oldTenses[oldTense] = oldTense;
+        kDebug() << "Warning, tense not found in document!";
+    }
+    m_tenses.insert(m_oldTenses.value(oldTense));
+    return m_oldTenses.value(oldTense);
+}
+
+
+QStringList KEduVocKvtmlCompability::documentTenses() const
+{
+    return m_tenses.values();
+}
+
index 109812a10eb61489fb11bc4dc0848615839ba222..c8ea1703766004944a6184742cdf081b413e8e7a 100644 (file)
@@ -72,9 +72,6 @@
 #define UL_USER_USAGE  "#"   // designates number of user type
 
 
-
-
-
 /**
   * @file contains defines and constants necessary for reading kvtml files prior to KDE4. kvtml version 1.
   */
@@ -134,6 +131,9 @@ public:
     QString oldType( const QString& mainType, const QString& subType ) const;
 
 
+    void addUserdefinedTense( const QString& tense );
+    QString tenseFromKvtml1( const QString & oldTense );
+    QStringList documentTenses() const;
 
 private:
     /**
@@ -146,10 +146,6 @@ private:
     /// Map to store usages. Initialized with preset values by the constructor. Later user defined usages can be added.
     QMap< QString, QString > m_usages;
 
-    /// # defines user defined usage
-    static const QString KVTML_1_USAGE_USER_DEFINED;
-    /// : seperates usages
-    static const QString KVTML_1_USAGE_SEPERATOR;
 
     /// only order was decisive, we have to keep count.
     int m_userdefinedUsageCounter;
@@ -161,14 +157,17 @@ private:
     QMap<QString, QString> m_oldMainTypeNames;
     QMap<QString, QString> m_oldSubTypeNames;
 
-    static const QString KVTML_1_TYPE_USER;
-    static const QString KVTML_1_TYPE_DIV;
-
 ///////////TENSES/CONJUGATIONS///////
-    void initOldConjugations();
-    QMap<QString, QString> m_oldTenses;
+    void initOldTenses();
 
+    QMap<QString, QString> m_oldTenses;
+    int m_userdefinedTenseCounter;
+    QSet<QString> m_tenses;
 
+    /// # defines user defined usage/word type/tense
+    static const QString KVTML_1_USER_DEFINED;
+    /// : seperates usages/word types
+    static const QString KVTML_1_SEPERATOR;
 };
 
 
index 6a79ac5ab4a2361f2de43e087f49194fe7611e02..0eea625ebdea4605325e36a998af94d03c2392e6 100644 (file)
@@ -180,6 +180,8 @@ bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent )
         }
     }
 
+    m_doc->setTenseDescriptions(m_compability.documentTenses());
+
     return true;
 }
 
@@ -387,7 +389,7 @@ bool KEduVocKvtmlReader::readConjug( QDomElement &domElementParent, QList<KEduVo
     QString pers3_f_plur;
     QString pers3_n_plur;
     QString lang;
-    QString type;
+    QString tense; // former type
 
     // this gets a list of keduvocconjugations, count will be the conjug number to be filled.
     int count = 0;
@@ -402,7 +404,7 @@ bool KEduVocKvtmlReader::readConjug( QDomElement &domElementParent, QList<KEduVo
     {
         if ( domElementConjugChild.tagName() == KV_CON_ENTRY ) {            // if KV_CON_ENTRY == "e" is found, we are reading a personal pronun definition.
             // CONJ_PREFIX is defined as "--"
-            type = CONJ_PREFIX;
+            tense = CONJ_PREFIX;
 
             //----------
             // Attribute
@@ -420,25 +422,9 @@ bool KEduVocKvtmlReader::readConjug( QDomElement &domElementParent, QList<KEduVo
 
             // "n" == is the type is the tense
             QDomAttr domAttrLang = domElementConjugChild.attributeNode( KV_CON_NAME );
-            type = domAttrLang.value();
-            if ( type.isNull() )
-                type = "";
-
-            // if it starts with "#" the user typed in the tense name
-            if ( type.length() != 0 && type.left( 1 ) == UL_USER_TENSE ) {
-                int num = qMin( type.mid( 1, 40 ).toInt(), 1000 ); // paranoia check
-                if ( num > m_doc->tenseDescriptions().count() ) {
-                    // description missing ?
-                    QString s;
-                    QStringList sl = m_doc->tenseDescriptions();
-                    for ( int i = m_doc->tenseDescriptions().count(); i < num; i++ ) {
-                        s.setNum( i + 1 );
-                        s.prepend( "#" ); // invent descr according to number
-                        sl.append( s );
-                    }
-                    m_doc->setTenseDescriptions( sl );
-                }
-            }
+            QString oldShortTense = domAttrLang.value();
+
+            tense = m_compability.tenseFromKvtml1( oldShortTense );
         }
 
         pers1_sing = "";
@@ -525,24 +511,24 @@ bool KEduVocKvtmlReader::readConjug( QDomElement &domElementParent, QList<KEduVo
         // now set the data: [count] - number of conjug?
         // type - the tense?
         // finally the person
-        curr_conjug[count].setPers3SingularCommon( type, s3_common );
-        curr_conjug[count].setPers3PluralCommon( type, p3_common );
-        curr_conjug[count].setPers1Singular( type, pers1_sing );
-        curr_conjug[count].setPers2Singular( type, pers2_sing );
-        curr_conjug[count].setPers3FemaleSingular( type, pers3_f_sing );
-        curr_conjug[count].setPers3MaleSingular( type, pers3_m_sing );
-        curr_conjug[count].setPers3NaturalSingular( type, pers3_n_sing );
-        curr_conjug[count].setPers1Plural( type, pers1_plur );
-        curr_conjug[count].setPers2Plural( type, pers2_plur );
-        curr_conjug[count].setPers3FemalePlural( type, pers3_f_plur );
-        curr_conjug[count].setPers3MalePlural( type, pers3_m_plur );
-        curr_conjug[count].setPers3NaturalPlural( type, pers3_n_plur );
+        curr_conjug[count].setPers3SingularCommon( tense, s3_common );
+        curr_conjug[count].setPers3PluralCommon( tense, p3_common );
+        curr_conjug[count].setPers1Singular( tense, pers1_sing );
+        curr_conjug[count].setPers2Singular( tense, pers2_sing );
+        curr_conjug[count].setPers3FemaleSingular( tense, pers3_f_sing );
+        curr_conjug[count].setPers3MaleSingular( tense, pers3_m_sing );
+        curr_conjug[count].setPers3NaturalSingular( tense, pers3_n_sing );
+        curr_conjug[count].setPers1Plural( tense, pers1_plur );
+        curr_conjug[count].setPers2Plural( tense, pers2_plur );
+        curr_conjug[count].setPers3FemalePlural( tense, pers3_f_plur );
+        curr_conjug[count].setPers3MalePlural( tense, pers3_m_plur );
+        curr_conjug[count].setPers3NaturalPlural( tense, pers3_n_plur );
 
         if ( domElementConjugChild.tagName() == KV_CON_ENTRY )
             count++;
 
         domElementConjugChild = domElementConjugChild.nextSibling().toElement();
-    } // while -> next type, count++
+    } // while -> next tense, count++
 
     return true;
 }
@@ -578,33 +564,19 @@ bool KEduVocKvtmlReader::readType( QDomElement &domElementParent )
 
 bool KEduVocKvtmlReader::readTense( QDomElement &domElementParent )
 {
-    QString s;
     QDomElement currentElement;
-    QStringList descriptions;
 
     QDomNodeList entryList = domElementParent.elementsByTagName( KV_TENSE_DESC );
     if ( entryList.length() <= 0 )
         return false;
 
-    descriptions.clear();
-
     for ( int i = 0; i < entryList.count(); ++i ) {
         currentElement = entryList.item( i ).toElement();
         if ( currentElement.parentNode() == domElementParent ) {
-            int no = 0;
-
-            QDomAttr attribute = currentElement.attributeNode( KV_TENSE_NO );
-            if ( !attribute.isNull() )
-                no = attribute.value().toInt();
-
-            s = currentElement.text();
-            if ( s.isNull() )
-                s = "";
-            descriptions.append( s );
+            m_compability.addUserdefinedTense( currentElement.text() );
         }
     }
 
-    m_doc->setTenseDescriptions( descriptions );
     return true;
 }