From 4df792881594122b107ded321660edffd1541d9e Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 24 Sep 2007 17:06:43 +0000 Subject: [PATCH] Add a real personal pronoun class. It contains if male/female/neuter conjugations exist. Add methods to read/write personal ps. Rewrite conjugation to use enums. Redo the dialogs for entry conjugation and articles. Much simpler and nicer now. Conjugation practice does not work yet. Make declination class compile, not used still. Don't pass the domDoc countless times in the kvtml-1 writer, it's a member now. Adapt readers/writers, the kvtml-1 writer needs care, it will not work correctly. Rewrite of the article class with enums. Port parley. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=716403 --- keduvocdocument/CMakeLists.txt | 3 +- keduvocdocument/keduvocconjugation.cpp | 207 ++---------- keduvocdocument/keduvocconjugation.h | 51 ++- keduvocdocument/keduvocdeclination.cpp | 12 +- keduvocdocument/keduvocdeclination.h | 5 +- keduvocdocument/keduvocexpression.cpp | 2 +- keduvocdocument/keduvocidentifier.cpp | 6 +- keduvocdocument/keduvocidentifier.h | 8 +- keduvocdocument/keduvockvtml2reader.cpp | 362 +++++++------------- keduvocdocument/keduvockvtml2reader.h | 26 +- keduvocdocument/keduvockvtml2writer.cpp | 133 +++++--- keduvocdocument/keduvockvtml2writer.h | 4 +- keduvocdocument/keduvockvtmlreader.cpp | 157 ++++++++- keduvocdocument/keduvockvtmlreader.h | 3 +- keduvocdocument/keduvockvtmlwriter.cpp | 369 +++++++++++++++------ keduvocdocument/keduvockvtmlwriter.h | 33 +- keduvocdocument/keduvocpersonalpronoun.cpp | 110 ++++++ keduvocdocument/keduvocpersonalpronoun.h | 59 ++++ keduvocdocument/keduvoctranslation.cpp | 2 +- keduvocdocument/kvtml2defs.h | 13 +- 20 files changed, 912 insertions(+), 653 deletions(-) create mode 100644 keduvocdocument/keduvocpersonalpronoun.cpp create mode 100644 keduvocdocument/keduvocpersonalpronoun.h diff --git a/keduvocdocument/CMakeLists.txt b/keduvocdocument/CMakeLists.txt index b9474aa..ca12698 100644 --- a/keduvocdocument/CMakeLists.txt +++ b/keduvocdocument/CMakeLists.txt @@ -13,7 +13,8 @@ set(keduvocdocument_LIB_SRCS keduvocgrade.cpp keduvocgrammar.cpp keduvocconjugation.cpp -# keduvocdeclination.cpp + keduvocpersonalpronoun.cpp + keduvocdeclination.cpp keduvocwordtype.cpp keduvockvtmlreader.cpp keduvockvtml2reader.cpp diff --git a/keduvocdocument/keduvocconjugation.cpp b/keduvocdocument/keduvocconjugation.cpp index 975e903..786390a 100644 --- a/keduvocdocument/keduvocconjugation.cpp +++ b/keduvocdocument/keduvocconjugation.cpp @@ -31,28 +31,18 @@ class KEduVocConjugation::Private public: Private(); -// bool operator==(const conjug_t& other) const; - - bool p3common; - bool s3common; - QString pers1_sing; - QString pers2_sing; - QString pers3_m_sing; - QString pers3_f_sing; - QString pers3_n_sing; - QString pers1_plur; - QString pers2_plur; - QString pers3_m_plur; - QString pers3_f_plur; - QString pers3_n_plur; - + bool m_thirdCommonSingular; + bool m_thirdCommonDual; + bool m_thirdCommonPlural; + QMap m_conjugations; }; KEduVocConjugation::Private::Private() { - p3common = false; - s3common = false; + m_thirdCommonSingular = false; + m_thirdCommonDual = false; + m_thirdCommonPlural = false; } KEduVocConjugation::KEduVocConjugation() @@ -60,9 +50,13 @@ KEduVocConjugation::KEduVocConjugation() {} -KEduVocConjugation::KEduVocConjugation( const KEduVocConjugation& rhs ) - : d( new Private( *rhs.d ) ) +KEduVocConjugation::KEduVocConjugation( const KEduVocConjugation& other ) + : d( new Private ) { + d->m_thirdCommonSingular = other.d->m_thirdCommonSingular; + d->m_thirdCommonDual = other.d->m_thirdCommonDual; + d->m_thirdCommonPlural = other.d->m_thirdCommonPlural; + d->m_conjugations = other.d->m_conjugations; } @@ -74,177 +68,40 @@ KEduVocConjugation::~KEduVocConjugation() KEduVocConjugation& KEduVocConjugation::operator = ( const KEduVocConjugation& other ) { - d->s3common = other.d->s3common; - d->p3common = other.d->p3common; - d->pers1_sing = other.d->pers1_sing; - d->pers2_sing = other.d->pers2_sing; - d->pers3_m_sing = other.d->pers3_m_sing; - d->pers3_f_sing = other.d->pers3_f_sing; - d->pers3_n_sing = other.d->pers3_n_sing; - d->pers1_plur = other.d->pers1_plur; - d->pers2_plur = other.d->pers2_plur; - d->pers3_m_plur = other.d->pers3_m_plur; - d->pers3_f_plur = other.d->pers3_f_plur; - d->pers3_n_plur = other.d->pers3_n_plur; + d->m_thirdCommonSingular = other.d->m_thirdCommonSingular; + d->m_thirdCommonDual = other.d->m_thirdCommonDual; + d->m_thirdCommonPlural = other.d->m_thirdCommonPlural; + d->m_conjugations = other.d->m_conjugations; return *this; } bool KEduVocConjugation::operator ==(const KEduVocConjugation& other) const { - return d->s3common == other.d->s3common && - d->p3common == other.d->p3common && - d->pers1_sing == other.d->pers1_sing && - d->pers2_sing == other.d->pers2_sing && - d->pers3_m_sing == other.d->pers3_m_sing && - d->pers3_f_sing == other.d->pers3_f_sing && - d->pers3_n_sing == other.d->pers3_n_sing && - d->pers1_plur == other.d->pers1_plur && - d->pers2_plur == other.d->pers2_plur && - d->pers3_m_plur == other.d->pers3_m_plur && - d->pers3_f_plur == other.d->pers3_f_plur && - d->pers3_n_plur == other.d->pers3_n_plur; -} - -bool KEduVocConjugation::pers3SingularCommon() const -{ - return d->s3common; -} - - -bool KEduVocConjugation::pers3PluralCommon() const -{ - return d->p3common; -} - - -QString KEduVocConjugation::pers1Singular() const -{ - return d->pers1_sing; -} - - -QString KEduVocConjugation::pers2Singular() const -{ - return d->pers2_sing; -} - - -QString KEduVocConjugation::pers3FemaleSingular() const -{ - return d->pers3_f_sing; -} - - -QString KEduVocConjugation::pers3MaleSingular() const -{ - return d->pers3_m_sing; -} - - -QString KEduVocConjugation::pers3NaturalSingular() const -{ - return d->pers3_n_sing; -} - - -QString KEduVocConjugation::pers1Plural() const -{ - return d->pers1_plur; -} - - -QString KEduVocConjugation::pers2Plural() const -{ - return d->pers2_plur; -} - - -QString KEduVocConjugation::pers3FemalePlural() const -{ - return d->pers3_f_plur; -} - - -QString KEduVocConjugation::pers3MalePlural() const -{ - return d->pers3_m_plur; -} - - -QString KEduVocConjugation::pers3NaturalPlural() const -{ - return d->pers3_n_plur; -} - - -void KEduVocConjugation::setPers3PluralCommon( bool f ) -{ - d->p3common = f; -} - - -void KEduVocConjugation::setPers3SingularCommon( bool f ) -{ - d->s3common = f; -} - - -void KEduVocConjugation::setPers1Singular( const QString &str ) -{ - d->pers1_sing = str; -} - - -void KEduVocConjugation::setPers2Singular( const QString &str ) -{ - d->pers2_sing = str; + return d->m_conjugations == other.d->m_conjugations && + d->m_thirdCommonSingular == other.d->m_thirdCommonSingular && + d->m_thirdCommonDual == other.d->m_thirdCommonDual && + d->m_thirdCommonPlural == other.d->m_thirdCommonPlural; + ; } -void KEduVocConjugation::setPers3FemaleSingular( const QString &str ) +QString KEduVocConjugation::conjugation(ConjugationPerson person, ConjugationNumber number) const { - d->pers3_f_sing = str; + int index = indexOf(person, number); + if ( d->m_conjugations.contains(index) ) { + return d->m_conjugations.value(index); + } + return QString(); } - -void KEduVocConjugation::setPers3MaleSingular( const QString &str ) -{ - d->pers3_m_sing = str; -} - - -void KEduVocConjugation::setPers3NaturalSingular( const QString &str ) -{ - d->pers3_n_sing = str; -} - - -void KEduVocConjugation::setPers1Plural( const QString &str ) -{ - d->pers1_plur = str; -} - - -void KEduVocConjugation::setPers2Plural( const QString &str ) -{ - d->pers2_plur = str; -} - - -void KEduVocConjugation::setPers3FemalePlural( const QString &str ) -{ - d->pers3_f_plur = str; -} - - -void KEduVocConjugation::setPers3MalePlural( const QString &str ) +void KEduVocConjugation::setConjugation(const QString & conjugation, ConjugationPerson person, ConjugationNumber number) { - d->pers3_m_plur = str; + d->m_conjugations[indexOf(person, number)] = conjugation; } -void KEduVocConjugation::setPers3NaturalPlural( const QString &str ) +int KEduVocConjugation::indexOf(ConjugationPerson person, ConjugationNumber number) const { - d->pers3_n_plur = str; + return person + PersonMAX * number; } diff --git a/keduvocdocument/keduvocconjugation.h b/keduvocdocument/keduvocconjugation.h index f420c5b..4d87de9 100644 --- a/keduvocdocument/keduvocconjugation.h +++ b/keduvocdocument/keduvocconjugation.h @@ -36,6 +36,24 @@ class KEDUVOCDOCUMENT_EXPORT KEduVocConjugation { public: + enum ConjugationNumber { + Singular, + Dual, + Plural, + NumberMAX + }; + + // store third person neuter/common in the same sttr + enum ConjugationPerson { + First, + Second, + ThirdMale, + ThirdFemale, + ThirdNeuterCommon, + PersonMAX + }; + + /** * The constructor */ @@ -45,40 +63,17 @@ public: ~KEduVocConjugation(); - QString pers1Singular( ) const; - QString pers2Singular( ) const; - bool pers3SingularCommon( ) const; - QString pers3FemaleSingular( ) const; - QString pers3MaleSingular( ) const; - QString pers3NaturalSingular( ) const; - - QString pers1Plural( ) const; - QString pers2Plural( ) const; - bool pers3PluralCommon( ) const; - QString pers3FemalePlural( ) const; - QString pers3MalePlural( ) const; - QString pers3NaturalPlural( ) const; - - void setPers1Singular( const QString &str ); - void setPers2Singular( const QString &str ); - void setPers3SingularCommon( bool f ); - void setPers3FemaleSingular( const QString &str ); - void setPers3MaleSingular( const QString &str ); - void setPers3NaturalSingular( const QString &str ); - - void setPers1Plural( const QString &str ); - void setPers2Plural( const QString &str ); - void setPers3PluralCommon( bool f ); - void setPers3FemalePlural( const QString &str ); - void setPers3MalePlural( const QString &str ); - void setPers3NaturalPlural( const QString &str ); - KEduVocConjugation& operator = ( const KEduVocConjugation& a ); bool operator == ( const KEduVocConjugation& a ) const; + QString conjugation(ConjugationPerson person, ConjugationNumber number) const; + void setConjugation(const QString& conjugation, ConjugationPerson person, ConjugationNumber number); + private: class Private; Private* const d; + + int indexOf(ConjugationPerson person, ConjugationNumber number) const; }; diff --git a/keduvocdocument/keduvocdeclination.cpp b/keduvocdocument/keduvocdeclination.cpp index c9c924c..c5df8a6 100644 --- a/keduvocdocument/keduvocdeclination.cpp +++ b/keduvocdocument/keduvocdeclination.cpp @@ -22,7 +22,7 @@ ***************************************************************************/ #include "keduvocdeclination.h" -#include +#include class KEduVocDeclination::Private { @@ -54,8 +54,8 @@ KEduVocDeclination::~KEduVocDeclination() QString KEduVocDeclination::declination(DeclinationNumber number, DeclinationCase decCase) { - if ( m_declinations.contains(indexOf(number, decCase)) ) { - return m_declinations.value(indexOf(number, decCase)); + if ( d->m_declinations.contains(indexOf(number, decCase)) ) { + return d->m_declinations.value(indexOf(number, decCase)); } else { return QString(); } @@ -63,17 +63,17 @@ QString KEduVocDeclination::declination(DeclinationNumber number, DeclinationCas void KEduVocDeclination::setDeclination(const QString & declination, DeclinationNumber number, DeclinationCase decCase) { - m_declinations[indexOf(number, decCase)] = declination; + d->m_declinations[indexOf(number, decCase)] = declination; } int KEduVocDeclination::indexOf(DeclinationNumber number, DeclinationCase decCase) { - return number * 10 + decCase; + return number * DeclinationCaseMAX + decCase; } bool KEduVocDeclination::isEmpty() { - return m_declinations.isEmpty(); + return d->m_declinations.isEmpty(); } diff --git a/keduvocdocument/keduvocdeclination.h b/keduvocdocument/keduvocdeclination.h index 0974d91..dfd5ef0 100644 --- a/keduvocdocument/keduvocdeclination.h +++ b/keduvocdocument/keduvocdeclination.h @@ -23,6 +23,8 @@ #ifndef KEDUVOCDECLINATION_H #define KEDUVOCDECLINATION_H +#include + /** A declination contains all forms that a NOUN possibly can have. @@ -50,7 +52,8 @@ public: Accusative, Ablative, Locative, - Vocative + Vocative, + DeclinationCaseMAX }; diff --git a/keduvocdocument/keduvocexpression.cpp b/keduvocdocument/keduvocexpression.cpp index 46bfac3..b18e372 100644 --- a/keduvocdocument/keduvocexpression.cpp +++ b/keduvocdocument/keduvocexpression.cpp @@ -185,7 +185,7 @@ bool KEduVocExpression::operator== ( const KEduVocExpression &expression ) const return ( *d == *expression.d ); } -KEduVocTranslation & KEduVocExpression::translation( int index ) const +KEduVocTranslation& KEduVocExpression::translation( int index ) const { return d->m_translations[index]; } diff --git a/keduvocdocument/keduvocidentifier.cpp b/keduvocdocument/keduvocidentifier.cpp index cb05910..7339b52 100644 --- a/keduvocdocument/keduvocidentifier.cpp +++ b/keduvocdocument/keduvocidentifier.cpp @@ -42,7 +42,7 @@ public: QString m_type; /** I, you, he, she, it... */ - KEduVocConjugation m_personalPronouns; + KEduVocPersonalPronoun m_personalPronouns; /** the for english ;) der, die, das ... in german */ @@ -125,12 +125,12 @@ KEduVocArticle KEduVocIdentifier::article() const return d->m_articles; } -KEduVocConjugation KEduVocIdentifier::personalPronouns() const +KEduVocPersonalPronoun KEduVocIdentifier::personalPronouns() const { return d->m_personalPronouns; } -void KEduVocIdentifier::setPersonalPronouns( const KEduVocConjugation & pronouns ) +void KEduVocIdentifier::setPersonalPronouns( const KEduVocPersonalPronoun & pronouns ) { d->m_personalPronouns = pronouns; } diff --git a/keduvocdocument/keduvocidentifier.h b/keduvocdocument/keduvocidentifier.h index c3bdcff..cbec816 100644 --- a/keduvocdocument/keduvocidentifier.h +++ b/keduvocdocument/keduvocidentifier.h @@ -25,7 +25,7 @@ #include "libkeduvocdocument_export.h" -#include "keduvocconjugation.h" +#include "keduvocpersonalpronoun.h" #include "keduvocgrammar.h" #include @@ -103,15 +103,15 @@ public: /** * Get the personal pronouns for this identifier - * @returns a KEduVocConjugation containing the personal pronouns + * @returns a KEduVocPersonalPronoun containing the personal pronouns */ - KEduVocConjugation personalPronouns() const; + KEduVocPersonalPronoun personalPronouns() const; /** * Sets personal pronouns * @param pronouns a KEduVocConjugation containing the personal pronouns */ - void setPersonalPronouns( const KEduVocConjugation &pronouns ); + void setPersonalPronouns( const KEduVocPersonalPronoun &pronouns ); private: class Private; diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index daf0cbd..2b8638b 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -245,9 +245,9 @@ bool KEduVocKvtml2Reader::readIdentifier( QDomElement &identifierElement ) currentElement = identifierElement.firstChildElement( KVTML_PERSONALPRONOUNS ); if ( !currentElement.isNull() ) { - KEduVocConjugation personalPronouns; - readConjugation( currentElement, personalPronouns ); - m_doc->identifier(id).setPersonalPronouns( personalPronouns ); + KEduVocPersonalPronoun personalPronoun; + readPersonalPronoun( currentElement, personalPronoun ); + m_doc->identifier(id).setPersonalPronouns( personalPronoun ); } return result; } @@ -540,119 +540,6 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi } -bool KEduVocKvtml2Reader::readConjugation( QDomElement &conjugElement, KEduVocConjugation &conjugation ) -/* - - Futurepastperfekt:) - - - - - - - - - - - - - - - - - -*/ -{ - bool p3_common; - bool s3_common; - QString singfirst; - QString singsecond; - QString singthirdmale; - QString singthirdfemale; - QString singthirdneutral; - QString plurfirst; - QString plursecond; - QString plurthirdmale; - QString plurthirdfemale; - QString plurthirdneutral; - - QDomElement currentGroup = conjugElement.firstChildElement( KVTML_SINGULAR ); - if ( !currentGroup.isNull() ) - { - QDomElement currentElement = currentGroup.firstChildElement( KVTML_1STPERSON ); - singfirst = currentElement.text(); - - currentElement = currentGroup.firstChildElement( KVTML_2NDPERSON ); - singsecond = currentElement.text(); - - currentGroup = currentGroup.firstChildElement( KVTML_3RDPERSON ); - if ( !currentGroup.isNull() ) { - currentElement = currentGroup.firstChildElement( KVTML_COMMON ); - if ( !currentElement.isNull() ) { - s3_common = true; - singthirdmale = currentElement.text(); - singthirdfemale = singthirdmale; - singthirdneutral = singthirdmale; - } else { - s3_common = false; - currentElement = currentGroup.firstChildElement( KVTML_MALE ); - singthirdmale = currentElement.text(); - - currentElement = currentGroup.firstChildElement( KVTML_FEMALE ); - singthirdfemale = currentElement.text(); - currentElement = currentGroup.firstChildElement( KVTML_NEUTRAL ); - singthirdneutral = currentElement.text(); - } - - } - } - - currentGroup = conjugElement.firstChildElement( KVTML_PLURAL ); - if ( !currentGroup.isNull() ) - { - QDomElement currentElement = currentGroup.firstChildElement( KVTML_1STPERSON ); - plurfirst = currentElement.text(); - - currentElement = currentGroup.firstChildElement( KVTML_2NDPERSON ); - plursecond = currentElement.text(); - - currentGroup = currentGroup.firstChildElement( KVTML_3RDPERSON ); - if ( !currentGroup.isNull() ) { - currentElement = currentGroup.firstChildElement( KVTML_COMMON ); - if ( !currentElement.isNull() ) { - p3_common = true; - plurthirdmale = currentElement.text(); - plurthirdfemale = singthirdmale; - plurthirdneutral = singthirdmale; - } else { - p3_common = false; - currentElement = currentGroup.firstChildElement( KVTML_MALE ); - plurthirdmale = currentElement.text(); - currentElement = currentGroup.firstChildElement( KVTML_FEMALE ); - plurthirdfemale = currentElement.text(); - currentElement = currentGroup.firstChildElement( KVTML_NEUTRAL ); - plurthirdneutral = currentElement.text(); - } - - } - } - - conjugation.setPers3SingularCommon( s3_common ); - conjugation.setPers3PluralCommon( p3_common ); - conjugation.setPers1Singular( singfirst ); - conjugation.setPers2Singular( singsecond ); - conjugation.setPers3FemaleSingular( singthirdfemale ); - conjugation.setPers3MaleSingular( singthirdmale ); - conjugation.setPers3NaturalSingular( singthirdneutral ); - conjugation.setPers1Plural( plurfirst ); - conjugation.setPers2Plural( plursecond ); - conjugation.setPers3FemalePlural( plurthirdfemale ); - conjugation.setPers3MalePlural( plurthirdmale ); - conjugation.setPers3NaturalPlural( plurthirdneutral ); - - return true; -} - bool KEduVocKvtml2Reader::readTypes( QDomElement &typesElement ) { QString mainTypeName; @@ -845,124 +732,129 @@ bool KEduVocKvtml2Reader::readGrade( QDomElement &gradeElement, KEduVocExpressio } -//**** old code from kvtmlreader -// grade = KV_NORM_GRADE; -// rev_grade = KV_NORM_GRADE; -// attribute = domElementExpressionChild.attributeNode(KV_GRADE); -// if (!attribute.isNull()) -// { -// QString s = attribute.value(); -// if ((pos = s.indexOf(';')) >= 1) -// { -// grade = s.left(pos).toInt(); -// rev_grade = s.mid(pos + 1, s.length()).toInt(); -// } -// else -// grade = s.toInt(); -// } - -// count = 0; -// rev_count = 0; -// attribute = domElementExpressionChild.attributeNode(KV_COUNT); -// if (!attribute.isNull()) -// { -// QString s = attribute.value(); -// if ((pos = s.indexOf(';')) >= 1) -// { -// count = s.left(pos).toInt(); -// rev_count = s.mid(pos + 1, s.length()).toInt(); -// } -// else -// count = s.toInt(); -// } - -// bcount = 0; -// rev_bcount = 0; -// attribute = domElementExpressionChild.attributeNode(KV_BAD); -// if (!attribute.isNull()) -// { -// QString s = attribute.value(); -// if ((pos = s.indexOf(';')) >= 1) -// { -// bcount = s.left(pos).toInt(); -// rev_bcount = s.mid(pos + 1, s.length()).toInt(); -// } -// else -// bcount = s.toInt(); -// } - -// date.setTime_t(0); -// rev_date.setTime_t(0); -// attribute = domElementExpressionChild.attributeNode(KV_DATE); -// if (!attribute.isNull()) -// { -// QString s = attribute.value(); -// if ((pos = s.indexOf(';')) >= 1) -// { -// date.setTime_t(s.left(pos).toInt()); -// rev_date.setTime_t(s.mid(pos + 1, s.length()).toInt()); -// } -// else -// date.setTime_t(s.toInt()); -// } - -// attribute = domElementExpressionChild.attributeNode(KV_DATE2); -// if (!attribute.isNull()) -// { -// //this format is deprecated and ignored. -// } - -// faux_ami_f = ""; -// attribute = domElementExpressionChild.attributeNode(KV_FAUX_AMI_F); -// if (!attribute.isNull()) -// faux_ami_f = attribute.value(); - -// faux_ami_t = ""; -// attribute = domElementExpressionChild.attributeNode(KV_FAUX_AMI_T); -// if (!attribute.isNull()) -// faux_ami_t = attribute.value(); - -// usage = ""; -// attribute = domElementExpressionChild.attributeNode(KV_USAGE); -// if (!attribute.isNull()) -// { -// usage = attribute.value(); -// if (usage.length() != 0 && usage.left(1) == UL_USER_USAGE) -// { -// int num = qMin(usage.mid (1, 40).toInt(), 1000); // paranioa check -// if (num > m_doc->usageDescriptions().count()) -// { -// // description missing ? -// QStringList sl = m_doc->usageDescriptions(); -// QString s; -// for (int i = m_doc->usageDescriptions().count(); i < num; i++) -// { -// s.setNum(i + 1); -// s.prepend("#"); // invent descr according to number -// sl.append(s); -// } -// m_doc->setUsageDescriptions(sl); -// } -// } -// } - -// if (type.length() != 0 && type.left(1) == QM_USER_TYPE) -// { -// int num = qMin(type.mid (1, 40).toInt(), 1000); // paranoia check -// if (num > m_doc->typeDescriptions().count()) -// { -// // description missing ? -// QString s; -// QStringList sl = m_doc->typeDescriptions(); -// for (int i = m_doc->typeDescriptions().count(); i < num; i++) -// { -// s.setNum(i + 1); -// s.prepend("#"); // invent descr according to number -// sl.append(s); -// } -// m_doc->setTypeDescriptions(sl); -// } -// } -// } + +bool KEduVocKvtml2Reader::readConjugation( QDomElement &conjugElement, KEduVocConjugation &conjugation ) +/* + + Futurepastperfekt:) + + + + + + + + + + + + + + + + + +*/ +{ + QDomElement personElement = conjugElement.firstChildElement( KVTML_SINGULAR ); + if ( !personElement.isNull() ) + { + readConjugationPerson( personElement, conjugation, KEduVocConjugation::Singular ); + } + + personElement = conjugElement.firstChildElement( KVTML_DUAL ); + if ( !personElement.isNull() ) + { + readConjugationPerson( personElement, conjugation, KEduVocConjugation::Dual ); + } + + personElement = conjugElement.firstChildElement( KVTML_PLURAL ); + if ( !personElement.isNull() ) + { + readConjugationPerson( personElement, conjugation, KEduVocConjugation::Plural ); + } + + return true; +} + + +bool KEduVocKvtml2Reader::readConjugationPerson(QDomElement & personElement, KEduVocConjugation & conjugation, KEduVocConjugation::ConjugationNumber number) +{ + QDomElement currentElement = personElement.firstChildElement( KVTML_1STPERSON ); + conjugation.setConjugation( currentElement.text(), + KEduVocConjugation::First, number ); + + currentElement = personElement.firstChildElement( KVTML_2NDPERSON ); + conjugation.setConjugation( currentElement.text(), + KEduVocConjugation::Second, number ); + + currentElement = personElement.firstChildElement( KVTML_THIRD_MALE ); + conjugation.setConjugation( currentElement.text(), + KEduVocConjugation::ThirdMale, number ); + + currentElement = personElement.firstChildElement( KVTML_THIRD_FEMALE ); + conjugation.setConjugation( currentElement.text(), + KEduVocConjugation::ThirdFemale, number ); + + currentElement = personElement.firstChildElement( KVTML_THIRD_NEUTER_COMMON ); + conjugation.setConjugation( currentElement.text(), + KEduVocConjugation::ThirdNeuterCommon, number ); +} + + +bool KEduVocKvtml2Reader::readPersonalPronoun(QDomElement & pronounElement, KEduVocPersonalPronoun & pronoun) +{ + QDomElement personElement = pronounElement.firstChildElement( KVTML_SINGULAR ); + if ( !personElement.isNull() ) { + readPersonalPronounChild( personElement, pronoun, KEduVocConjugation::Singular ); + } + + personElement = pronounElement.firstChildElement( KVTML_DUAL ); + if ( !personElement.isNull() ) { + readPersonalPronounChild( personElement, pronoun, KEduVocConjugation::Dual ); + } + + personElement = pronounElement.firstChildElement( KVTML_PLURAL ); + if ( !personElement.isNull() ) { + readPersonalPronounChild( personElement, pronoun, KEduVocConjugation::Plural ); + } +} + + +bool KEduVocKvtml2Reader::readPersonalPronounChild(QDomElement & personElement, KEduVocPersonalPronoun & pronoun, KEduVocConjugation::ConjugationNumber number) +{ + QDomElement currentElement = personElement.firstChildElement( KVTML_1STPERSON ); + pronoun.setPersonalPronoun( currentElement.text(), + KEduVocConjugation::First, number ); + + currentElement = personElement.firstChildElement( KVTML_2NDPERSON ); + pronoun.setPersonalPronoun( currentElement.text(), + KEduVocConjugation::Second, number ); + + currentElement = personElement.firstChildElement( KVTML_THIRD_MALE ); + pronoun.setPersonalPronoun( currentElement.text(), + KEduVocConjugation::ThirdMale, number ); + + currentElement = personElement.firstChildElement( KVTML_THIRD_FEMALE ); + pronoun.setPersonalPronoun( currentElement.text(), + KEduVocConjugation::ThirdFemale, number ); + + currentElement = personElement.firstChildElement( KVTML_THIRD_NEUTER_COMMON ); + pronoun.setPersonalPronoun( currentElement.text(), + KEduVocConjugation::ThirdNeuterCommon, number ); + + if ( !personElement.firstChildElement(KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT).isNull() ){ + pronoun.setMaleFemaleDifferent(true); + if ( !personElement.firstChildElement(KVTML_THIRD_PERSON_NEUTER_EXISTS).isNull() ){ + pronoun.setNeuterExists(true); + } else { + pronoun.setNeuterExists(false); + } + } else { + pronoun.setMaleFemaleDifferent(false); + pronoun.setNeuterExists(false); + } +} + #include "keduvockvtml2reader.moc" diff --git a/keduvocdocument/keduvockvtml2reader.h b/keduvocdocument/keduvockvtml2reader.h index 1848092..6feedeb 100644 --- a/keduvocdocument/keduvockvtml2reader.h +++ b/keduvocdocument/keduvockvtml2reader.h @@ -20,6 +20,7 @@ #include #include "keduvocexpression.h" +#include "keduvocpersonalpronoun.h" #include "keduvocgrammar.h" #include "keduvocmultiplechoice.h" @@ -44,6 +45,15 @@ public: */ bool readDoc( KEduVocDocument *doc ); + /** get the errormessage string + * @returns the errormessage string + */ + QString errorMessage() const + { + return m_errorMessage; + } + +private: /** read information entries * @param informationElement QDomElement information */ @@ -63,11 +73,17 @@ public: */ bool readArticle( QDomElement &articleElement, int identifierNum ); + bool readPersonalPronoun( QDomElement &conjugElement, KEduVocPersonalPronoun &pronoun ); + + bool readPersonalPronounChild(QDomElement & personElement, KEduVocPersonalPronoun & pronoun, KEduVocConjugation::ConjugationNumber number); + + /** read in a conjugation * @param conjugElement QDomElement for the conjugation group * @param curr_conjug conjugation object to populate */ bool readConjugation( QDomElement &conjugElement, KEduVocConjugation &conjugation ); + bool readConjugationPerson( QDomElement &personElement, KEduVocConjugation &conjugation, KEduVocConjugation::ConjugationNumber number ); /** read the types * @param typesElement QDomElement for the types group @@ -118,16 +134,6 @@ public: */ bool readLesson( QDomElement &lessonElement ); - /** get the errormessage string - * @returns the errormessage string - */ - QString errorMessage() const - { - return m_errorMessage; - } - -private: - /** pre-opened QIODevice to read from */ QIODevice *m_inputFile; diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 56b59c2..7a80b1c 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -161,7 +161,7 @@ bool KEduVocKvtml2Writer::writeIdentifiers( QDomElement &identifiersElement ) // record personalpronouns QDomElement personalpronouns = m_domDoc.createElement( KVTML_PERSONALPRONOUNS ); - writeConjugation( personalpronouns, m_doc->identifier(i).personalPronouns(), QString() ); + writePersonalPronoun( personalpronouns, m_doc->identifier(i).personalPronouns() ); if ( personalpronouns.hasChildNodes() ) { identifier.appendChild( personalpronouns ); } @@ -538,60 +538,41 @@ bool KEduVocKvtml2Writer::writeConjugation( QDomElement &conjugationElement, // write the tense tag conjugationElement.appendChild( newTextElement(KVTML_TENSE, tense) ); - // first singular conjugations - QString first = conjugation.pers1Singular(); - QString second = conjugation.pers2Singular(); - bool third_common = conjugation.pers3SingularCommon(); - QString third_male = conjugation.pers3MaleSingular(); - QString third_female = conjugation.pers3FemaleSingular(); - QString third_neutral = conjugation.pers3NaturalSingular(); - - if ( !first.isEmpty() || !second.isEmpty() || !third_female.isEmpty() || - !third_male.isEmpty() || !third_neutral.isEmpty() ) { - QDomElement singular = m_domDoc.createElement( KVTML_SINGULAR ); - - singular.appendChild( newTextElement( KVTML_1STPERSON, first ) ); - singular.appendChild( newTextElement( KVTML_2NDPERSON, second ) ); - - QDomElement thirdPerson = m_domDoc.createElement( KVTML_3RDPERSON ); - singular.appendChild( thirdPerson ); - - if ( third_common ) { - thirdPerson.appendChild( newTextElement( KVTML_COMMON, third_female ) ); - } else { - thirdPerson.appendChild( newTextElement( KVTML_MALE, third_male ) ); - thirdPerson.appendChild( newTextElement( KVTML_FEMALE, third_female ) ); - thirdPerson.appendChild( newTextElement( KVTML_NEUTRAL, third_neutral ) ); - } - conjugationElement.appendChild( singular ); - } - - // now for plurals - first = conjugation.pers1Plural(); - second = conjugation.pers2Plural(); - third_common = conjugation.pers3PluralCommon(); - third_male = conjugation.pers3MalePlural(); - third_female = conjugation.pers3FemalePlural(); - third_neutral = conjugation.pers3NaturalPlural(); - - if ( !first.isEmpty() || !second.isEmpty() || !third_female.isEmpty() || - !third_male.isEmpty() || !third_neutral.isEmpty() ) { - QDomElement plural = m_domDoc.createElement( KVTML_PLURAL ); - - plural.appendChild( newTextElement( KVTML_1STPERSON, first ) ); - plural.appendChild( newTextElement( KVTML_2NDPERSON, second ) ); + for ( KEduVocConjugation::ConjugationNumber num = KEduVocConjugation::Singular; num < KEduVocConjugation::NumberMAX; num = KEduVocConjugation::ConjugationNumber(num +1) ) { + QString first = conjugation.conjugation( + KEduVocConjugation::First, KEduVocConjugation::Singular ); + QString second = conjugation.conjugation( + KEduVocConjugation::Second, KEduVocConjugation::Singular ); + QString third_male = conjugation.conjugation( + KEduVocConjugation::ThirdMale, KEduVocConjugation::Singular ); + QString third_female = conjugation.conjugation( + KEduVocConjugation::ThirdFemale, KEduVocConjugation::Singular ); + QString third_neutral = conjugation.conjugation( + KEduVocConjugation::ThirdNeuterCommon, KEduVocConjugation::Singular ); + + if ( !first.isEmpty() || !second.isEmpty() || !third_female.isEmpty() || + !third_male.isEmpty() || !third_neutral.isEmpty() ) { + QDomElement number; + switch (num) { + case KEduVocConjugation::Singular: + number = m_domDoc.createElement( KVTML_SINGULAR ); + break; + case KEduVocConjugation::Dual: + number = m_domDoc.createElement( KVTML_DUAL ); + break; + case KEduVocConjugation::Plural: + number = m_domDoc.createElement( KVTML_PLURAL ); + break; + } - QDomElement thirdPerson = m_domDoc.createElement( KVTML_3RDPERSON ); - plural.appendChild( thirdPerson ); + number.appendChild( newTextElement( KVTML_1STPERSON, first ) ); + number.appendChild( newTextElement( KVTML_2NDPERSON, second ) ); + number.appendChild( newTextElement( KVTML_THIRD_MALE, third_male ) ); + number.appendChild( newTextElement( KVTML_THIRD_FEMALE, third_female ) ); + number.appendChild( newTextElement( KVTML_THIRD_NEUTER_COMMON, third_neutral ) ); - if ( third_common ) { - thirdPerson.appendChild( newTextElement( KVTML_COMMON, third_female ) ); - } else { - thirdPerson.appendChild( newTextElement( KVTML_MALE, third_male ) ); - thirdPerson.appendChild( newTextElement( KVTML_FEMALE, third_female ) ); - thirdPerson.appendChild( newTextElement( KVTML_NEUTRAL, third_neutral ) ); + conjugationElement.appendChild( number ); } - conjugationElement.appendChild( plural ); } return true; @@ -604,3 +585,51 @@ QDomElement KEduVocKvtml2Writer::newTextElement( const QString &elementName, con retval.appendChild( textNode ); return retval; } + +bool KEduVocKvtml2Writer::writePersonalPronoun(QDomElement & pronounElement, const KEduVocPersonalPronoun & pronoun) +{ + // general pronoun properties + if ( pronoun.maleFemaleDifferent() ) { + pronounElement.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT ) ); + } + if ( pronoun.neuterExists() ) { + pronounElement.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_NEUTER_EXISTS ) ); + } + + for ( KEduVocConjugation::ConjugationNumber num = KEduVocConjugation::Singular; num < KEduVocConjugation::NumberMAX; num = KEduVocConjugation::ConjugationNumber(num +1) ) { + QString first = pronoun.personalPronoun( + KEduVocConjugation::First, KEduVocConjugation::Singular ); + QString second = pronoun.personalPronoun( + KEduVocConjugation::Second, KEduVocConjugation::Singular ); + QString third_male = pronoun.personalPronoun( + KEduVocConjugation::ThirdMale, KEduVocConjugation::Singular ); + QString third_female = pronoun.personalPronoun( + KEduVocConjugation::ThirdFemale, KEduVocConjugation::Singular ); + QString third_neutral = pronoun.personalPronoun( + KEduVocConjugation::ThirdNeuterCommon, KEduVocConjugation::Singular ); + + if ( !first.isEmpty() || !second.isEmpty() || !third_female.isEmpty() || + !third_male.isEmpty() || !third_neutral.isEmpty() ) { + QDomElement number; + switch (num) { + case KEduVocConjugation::Singular: + number = m_domDoc.createElement( KVTML_SINGULAR ); + break; + case KEduVocConjugation::Dual: + number = m_domDoc.createElement( KVTML_DUAL ); + break; + case KEduVocConjugation::Plural: + number = m_domDoc.createElement( KVTML_PLURAL ); + break; + } + + number.appendChild( newTextElement( KVTML_1STPERSON, first ) ); + number.appendChild( newTextElement( KVTML_2NDPERSON, second ) ); + number.appendChild( newTextElement( KVTML_THIRD_MALE, third_male ) ); + number.appendChild( newTextElement( KVTML_THIRD_FEMALE, third_female ) ); + number.appendChild( newTextElement( KVTML_THIRD_NEUTER_COMMON, third_neutral ) ); + + pronounElement.appendChild( number ); + } + } +} diff --git a/keduvocdocument/keduvockvtml2writer.h b/keduvocdocument/keduvockvtml2writer.h index 07b1b0b..51efe0e 100644 --- a/keduvocdocument/keduvockvtml2writer.h +++ b/keduvocdocument/keduvockvtml2writer.h @@ -24,6 +24,7 @@ #include "keduvocgrammar.h" #include "keduvocmultiplechoice.h" #include "keduvoctranslation.h" +#include "keduvocpersonalpronoun.h" class KEduVocDocument; @@ -61,8 +62,9 @@ public: * @param type conjugation type */ bool writeConjugation( QDomElement &conjugationElement, const KEduVocConjugation &conjugation, - const QString &type ); + const QString &tense ); + bool writePersonalPronoun( QDomElement &pronounElement, const KEduVocPersonalPronoun &pronoun); /** write types * @param typesElement QDomElement types to write to */ diff --git a/keduvocdocument/keduvockvtmlreader.cpp b/keduvocdocument/keduvockvtmlreader.cpp index ed9a30c..45bc80e 100644 --- a/keduvocdocument/keduvockvtmlreader.cpp +++ b/keduvocdocument/keduvockvtmlreader.cpp @@ -144,8 +144,8 @@ bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent ) return false; } - KEduVocConjugation pronouns; - if (! readConjugation( domElementConjugChild, pronouns ) ) { + KEduVocPersonalPronoun pronouns; + if (! readPersonalPronouns( domElementConjugChild, pronouns ) ) { return false; } m_doc->identifier(count).setPersonalPronouns( pronouns ); @@ -471,22 +471,151 @@ bool KEduVocKvtmlReader::readConjugation( QDomElement &domElementParent, KEduVoc // traemostraéistraen // until no elements are left in that soup. + // now set the data: [count] - number of conjug? + // type - the tense? + // finally the person + + const KEduVocConjugation::ConjugationNumber numS = KEduVocConjugation::Singular; + const KEduVocConjugation::ConjugationNumber numP = KEduVocConjugation::Plural; + + conjugation.setConjugation( pers1_sing, KEduVocConjugation::First, numS); + conjugation.setConjugation( pers2_sing, KEduVocConjugation::Second, numS); + conjugation.setConjugation( pers1_plur, KEduVocConjugation::First, numP); + conjugation.setConjugation( pers2_plur, KEduVocConjugation::Second, numP); + + if ( s3_common ) { + conjugation.setConjugation( pers3_f_sing, KEduVocConjugation::ThirdNeuterCommon, KEduVocConjugation::Singular ); + } else { + conjugation.setConjugation( pers3_m_sing, + KEduVocConjugation::ThirdMale, KEduVocConjugation::Singular ); + conjugation.setConjugation( pers3_f_sing, + KEduVocConjugation::ThirdFemale, KEduVocConjugation::Singular ); + conjugation.setConjugation( pers3_n_sing, + KEduVocConjugation::ThirdNeuterCommon, KEduVocConjugation::Singular ); + } + + if ( p3_common ) { + conjugation.setConjugation( pers3_f_plur, KEduVocConjugation::ThirdNeuterCommon, KEduVocConjugation::Plural ); + } else { + conjugation.setConjugation( pers3_m_plur, + KEduVocConjugation::ThirdMale, KEduVocConjugation::Plural ); + conjugation.setConjugation( pers3_f_plur, + KEduVocConjugation::ThirdFemale, KEduVocConjugation::Plural ); + conjugation.setConjugation( pers3_n_plur, + KEduVocConjugation::ThirdNeuterCommon, KEduVocConjugation::Plural ); + } + + return true; +} + + + + +bool KEduVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, KEduVocPersonalPronoun& pronouns ) +{ +// QString s; + bool p3_common; + bool s3_common; + QString pers1_sing; + QString pers2_sing; + QString pers3_m_sing; + QString pers3_f_sing; + QString pers3_n_sing; + QString pers1_plur; + QString pers2_plur; + QString pers3_m_plur; + QString pers3_f_plur; + QString pers3_n_plur; + + p3_common = false; + s3_common = false; + + // get the individual entries for persons... + QDomElement domElementConjugGrandChild = domElementParent.firstChild().toElement(); + while ( !domElementConjugGrandChild.isNull() ) { + if ( domElementConjugGrandChild.tagName() == KV_CON_P1S ) { + pers1_sing = domElementConjugGrandChild.text(); + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P2S ) { + pers2_sing = domElementConjugGrandChild.text(); + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SF ) { + QDomAttr domAttrCommon = domElementConjugGrandChild.attributeNode( KV_CONJ_COMMON ); + if ( !domAttrCommon.isNull() ) + s3_common = domAttrCommon.value().toInt(); // returns 0 if the conversion fails + pers3_f_sing = domElementConjugGrandChild.text(); + + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SM ) { + pers3_m_sing = domElementConjugGrandChild.text(); + + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SN ) { + pers3_n_sing = domElementConjugGrandChild.text(); + + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P1P ) { + pers1_plur = domElementConjugGrandChild.text(); + + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P2P ) { + pers2_plur = domElementConjugGrandChild.text(); + + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PF ) { + QDomAttr domAttrCommon = domElementConjugGrandChild.attributeNode( KV_CONJ_COMMON ); + if ( !domAttrCommon.isNull() ) + p3_common = domAttrCommon.value().toInt(); // returns 0 if the conversion fails + + pers3_f_plur = domElementConjugGrandChild.text(); + + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PM ) { + pers3_m_plur = domElementConjugGrandChild.text(); + + } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PN ) { + pers3_n_plur = domElementConjugGrandChild.text(); + + } else { + return false; + } + + domElementConjugGrandChild = domElementConjugGrandChild.nextSibling().toElement(); + } // while - probably to be sure, because the persons could be in any order. + // I guess this goes over only one set, such as: + // traigotraestrae + // traemostraéistraen + // until no elements are left in that soup. // now set the data: [count] - number of conjug? // type - the tense? // finally the person - conjugation.setPers3SingularCommon( s3_common ); - conjugation.setPers3PluralCommon( p3_common ); - conjugation.setPers1Singular( pers1_sing ); - conjugation.setPers2Singular( pers2_sing ); - conjugation.setPers3FemaleSingular( pers3_f_sing ); - conjugation.setPers3MaleSingular( pers3_m_sing ); - conjugation.setPers3NaturalSingular( pers3_n_sing ); - conjugation.setPers1Plural( pers1_plur ); - conjugation.setPers2Plural( pers2_plur ); - conjugation.setPers3FemalePlural( pers3_f_plur ); - conjugation.setPers3MalePlural( pers3_m_plur ); - conjugation.setPers3NaturalPlural( pers3_n_plur ); + + const KEduVocConjugation::ConjugationNumber numS = KEduVocConjugation::Singular; + pronouns.setMaleFemaleDifferent(false); + pronouns.setPersonalPronoun( pers1_sing, KEduVocConjugation::First, numS ); + pronouns.setPersonalPronoun( pers2_sing, KEduVocConjugation::Second, numS ); + + // used to have common in female + if ( s3_common ) { + pronouns.setPersonalPronoun( pers3_f_sing, KEduVocConjugation::ThirdNeuterCommon, numS ); + } else { + pronouns.setPersonalPronoun( pers3_m_sing, + KEduVocConjugation::ThirdMale, numS ); + pronouns.setPersonalPronoun( pers3_f_sing, + KEduVocConjugation::ThirdFemale, numS ); + pronouns.setPersonalPronoun( pers3_n_sing, + KEduVocConjugation::ThirdNeuterCommon, numS ); + pronouns.setMaleFemaleDifferent(true); + } + + const KEduVocConjugation::ConjugationNumber numP = KEduVocConjugation::Plural; + + pronouns.setPersonalPronoun( pers1_sing, KEduVocConjugation::First, numP ); + pronouns.setPersonalPronoun( pers2_sing, KEduVocConjugation::Second, numP ); + if ( p3_common ) { + pronouns.setPersonalPronoun( pers3_f_plur, KEduVocConjugation::ThirdNeuterCommon, numP ); + } else { + pronouns.setPersonalPronoun( pers3_m_plur, + KEduVocConjugation::ThirdMale, numP ); + pronouns.setPersonalPronoun( pers3_f_plur, + KEduVocConjugation::ThirdFemale, numP ); + pronouns.setPersonalPronoun( pers3_n_plur, + KEduVocConjugation::ThirdNeuterCommon, numP ); + pronouns.setMaleFemaleDifferent(true); + } return true; } diff --git a/keduvocdocument/keduvockvtmlreader.h b/keduvocdocument/keduvockvtmlreader.h index 663b65c..ec8ee31 100644 --- a/keduvocdocument/keduvockvtmlreader.h +++ b/keduvocdocument/keduvockvtmlreader.h @@ -29,11 +29,11 @@ #include "keduvocgrammar.h" #include "keduvocmultiplechoice.h" #include "keduvockvtmlcompability.h" +#include "keduvocpersonalpronoun.h" class QIODevice; class KEduVocDocument; - /** @author Eric Pignet */ @@ -56,6 +56,7 @@ public: bool readLesson( QDomElement &domElementParent ); bool readArticle( QDomElement &domElementParent ); + bool readPersonalPronouns( QDomElement &domElementParent, KEduVocPersonalPronoun& pronouns ); bool readConjugation( QDomElement &domElementParent, KEduVocConjugation &conjugation ); bool readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslation &translation ); bool readType( QDomElement &domElementParent ); diff --git a/keduvocdocument/keduvockvtmlwriter.cpp b/keduvocdocument/keduvockvtmlwriter.cpp index c75a958..cadab68 100644 --- a/keduvocdocument/keduvockvtmlwriter.cpp +++ b/keduvocdocument/keduvockvtmlwriter.cpp @@ -44,10 +44,10 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato m_doc = doc; - QDomDocument domDoc( "kvtml SYSTEM \"kvoctrain.dtd\"" ); - domDoc.appendChild( domDoc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) ); - QDomElement domElementKvtml = domDoc.createElement( "kvtml" ); - domDoc.appendChild( domElementKvtml ); + m_domDoc = QDomDocument( "kvtml SYSTEM \"kvoctrain.dtd\"" ); + m_domDoc.appendChild( m_domDoc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) ); + QDomElement domElementKvtml = m_domDoc.createElement( "kvtml" ); + m_domDoc.appendChild( domElementKvtml ); domElementKvtml.setAttribute( KV_ENCODING, ( QString ) "UTF-8" ); domElementKvtml.setAttribute( KV_GENERATOR, generator ); @@ -66,27 +66,27 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato if ( !m_doc->documentComment().isEmpty() ) domElementKvtml.setAttribute( KV_DOC_REM, m_doc->documentComment() ); - if ( !writeLesson( domDoc, domElementKvtml ) ) + if ( !writeLesson( domElementKvtml ) ) return false; - if ( !writeArticle( domDoc, domElementKvtml ) ) + if ( !writeArticle( domElementKvtml ) ) return false; - QList conjugations; + QList pronouns; for ( int i = 0; i < m_doc->identifierCount(); i++ ) - conjugations.append( m_doc->identifier(i).personalPronouns() ); - if ( conjugations.count() > 0 ) { - if ( !writeConjugHeader( domDoc, domElementKvtml, conjugations ) ) + pronouns.append( m_doc->identifier(i).personalPronouns() ); + if ( pronouns.count() > 0 ) { + if ( !writePersonalPronouns(domElementKvtml, pronouns ) ) return false; } - if ( !writeType( domDoc, domElementKvtml ) ) + if ( !writeType( domElementKvtml ) ) return false; - if ( !writeTense( domDoc, domElementKvtml ) ) + if ( !writeTense( domElementKvtml ) ) return false; - if ( !writeUsage( domDoc, domElementKvtml ) ) + if ( !writeUsage( domElementKvtml ) ) return false; QString q_org, q_trans; @@ -96,7 +96,7 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato for ( int i = 0; i < entryCount; i++ ) { KEduVocExpression *entry = m_doc->entry( i ); - QDomElement domElementExpression = domDoc.createElement( KV_EXPR ); + QDomElement domElementExpression = m_domDoc.createElement( KV_EXPR ); if ( entry->lesson() != 0 ) { int lm = entry->lesson(); @@ -115,7 +115,7 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato if ( !entry->isActive() ) domElementExpression.setAttribute( KV_INACTIVE, 1 ); - QDomElement domElementOriginal = domDoc.createElement( KV_ORG ); + QDomElement domElementOriginal = m_domDoc.createElement( KV_ORG ); if ( first_expr ) { // save space, only tell language in first entry QString s; @@ -156,7 +156,7 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato if ( !entry->translation( 0 ).type().isEmpty() ) domElementOriginal.setAttribute( KV_EXPRTYPE, m_compability.oldType( entry->translation( 0 ).type(), entry->translation( 0 ).subType() ) ); - if ( !writeMultipleChoice( domDoc, domElementOriginal, entry->translation( 0 ).multipleChoice() ) ) + if ( !writeMultipleChoice(domElementOriginal, entry->translation( 0 ).multipleChoice() ) ) return false; QString s; @@ -169,24 +169,24 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato if ( entype == QM_VERB ) { // conjugation - if ( !writeConjugEntry( domDoc, domElementOriginal, entry->translation( 0 )) ) { + if ( !writeConjugEntry(domElementOriginal, entry->translation( 0 )) ) { return false; } } else if ( entype == QM_ADJ && !entry->translation( 0 ).comparison().isEmpty() ) { KEduVocComparison comp = entry->translation( 0 ).comparison(); - if ( !writeComparison( domDoc, domElementOriginal, comp ) ) + if ( !writeComparison(domElementOriginal, comp ) ) return false; } - QDomText domTextOriginal = domDoc.createTextNode( entry->translation( 0 ).text() ); + QDomText domTextOriginal = m_domDoc.createTextNode( entry->translation( 0 ).text() ); domElementOriginal.appendChild( domTextOriginal ); domElementExpression.appendChild( domElementOriginal ); int trans = 1; while ( trans < m_doc->identifierCount() ) { - QDomElement domElementTranslation = domDoc.createElement( KV_TRANS ); + QDomElement domElementTranslation = m_domDoc.createElement( KV_TRANS ); if ( first_expr ) { // save space, only tell language in first entry QString s; @@ -248,7 +248,7 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato if ( !entry->translation( trans ).type().isEmpty() ) domElementTranslation.setAttribute( KV_EXPRTYPE, m_compability.oldType( entry->translation( trans ).type(), entry->translation( trans ).subType() ) ); - if ( !writeMultipleChoice( domDoc, domElementTranslation, entry->translation( trans ).multipleChoice() ) ) + if ( !writeMultipleChoice(domElementTranslation, entry->translation( trans ).multipleChoice() ) ) return false; QString s; @@ -260,18 +260,18 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato entype = s; if ( entype == QM_VERB ) { - if ( !writeConjugEntry( domDoc, domElementTranslation, entry->translation( trans ) ) ) { + if ( !writeConjugEntry(domElementTranslation, entry->translation( trans ) ) ) { return false; } } if ( entype == QM_ADJ && !entry->translation( trans ).comparison().isEmpty() ) { KEduVocComparison comp = entry->translation( trans ).comparison(); - if ( !writeComparison( domDoc, domElementTranslation, comp ) ) + if ( !writeComparison(domElementTranslation, comp ) ) return false; } - QDomText domTextTranslation = domDoc.createTextNode( entry->translation( trans ).text() ); + QDomText domTextTranslation = m_domDoc.createTextNode( entry->translation( trans ).text() ); domElementTranslation.appendChild( domTextTranslation ); domElementExpression.appendChild( domElementTranslation ); @@ -283,26 +283,26 @@ bool KEduVocKvtmlWriter::writeDoc( KEduVocDocument *doc, const QString &generato first_expr = false; } - domDoc.appendChild( domElementKvtml ); + m_domDoc.appendChild( domElementKvtml ); QTextStream ts( m_outputFile ); - domDoc.save( ts, 2 ); + m_domDoc.save( ts, 2 ); return true; } -bool KEduVocKvtmlWriter::writeLesson( QDomDocument &domDoc, QDomElement &domElementParent ) +bool KEduVocKvtmlWriter::writeLesson( QDomElement &domElementParent ) { if ( m_doc->lessonCount() == 0 ) return true; - QDomElement domElementLesson = domDoc.createElement( KV_LESS_GRP ); + QDomElement domElementLesson = m_domDoc.createElement( KV_LESS_GRP ); domElementLesson.setAttribute( KV_SIZEHINT, m_doc->sizeHint( -1 ) ); for ( int i = 0; i < m_doc->lessonCount(); ++i ) { - QDomElement domElementDesc = domDoc.createElement( KV_LESS_DESC ); - QDomText domTextDesc = domDoc.createTextNode( m_doc->lesson(i).name() ); + QDomElement domElementDesc = m_domDoc.createElement( KV_LESS_DESC ); + QDomText domTextDesc = m_domDoc.createTextNode( m_doc->lesson(i).name() ); domElementDesc.setAttribute( KV_LESS_NO, i ); if ( m_doc->currentLesson() == i ) { @@ -320,7 +320,7 @@ bool KEduVocKvtmlWriter::writeLesson( QDomDocument &domDoc, QDomElement &domElem } -bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domElementParent ) +bool KEduVocKvtmlWriter::writeArticle( QDomElement &domElementParent ) /*
lang determines also lang order in entries !! @@ -334,14 +334,14 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle
*/ { - QDomElement domElementArticle = domDoc.createElement( KV_ARTICLE_GRP ); + QDomElement domElementArticle = m_domDoc.createElement( KV_ARTICLE_GRP ); QString def; QString indef; QString s; for ( int i = 0; i < m_doc->identifierCount(); i++ ) { - QDomElement domElementEntry = domDoc.createElement( KV_ART_ENTRY ); + QDomElement domElementEntry = m_domDoc.createElement( KV_ART_ENTRY ); s = m_doc->identifier(i).name().simplified(); domElementEntry.setAttribute( KV_LANG, s ); @@ -349,16 +349,16 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle // female articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Feminine ); if ( !articleString.isEmpty() ) { - QDomElement domElementFD = domDoc.createElement( KV_ART_FD ); - QDomText domTextFD = domDoc.createTextNode( articleString ); + QDomElement domElementFD = m_domDoc.createElement( KV_ART_FD ); + QDomText domTextFD = m_domDoc.createTextNode( articleString ); domElementFD.appendChild( domTextFD ); domElementEntry.appendChild( domElementFD ); } articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Feminine ); if ( !articleString.isEmpty() ) { - QDomElement domElementFI = domDoc.createElement( KV_ART_FI ); - QDomText domTextFI = domDoc.createTextNode( articleString ); + QDomElement domElementFI = m_domDoc.createElement( KV_ART_FI ); + QDomText domTextFI = m_domDoc.createTextNode( articleString ); domElementFI.appendChild( domTextFI ); domElementEntry.appendChild( domElementFI ); @@ -368,16 +368,16 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle // male articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Masculine ); if ( !articleString.isEmpty() ) { - QDomElement domElementMD = domDoc.createElement( KV_ART_MD ); - QDomText domTextMD = domDoc.createTextNode( articleString ); + QDomElement domElementMD = m_domDoc.createElement( KV_ART_MD ); + QDomText domTextMD = m_domDoc.createTextNode( articleString ); domElementMD.appendChild( domTextMD ); domElementEntry.appendChild( domElementMD ); } articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Masculine ); if ( !articleString.isEmpty() ) { - QDomElement domElementMI = domDoc.createElement( KV_ART_MI ); - QDomText domTextMI = domDoc.createTextNode( articleString ); + QDomElement domElementMI = m_domDoc.createElement( KV_ART_MI ); + QDomText domTextMI = m_domDoc.createTextNode( articleString ); domElementMI.appendChild( domTextMI ); domElementEntry.appendChild( domElementMI ); @@ -386,16 +386,16 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle // neuter articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Neuter ); if ( !articleString.isEmpty() ) { - QDomElement domElementND = domDoc.createElement( KV_ART_ND ); - QDomText domTextND = domDoc.createTextNode( articleString ); + QDomElement domElementND = m_domDoc.createElement( KV_ART_ND ); + QDomText domTextND = m_domDoc.createTextNode( articleString ); domElementND.appendChild( domTextND ); domElementEntry.appendChild( domElementND ); } articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Neuter ); if ( !articleString.isEmpty() ) { - QDomElement domElementNI = domDoc.createElement( KV_ART_NI ); - QDomText domTextNI = domDoc.createTextNode( articleString ); + QDomElement domElementNI = m_domDoc.createElement( KV_ART_NI ); + QDomText domTextNI = m_domDoc.createTextNode( articleString ); domElementNI.appendChild( domTextNI ); domElementEntry.appendChild( domElementNI ); @@ -409,21 +409,21 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle } -bool KEduVocKvtmlWriter::writeType( QDomDocument &domDoc, QDomElement &domElementParent ) +bool KEduVocKvtmlWriter::writeType( QDomElement &domElementParent ) { /** @todo port to new type handling if (m_doc->typeDescriptions().count() == 0) return true; - QDomElement domElementType = domDoc.createElement(KV_TYPE_GRP); + QDomElement domElementType = m_domDoc.createElement(KV_TYPE_GRP); int count = 1; foreach(QString type, m_doc->typeDescriptions()) { if (!(type.isNull()) ) { - QDomElement domElementDesc = domDoc.createElement(KV_TYPE_DESC); - QDomText domTextDesc = domDoc.createTextNode(type); + QDomElement domElementDesc = m_domDoc.createElement(KV_TYPE_DESC); + QDomText domTextDesc = m_domDoc.createTextNode(type); domElementDesc.setAttribute(KV_TYPE_NO, count); domElementDesc.appendChild(domTextDesc); @@ -438,18 +438,18 @@ bool KEduVocKvtmlWriter::writeType( QDomDocument &domDoc, QDomElement &domElemen } -bool KEduVocKvtmlWriter::writeTense( QDomDocument &domDoc, QDomElement &domElementParent ) +bool KEduVocKvtmlWriter::writeTense( QDomElement &domElementParent ) { if ( m_doc->tenseDescriptions().count() == 0 ) return true; - QDomElement domElementTense = domDoc.createElement( KV_TENSE_GRP ); + QDomElement domElementTense = m_domDoc.createElement( KV_TENSE_GRP ); int count = 1; foreach( QString tense, m_doc->tenseDescriptions() ) { if ( !( tense.isNull() ) ) { - QDomElement domElementDesc = domDoc.createElement( KV_TENSE_DESC ); - QDomText domTextDesc = domDoc.createTextNode( tense ); + QDomElement domElementDesc = m_domDoc.createElement( KV_TENSE_DESC ); + QDomText domTextDesc = m_domDoc.createTextNode( tense ); domElementDesc.setAttribute( KV_TENSE_NO, count ); domElementDesc.appendChild( domTextDesc ); @@ -463,7 +463,7 @@ bool KEduVocKvtmlWriter::writeTense( QDomDocument &domDoc, QDomElement &domEleme } -bool KEduVocKvtmlWriter::writeUsage( QDomDocument &domDoc, QDomElement &domElementParent ) +bool KEduVocKvtmlWriter::writeUsage( QDomElement &domElementParent ) { ///@todo usages @@ -471,15 +471,15 @@ bool KEduVocKvtmlWriter::writeUsage( QDomDocument &domDoc, QDomElement &domEleme if (m_doc->usageDescriptions().count() == 0) return true; - QDomElement domElementUsage = domDoc.createElement(KV_USAGE_GRP); + QDomElement domElementUsage = m_domDoc.createElement(KV_USAGE_GRP); int count = 1; foreach(QString usage, m_doc->usageDescriptions()) { if (!(usage.isNull())) { - QDomElement domElementDesc = domDoc.createElement(KV_USAGE_DESC); - QDomText domTextDesc = domDoc.createTextNode(usage); + QDomElement domElementDesc = m_domDoc.createElement(KV_USAGE_DESC); + QDomText domTextDesc = m_domDoc.createTextNode(usage); domElementDesc.setAttribute(KV_USAGE_NO, count); domElementDesc.appendChild(domTextDesc); @@ -494,7 +494,7 @@ bool KEduVocKvtmlWriter::writeUsage( QDomDocument &domDoc, QDomElement &domEleme } -bool KEduVocKvtmlWriter::writeComparison( QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocComparison &comp ) +bool KEduVocKvtmlWriter::writeComparison( QDomElement &domElementParent, const KEduVocComparison &comp ) /* good @@ -506,27 +506,27 @@ bool KEduVocKvtmlWriter::writeComparison( QDomDocument &domDoc, QDomElement &dom if ( comp.isEmpty() ) return true; - QDomElement domElementComparison = domDoc.createElement( KV_COMPARISON_GRP ); + QDomElement domElementComparison = m_domDoc.createElement( KV_COMPARISON_GRP ); if ( !comp.l1().isEmpty() ) { - QDomElement domElementL1 = domDoc.createElement( KV_COMP_L1 ); - QDomText domTextL1 = domDoc.createTextNode( comp.l1() ); + QDomElement domElementL1 = m_domDoc.createElement( KV_COMP_L1 ); + QDomText domTextL1 = m_domDoc.createTextNode( comp.l1() ); domElementL1.appendChild( domTextL1 ); domElementComparison.appendChild( domElementL1 ); } if ( !comp.l2().isEmpty() ) { - QDomElement domElementL2 = domDoc.createElement( KV_COMP_L2 ); - QDomText domTextL2 = domDoc.createTextNode( comp.l2() ); + QDomElement domElementL2 = m_domDoc.createElement( KV_COMP_L2 ); + QDomText domTextL2 = m_domDoc.createTextNode( comp.l2() ); domElementL2.appendChild( domTextL2 ); domElementComparison.appendChild( domElementL2 ); } if ( !comp.l3().isEmpty() ) { - QDomElement domElementL3 = domDoc.createElement( KV_COMP_L3 ); - QDomText domTextL3 = domDoc.createTextNode( comp.l3() ); + QDomElement domElementL3 = m_domDoc.createElement( KV_COMP_L3 ); + QDomText domTextL3 = m_domDoc.createTextNode( comp.l3() ); domElementL3.appendChild( domTextL3 ); domElementComparison.appendChild( domElementL3 ); @@ -537,7 +537,7 @@ bool KEduVocKvtmlWriter::writeComparison( QDomDocument &domDoc, QDomElement &dom } -bool KEduVocKvtmlWriter::writeMultipleChoice( QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocMultipleChoice &mc ) +bool KEduVocKvtmlWriter::writeMultipleChoice( QDomElement &domElementParent, const KEduVocMultipleChoice &mc ) /* good @@ -551,43 +551,43 @@ bool KEduVocKvtmlWriter::writeMultipleChoice( QDomDocument &domDoc, QDomElement if ( mc.isEmpty() ) return true; - QDomElement domElementMC = domDoc.createElement( KV_MULTIPLECHOICE_GRP ); + QDomElement domElementMC = m_domDoc.createElement( KV_MULTIPLECHOICE_GRP ); if ( !mc.choice( 1 ).isEmpty() ) { - QDomElement domElementMC1 = domDoc.createElement( KV_MC_1 ); - QDomText domTextMC1 = domDoc.createTextNode( mc.choice( 1 ) ); + QDomElement domElementMC1 = m_domDoc.createElement( KV_MC_1 ); + QDomText domTextMC1 = m_domDoc.createTextNode( mc.choice( 1 ) ); domElementMC1.appendChild( domTextMC1 ); domElementMC.appendChild( domElementMC1 ); } if ( !mc.choice( 2 ).isEmpty() ) { - QDomElement domElementMC2 = domDoc.createElement( KV_MC_2 ); - QDomText domTextMC2 = domDoc.createTextNode( mc.choice( 2 ) ); + QDomElement domElementMC2 = m_domDoc.createElement( KV_MC_2 ); + QDomText domTextMC2 = m_domDoc.createTextNode( mc.choice( 2 ) ); domElementMC2.appendChild( domTextMC2 ); domElementMC.appendChild( domElementMC2 ); } if ( !mc.choice( 3 ).isEmpty() ) { - QDomElement domElementMC3 = domDoc.createElement( KV_MC_3 ); - QDomText domTextMC3 = domDoc.createTextNode( mc.choice( 3 ) ); + QDomElement domElementMC3 = m_domDoc.createElement( KV_MC_3 ); + QDomText domTextMC3 = m_domDoc.createTextNode( mc.choice( 3 ) ); domElementMC3.appendChild( domTextMC3 ); domElementMC.appendChild( domElementMC3 ); } if ( !mc.choice( 4 ).isEmpty() ) { - QDomElement domElementMC4 = domDoc.createElement( KV_MC_4 ); - QDomText domTextMC4 = domDoc.createTextNode( mc.choice( 4 ) ); + QDomElement domElementMC4 = m_domDoc.createElement( KV_MC_4 ); + QDomText domTextMC4 = m_domDoc.createTextNode( mc.choice( 4 ) ); domElementMC4.appendChild( domTextMC4 ); domElementMC.appendChild( domElementMC4 ); } if ( !mc.choice( 5 ).isEmpty() ) { - QDomElement domElementMC5 = domDoc.createElement( KV_MC_5 ); - QDomText domTextMC5 = domDoc.createTextNode( mc.choice( 5 ) ); + QDomElement domElementMC5 = m_domDoc.createElement( KV_MC_5 ); + QDomText domTextMC5 = m_domDoc.createTextNode( mc.choice( 5 ) ); domElementMC5.appendChild( domTextMC5 ); domElementMC.appendChild( domElementMC5 ); @@ -598,7 +598,7 @@ bool KEduVocKvtmlWriter::writeMultipleChoice( QDomDocument &domDoc, QDomElement } -bool KEduVocKvtmlWriter::writeConjugHeader( QDomDocument &domDoc, QDomElement &domElementParent, QList &curr_conjug ) +bool KEduVocKvtmlWriter::writeConjugHeader( QDomElement &domElementParent, QList &curr_conjug ) { /* used in header for definiton of "prefix" @@ -620,11 +620,11 @@ bool KEduVocKvtmlWriter::writeConjugHeader( QDomDocument &domDoc, QDomElement &d if ( curr_conjug.size() == 0 ) return true; - QDomElement domElementConjug = domDoc.createElement( KV_CONJUG_GRP ); + QDomElement domElementConjug = m_domDoc.createElement( KV_CONJUG_GRP ); QString s; for ( int ent = 0; ent < qMin( curr_conjug.count(), m_doc->identifierCount() ); ent++ ) { - QDomElement domElementEntry = domDoc.createElement( KV_CON_ENTRY ); + QDomElement domElementEntry = m_domDoc.createElement( KV_CON_ENTRY ); s = m_doc->identifier( ent ).name().simplified(); if ( s.isEmpty() ) { @@ -633,7 +633,7 @@ bool KEduVocKvtmlWriter::writeConjugHeader( QDomDocument &domDoc, QDomElement &d } domElementEntry.setAttribute( KV_LANG, s ); - if ( !writeConjug( domDoc, domElementEntry, curr_conjug[ent], "--" ) ) + if ( !writeConjug(domElementEntry, curr_conjug[ent], "--" ) ) return false; domElementConjug.appendChild( domElementEntry ); @@ -644,7 +644,7 @@ bool KEduVocKvtmlWriter::writeConjugHeader( QDomDocument &domDoc, QDomElement &d } -bool KEduVocKvtmlWriter::writeConjugEntry( QDomDocument &domDoc, QDomElement &domElementParent, KEduVocTranslation &translation ) +bool KEduVocKvtmlWriter::writeConjugEntry( QDomElement &domElementParent, KEduVocTranslation &translation ) /* in entry for definition of tenses of (irreg.) verbs @@ -664,14 +664,14 @@ bool KEduVocKvtmlWriter::writeConjugEntry( QDomDocument &domDoc, QDomElement &do { // curr_conjug.cleanUp(); - QDomElement domElementConjug = domDoc.createElement( KV_CONJUG_GRP ); + QDomElement domElementConjug = m_domDoc.createElement( KV_CONJUG_GRP ); foreach ( QString tense, translation.conjugationTenses() ) { - QDomElement domElementType = domDoc.createElement( KV_CON_TYPE ); + QDomElement domElementType = m_domDoc.createElement( KV_CON_TYPE ); domElementType.setAttribute( KV_CON_NAME, m_compability.oldTense(tense) ); - if ( !writeConjug( domDoc, domElementType, translation.conjugation(tense), m_compability.oldTense(tense) ) ) + if ( !writeConjug(domElementType, translation.conjugation(tense), m_compability.oldTense(tense) ) ) return false; domElementConjug.appendChild( domElementType ); @@ -682,27 +682,29 @@ bool KEduVocKvtmlWriter::writeConjugEntry( QDomDocument &domDoc, QDomElement &do } -bool KEduVocKvtmlWriter::writeConjug( QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocConjugation &curr_conjug, const QString &type ) +bool KEduVocKvtmlWriter::writeConjug( QDomElement &domElementParent, const KEduVocConjugation &curr_conjug, const QString &type ) { +///@todo if we are to enable the writer: port this! +/* if ( !curr_conjug.pers1Singular().isEmpty() ) { - QDomElement domElementP1s = domDoc.createElement( KV_CON_P1S ); - QDomText domTextP1s = domDoc.createTextNode( curr_conjug.pers1Singular() ); + QDomElement domElementP1s = m_domDoc.createElement( KV_CON_P1S ); + QDomText domTextP1s = m_domDoc.createTextNode( curr_conjug.pers1Singular() ); domElementP1s.appendChild( domTextP1s ); domElementParent.appendChild( domElementP1s ); } if ( !curr_conjug.pers2Singular().isEmpty() ) { - QDomElement domElementP2s = domDoc.createElement( KV_CON_P2S ); - QDomText domTextP2s = domDoc.createTextNode( curr_conjug.pers2Singular() ); + QDomElement domElementP2s = m_domDoc.createElement( KV_CON_P2S ); + QDomText domTextP2s = m_domDoc.createTextNode( curr_conjug.pers2Singular() ); domElementP2s.appendChild( domTextP2s ); domElementParent.appendChild( domElementP2s ); } if ( !curr_conjug.pers3FemaleSingular().isEmpty() || curr_conjug.pers3SingularCommon() ) { - QDomElement domElementP3sf = domDoc.createElement( KV_CON_P3SF ); - QDomText domTextP3sf = domDoc.createTextNode( curr_conjug.pers3FemaleSingular() ); + QDomElement domElementP3sf = m_domDoc.createElement( KV_CON_P3SF ); + QDomText domTextP3sf = m_domDoc.createTextNode( curr_conjug.pers3FemaleSingular() ); if ( curr_conjug.pers3SingularCommon() ) domElementP3sf.setAttribute( KV_CONJ_COMMON, 1 ); @@ -712,40 +714,40 @@ bool KEduVocKvtmlWriter::writeConjug( QDomDocument &domDoc, QDomElement &domElem } if ( !curr_conjug.pers3MaleSingular().isEmpty() ) { - QDomElement domElementP3sm = domDoc.createElement( KV_CON_P3SM ); - QDomText domTextP3sm = domDoc.createTextNode( curr_conjug.pers3MaleSingular() ); + QDomElement domElementP3sm = m_domDoc.createElement( KV_CON_P3SM ); + QDomText domTextP3sm = m_domDoc.createTextNode( curr_conjug.pers3MaleSingular() ); domElementP3sm.appendChild( domTextP3sm ); domElementParent.appendChild( domElementP3sm ); } if ( !curr_conjug.pers3NaturalSingular().isEmpty() ) { - QDomElement domElementP3sn = domDoc.createElement( KV_CON_P3SN ); - QDomText domTextP3sn = domDoc.createTextNode( curr_conjug.pers3NaturalSingular() ); + QDomElement domElementP3sn = m_domDoc.createElement( KV_CON_P3SN ); + QDomText domTextP3sn = m_domDoc.createTextNode( curr_conjug.pers3NaturalSingular() ); domElementP3sn.appendChild( domTextP3sn ); domElementParent.appendChild( domElementP3sn ); } if ( !curr_conjug.pers1Plural().isEmpty() ) { - QDomElement domElementP1p = domDoc.createElement( KV_CON_P1P ); - QDomText domTextP1p = domDoc.createTextNode( curr_conjug.pers1Plural() ); + QDomElement domElementP1p = m_domDoc.createElement( KV_CON_P1P ); + QDomText domTextP1p = m_domDoc.createTextNode( curr_conjug.pers1Plural() ); domElementP1p.appendChild( domTextP1p ); domElementParent.appendChild( domElementP1p ); } if ( !curr_conjug.pers2Plural().isEmpty() ) { - QDomElement domElementP2p = domDoc.createElement( KV_CON_P2P ); - QDomText domTextP2p = domDoc.createTextNode( curr_conjug.pers2Plural() ); + QDomElement domElementP2p = m_domDoc.createElement( KV_CON_P2P ); + QDomText domTextP2p = m_domDoc.createTextNode( curr_conjug.pers2Plural() ); domElementP2p.appendChild( domTextP2p ); domElementParent.appendChild( domElementP2p ); } if ( !curr_conjug.pers3FemalePlural().isEmpty() || curr_conjug.pers3PluralCommon() ) { - QDomElement domElementP3pf = domDoc.createElement( KV_CON_P3PF ); - QDomText domTextP3pf = domDoc.createTextNode( curr_conjug.pers3FemalePlural() ); + QDomElement domElementP3pf = m_domDoc.createElement( KV_CON_P3PF ); + QDomText domTextP3pf = m_domDoc.createTextNode( curr_conjug.pers3FemalePlural() ); if ( curr_conjug.pers3PluralCommon() ) domElementP3pf.setAttribute( KV_CONJ_COMMON, 1 ); @@ -755,20 +757,175 @@ bool KEduVocKvtmlWriter::writeConjug( QDomDocument &domDoc, QDomElement &domElem } if ( !curr_conjug.pers3MalePlural().isEmpty() ) { - QDomElement domElementP3pm = domDoc.createElement( KV_CON_P3PM ); - QDomText domTextP3pm = domDoc.createTextNode( curr_conjug.pers3MalePlural() ); + QDomElement domElementP3pm = m_domDoc.createElement( KV_CON_P3PM ); + QDomText domTextP3pm = m_domDoc.createTextNode( curr_conjug.pers3MalePlural() ); domElementP3pm.appendChild( domTextP3pm ); domElementParent.appendChild( domElementP3pm ); } if ( !curr_conjug.pers3NaturalPlural().isEmpty() ) { - QDomElement domElementP3pn = domDoc.createElement( KV_CON_P3PN ); - QDomText domTextP3pn = domDoc.createTextNode( curr_conjug.pers3NaturalPlural() ); + QDomElement domElementP3pn = m_domDoc.createElement( KV_CON_P3PN ); + QDomText domTextP3pn = m_domDoc.createTextNode( curr_conjug.pers3NaturalPlural() ); domElementP3pn.appendChild( domTextP3pn ); domElementParent.appendChild( domElementP3pn ); } + return true; */ + kDebug() << "Implement me!"; + return false; +} + +bool KEduVocKvtmlWriter::writePersonalPronouns( QDomElement &domElementParent, QList &curr_conjug ) +{ + /* + used in header for definiton of "prefix" + lang determines also lang order in entries !! + I which must NOT differ + you<2> + he + she + it + we + you + they + they + they + + + */ + const QString type = QString::fromLatin1("--"); + + if ( curr_conjug.size() == 0 ) + return true; + + QDomElement domElementConjug = m_domDoc.createElement( KV_CONJUG_GRP ); + QString s; + + for ( int ent = 0; ent < qMin( curr_conjug.count(), m_doc->identifierCount() ); ent++ ) { + QDomElement domElementEntry = m_domDoc.createElement( KV_CON_ENTRY ); + + s = m_doc->identifier( ent ).name().simplified(); + if ( s.isEmpty() ) { + s.setNum( ent ); + s.prepend( "translation " ); + } + + domElementEntry.setAttribute( KV_LANG, s ); + if ( !writePersonalPronounChild(domElementEntry, curr_conjug[ent] ) ) + return false; + + domElementConjug.appendChild( domElementEntry ); + } + + domElementParent.appendChild( domElementConjug ); + return true; +} + + +bool KEduVocKvtmlWriter::writePersonalPronounChild( QDomElement &domElementParent, const KEduVocPersonalPronoun &curr_conjug ) +{ + // the old stuff only has singular + const KEduVocConjugation::ConjugationNumber num = KEduVocConjugation::Singular; + + if ( !curr_conjug.personalPronoun( KEduVocConjugation::First, num ).isEmpty() ) { + domElementParent.appendChild( newTextElement( KV_CON_P1S, curr_conjug.personalPronoun( KEduVocConjugation::First, num ) ) ); + } + + if ( !curr_conjug.personalPronoun( KEduVocConjugation::Second, num ).isEmpty() ) { + domElementParent.appendChild( newTextElement( KV_CON_P2S, curr_conjug.personalPronoun( KEduVocConjugation::Second, num ) ) ); + } + + ///@todo if the writer ever becomes enabled, write the other pronouns +/* + if ( !curr_conjug.pers2Singular().isEmpty() ) { + QDomElement domElementP2s = m_domDoc.createElement( KV_CON_P2S ); + QDomText domTextP2s = m_domDoc.createTextNode( curr_conjug.pers2Singular() ); + + domElementP2s.appendChild( domTextP2s ); + domElementParent.appendChild( domElementP2s ); + } + + if ( !curr_conjug.pers3FemaleSingular().isEmpty() || curr_conjug.pers3SingularCommon() ) { + QDomElement domElementP3sf = m_domDoc.createElement( KV_CON_P3SF ); + QDomText domTextP3sf = m_domDoc.createTextNode( curr_conjug.pers3FemaleSingular() ); + + if ( curr_conjug.pers3SingularCommon() ) + domElementP3sf.setAttribute( KV_CONJ_COMMON, 1 ); + + domElementP3sf.appendChild( domTextP3sf ); + domElementParent.appendChild( domElementP3sf ); + } + + if ( !curr_conjug.pers3MaleSingular().isEmpty() ) { + QDomElement domElementP3sm = m_domDoc.createElement( KV_CON_P3SM ); + QDomText domTextP3sm = m_domDoc.createTextNode( curr_conjug.pers3MaleSingular() ); + + domElementP3sm.appendChild( domTextP3sm ); + domElementParent.appendChild( domElementP3sm ); + } + + if ( !curr_conjug.pers3NaturalSingular().isEmpty() ) { + QDomElement domElementP3sn = m_domDoc.createElement( KV_CON_P3SN ); + QDomText domTextP3sn = m_domDoc.createTextNode( curr_conjug.pers3NaturalSingular() ); + + domElementP3sn.appendChild( domTextP3sn ); + domElementParent.appendChild( domElementP3sn ); + } + + if ( !curr_conjug.pers1Plural().isEmpty() ) { + QDomElement domElementP1p = m_domDoc.createElement( KV_CON_P1P ); + QDomText domTextP1p = m_domDoc.createTextNode( curr_conjug.pers1Plural() ); + + domElementP1p.appendChild( domTextP1p ); + domElementParent.appendChild( domElementP1p ); + } + + if ( !curr_conjug.pers2Plural().isEmpty() ) { + QDomElement domElementP2p = m_domDoc.createElement( KV_CON_P2P ); + QDomText domTextP2p = m_domDoc.createTextNode( curr_conjug.pers2Plural() ); + + domElementP2p.appendChild( domTextP2p ); + domElementParent.appendChild( domElementP2p ); + } + + if ( !curr_conjug.pers3FemalePlural().isEmpty() || curr_conjug.pers3PluralCommon() ) { + QDomElement domElementP3pf = m_domDoc.createElement( KV_CON_P3PF ); + QDomText domTextP3pf = m_domDoc.createTextNode( curr_conjug.pers3FemalePlural() ); + + if ( curr_conjug.pers3PluralCommon() ) + domElementP3pf.setAttribute( KV_CONJ_COMMON, 1 ); + + domElementP3pf.appendChild( domTextP3pf ); + domElementParent.appendChild( domElementP3pf ); + } + + if ( !curr_conjug.pers3MalePlural().isEmpty() ) { + QDomElement domElementP3pm = m_domDoc.createElement( KV_CON_P3PM ); + QDomText domTextP3pm = m_domDoc.createTextNode( curr_conjug.pers3MalePlural() ); + + domElementP3pm.appendChild( domTextP3pm ); + domElementParent.appendChild( domElementP3pm ); + } + + if ( !curr_conjug.pers3NaturalPlural().isEmpty() ) { + QDomElement domElementP3pn = m_domDoc.createElement( KV_CON_P3PN ); + QDomText domTextP3pn = m_domDoc.createTextNode( curr_conjug.pers3NaturalPlural() ); + + domElementP3pn.appendChild( domTextP3pn ); + domElementParent.appendChild( domElementP3pn ); + }*/ + return true; } + +QDomElement KEduVocKvtmlWriter::newTextElement( const QString &elementName, const QString &text ) +{ + QDomElement retval = m_domDoc.createElement( elementName ); + QDomText textNode = m_domDoc.createTextNode( text ); + retval.appendChild( textNode ); + return retval; +} + + diff --git a/keduvocdocument/keduvockvtmlwriter.h b/keduvocdocument/keduvockvtmlwriter.h index 2a4d038..8a001a9 100644 --- a/keduvocdocument/keduvockvtmlwriter.h +++ b/keduvocdocument/keduvockvtmlwriter.h @@ -25,6 +25,7 @@ #include #include "keduvocgrammar.h" +#include "keduvocpersonalpronoun.h" #include "keduvocconjugation.h" #include "keduvocmultiplechoice.h" #include "keduvockvtmlcompability.h" @@ -42,22 +43,30 @@ public: bool writeDoc( KEduVocDocument *doc, const QString &generator ); - bool writeLesson( QDomDocument &domDoc, QDomElement &domElementParent ); - bool writeType( QDomDocument &domDoc, QDomElement &domElementParent ); - bool writeTense( QDomDocument &domDoc, QDomElement &domElementParent ); - bool writeUsage( QDomDocument &domDoc, QDomElement &domElementParent ); - bool writeOption( QDomDocument &domDoc, QDomElement &domElementParent ); - bool writeArticle( QDomDocument &domDoc, QDomElement &domElementParent ); - bool writeConjugHeader( QDomDocument &domDoc, QDomElement &domElementParent, QList &curr_conjug ); - bool writeConjug( QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocConjugation &curr_conjug, const QString &type ); - bool writeConjugEntry( QDomDocument &domDoc, QDomElement &domElementParent, KEduVocTranslation &translation ); - bool writeComparison( QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocComparison &comp ); - bool writeMultipleChoice( QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocMultipleChoice &mc ); - private: + bool writeLesson( QDomElement &domElementParent ); + bool writeType( QDomElement &domElementParent ); + bool writeTense( QDomElement &domElementParent ); + bool writeUsage( QDomElement &domElementParent ); + bool writeOption( QDomElement &domElementParent ); + bool writeArticle( QDomElement &domElementParent ); + + bool writePersonalPronouns( QDomElement &domElementParent, QList &curr_conjug ); + bool writePersonalPronounChild( QDomElement &domElementParent, const KEduVocPersonalPronoun &curr_conjug ); + + bool writeConjugHeader( QDomElement &domElementParent, QList &curr_conjug ); + bool writeConjug( QDomElement &domElementParent, const KEduVocConjugation &curr_conjug, const QString &type ); + bool writeConjugEntry( QDomElement &domElementParent, KEduVocTranslation &translation ); + bool writeComparison( QDomElement &domElementParent, const KEduVocComparison &comp ); + bool writeMultipleChoice( QDomElement &domElementParent, const KEduVocMultipleChoice &mc ); + + QDomElement newTextElement( const QString &elementName, const QString &text ); + QFile *m_outputFile; KEduVocDocument *m_doc; + QDomDocument m_domDoc; + KEduVocKvtmlCompability m_compability; }; diff --git a/keduvocdocument/keduvocpersonalpronoun.cpp b/keduvocdocument/keduvocpersonalpronoun.cpp new file mode 100644 index 0000000..4b65a63 --- /dev/null +++ b/keduvocdocument/keduvocpersonalpronoun.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** + Copyright 2007 Frederik Gladhorn + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "keduvocpersonalpronoun.h" +#include "keduvoccommon_p.h" +#include +#include + +class KEduVocPersonalPronoun::Private +{ +public: + Private(); + + bool m_maleFemaleDifferent; + bool m_neuterExists; + QMap m_personalpronouns; +}; + + +KEduVocPersonalPronoun::Private::Private() +{ + m_maleFemaleDifferent = false; + m_neuterExists = false; +} + +KEduVocPersonalPronoun::KEduVocPersonalPronoun() + : d( new Private ) +{} + + +KEduVocPersonalPronoun::KEduVocPersonalPronoun( const KEduVocPersonalPronoun& other ) + : d( new Private ) +{ + d->m_maleFemaleDifferent = other.d->m_maleFemaleDifferent; + d->m_neuterExists = other.d->m_neuterExists; + d->m_personalpronouns = other.d->m_personalpronouns; +} + + +KEduVocPersonalPronoun::~KEduVocPersonalPronoun() +{ + delete d; +} + + +KEduVocPersonalPronoun& KEduVocPersonalPronoun::operator = ( const KEduVocPersonalPronoun& other ) +{ + d->m_maleFemaleDifferent = other.d->m_maleFemaleDifferent; + d->m_neuterExists = other.d->m_neuterExists; + d->m_personalpronouns = other.d->m_personalpronouns; + return *this; +} + +bool KEduVocPersonalPronoun::operator ==(const KEduVocPersonalPronoun& other) const +{ + return d->m_personalpronouns == other.d->m_personalpronouns && + d->m_maleFemaleDifferent == other.d->m_maleFemaleDifferent && + d->m_neuterExists == other.d->m_neuterExists; +} + + +QString KEduVocPersonalPronoun::personalPronoun(KEduVocConjugation::ConjugationPerson person, KEduVocConjugation::ConjugationNumber number) const +{ + int index = indexOf(person, number); + if ( d->m_personalpronouns.contains(index) ) { + return d->m_personalpronouns.value(index); + } + return QString(); +} + +void KEduVocPersonalPronoun::setPersonalPronoun(const QString & personalpronoun, KEduVocConjugation::ConjugationPerson person, KEduVocConjugation::ConjugationNumber number) +{ + d->m_personalpronouns[indexOf(person, number)] = personalpronoun; +} + + +int KEduVocPersonalPronoun::indexOf(KEduVocConjugation::ConjugationPerson person, KEduVocConjugation::ConjugationNumber number) const +{ + return person + KEduVocConjugation::PersonMAX * number; +} + +bool KEduVocPersonalPronoun::maleFemaleDifferent() const +{ + return d->m_maleFemaleDifferent; +} + +void KEduVocPersonalPronoun::setMaleFemaleDifferent(bool different) +{ + d->m_maleFemaleDifferent = different; +} + +bool KEduVocPersonalPronoun::neuterExists() const +{ + return d->m_neuterExists; +} + +void KEduVocPersonalPronoun::setNeuterExists(bool exists) +{ + d->m_neuterExists = exists; +} diff --git a/keduvocdocument/keduvocpersonalpronoun.h b/keduvocdocument/keduvocpersonalpronoun.h new file mode 100644 index 0000000..8ba0d23 --- /dev/null +++ b/keduvocdocument/keduvocpersonalpronoun.h @@ -0,0 +1,59 @@ +/*************************************************************************** + Copyright 2007 Frederik Gladhorn + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KEDUVOCPERSONALPRONOUN_H +#define KEDUVOCPERSONALPRONOUN_H + +#include "libkeduvocdocument_export.h" +#include "keduvocconjugation.h" +#include + +/** + * The conjugation of a verb + */ +class KEDUVOCDOCUMENT_EXPORT KEduVocPersonalPronoun +{ +public: + + /** + * The constructor + */ + explicit KEduVocPersonalPronoun(); + + KEduVocPersonalPronoun( const KEduVocPersonalPronoun& rhs ); + + ~KEduVocPersonalPronoun(); + + KEduVocPersonalPronoun& operator = ( const KEduVocPersonalPronoun& a ); + bool operator == ( const KEduVocPersonalPronoun& a ) const; + + QString personalPronoun(KEduVocConjugation::ConjugationPerson person, KEduVocConjugation::ConjugationNumber number) const; + void setPersonalPronoun(const QString& conjugation, KEduVocConjugation::ConjugationPerson person, KEduVocConjugation::ConjugationNumber number); + + bool maleFemaleDifferent() const; + void setMaleFemaleDifferent(bool different); + + bool neuterExists() const; + void setNeuterExists(bool exists); +private: + class Private; + Private* const d; + + int indexOf(KEduVocConjugation::ConjugationPerson person, KEduVocConjugation::ConjugationNumber number) const; +}; + + + +#endif // KEDUVOCCONJUGATION_H + diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 7a5db65..5ba4555 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -327,7 +327,7 @@ void KEduVocTranslation::resetGrades() d->m_grades.clear(); } -KEduVocGrade & KEduVocTranslation::gradeFrom( int indexFrom ) +KEduVocGrade& KEduVocTranslation::gradeFrom( int indexFrom ) { return d->m_grades[indexFrom]; } diff --git a/keduvocdocument/kvtml2defs.h b/keduvocdocument/kvtml2defs.h index d4302b4..6de4629 100644 --- a/keduvocdocument/kvtml2defs.h +++ b/keduvocdocument/kvtml2defs.h @@ -51,11 +51,20 @@ #define KVTML_FEMALE "female" #define KVTML_NEUTRAL "neutral" #define KVTML_SINGULAR "singular" +// dual is the case where there's a special form for exactly two +#define KVTML_DUAL "dual" #define KVTML_PLURAL "plural" #define KVTML_1STPERSON "firstperson" #define KVTML_2NDPERSON "secondperson" -#define KVTML_3RDPERSON "thirdperson" -#define KVTML_COMMON "common" +#define KVTML_THIRD_MALE "thirdpersonmale" +#define KVTML_THIRD_FEMALE "thirdpersonfemale" +#define KVTML_THIRD_NEUTER_COMMON "thirdpersonneutercommon" + +// for the personal pronuns: +// if this tag exists, in a conjugation male/female are different +#define KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT "malefemaledifferent" +// if this tag exists conjugations even have a neuter form for the third person +#define KVTML_THIRD_PERSON_NEUTER_EXISTS "neuterexists" // word types #define KVTML_WORDTYPEDEFINITIONS "wordtypedefinitions" -- 2.47.3