From ed1cc127ea5211440286950b28d05fc87773391f Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Sun, 23 Mar 2008 03:26:46 +0000 Subject: [PATCH] Remove synonyms, antonyms and false friends completely. Add lists of pointers to keduvoctranslation to the translation class for them instead. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=789084 --- keduvocdocument/keduvockvtml2reader.cpp | 12 ++- keduvocdocument/keduvockvtml2writer.cpp | 21 +++-- keduvocdocument/keduvockvtmlreader.cpp | 20 ++-- keduvocdocument/keduvoctranslation.cpp | 117 ++++++++++++------------ keduvocdocument/keduvoctranslation.h | 59 +++++++----- 5 files changed, 124 insertions(+), 105 deletions(-) diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index f288e7d..40700f2 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -309,13 +309,15 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement, { // read the text, grade, declension and conjugation expr->translation(index)->fromKVTML2(translationElement); + QDomElement currentElement; // - QDomElement currentElement = translationElement.firstChildElement( KVTML_FALSEFRIEND ); - if ( !currentElement.isNull() ) { - int fromid = currentElement.attribute( KVTML_FROMID ).toInt(); - expr->translation(index)->setFalseFriend( fromid, currentElement.text() ); - } + /// @todo false friends +// currentElement = translationElement.firstChildElement( KVTML_FALSEFRIEND ); +// if ( !currentElement.isNull() ) { +// int fromid = currentElement.attribute( KVTML_FROMID ).toInt(); +// expr->translation(index)->setFalseFriend( fromid, currentElement.text() ); +// } // comparisons currentElement = translationElement.firstChildElement( KVTML_COMPARISON ); diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 7b8af38..68cbd21 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -337,18 +337,19 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd // so far only for KEduVocWord - text and grades translation->toKVTML2(translationElement); + ///@todo write false friends // // loop through the identifiers - for ( int i = 0; i < m_doc->identifierCount(); ++i ) { - // see if this identifier has a falsefriend in this translation - QString thisFriend = translation->falseFriend( i ); - if ( !thisFriend.isEmpty() ) { - // if so, create it, and set the fromid to i - QDomElement thisFriendElement = newTextElement( KVTML_FALSEFRIEND, thisFriend ); - thisFriendElement.setAttribute( KVTML_FROMID, QString::number( i ) ); - translationElement.appendChild( thisFriendElement ); - } - } +// for ( int i = 0; i < m_doc->identifierCount(); ++i ) { +// // see if this identifier has a falsefriend in this translation +// QString thisFriend = translation->falseFriend( i ); +// if ( !thisFriend.isEmpty() ) { +// // if so, create it, and set the fromid to i +// QDomElement thisFriendElement = newTextElement( KVTML_FALSEFRIEND, thisFriend ); +// thisFriendElement.setAttribute( KVTML_FROMID, QString::number( i ) ); +// translationElement.appendChild( thisFriendElement ); +// } +// } // comparison if ( !(translation->comparative().isEmpty() || translation->comparative().isEmpty())) { diff --git a/keduvocdocument/keduvockvtmlreader.cpp b/keduvocdocument/keduvockvtmlreader.cpp index 88ca25f..ae86547 100644 --- a/keduvocdocument/keduvockvtmlreader.cpp +++ b/keduvocdocument/keduvockvtmlreader.cpp @@ -1019,18 +1019,22 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) entry->translation( i )->setComment( remark ); if ( !pronunciation.isEmpty() ) entry->translation( i )->setPronunciation( pronunciation ); - if ( !faux_ami_f.isEmpty() ) - entry->translation( i )->setFalseFriend( 0, faux_ami_f ); - if ( !faux_ami_t.isEmpty() ) - entry->translation( 0 )->setFalseFriend( i, faux_ami_t ); - if ( !synonym.isEmpty() ) - entry->translation( i )->setSynonym( synonym ); + + ///@todo include false friends from kvtml-1 again? +// if ( !faux_ami_f.isEmpty() ) +// entry->translation( i )->setFalseFriend( 0, faux_ami_f ); +// if ( !faux_ami_t.isEmpty() ) +// entry->translation( 0 )->setFalseFriend( i, faux_ami_t ); + ///@todo include synonyms from kvtml-1 again? +// if ( !synonym.isEmpty() ) +// entry->translation( i )->setSynonym( synonym ); +// if ( !antonym.isEmpty() ) +// entry->translation( i )->setAntonym( antonym ); + if ( !example.isEmpty() ) entry->translation( i )->setExample( example ); if ( !paraphrase.isEmpty() ) entry->translation( i )->setParaphrase( paraphrase ); - if ( !antonym.isEmpty() ) - entry->translation( i )->setAntonym( antonym ); if ( i != 0 ) { entry->translation( i )->setGrade( grade ); diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 12bf5aa..d72a377 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -42,12 +42,8 @@ public: QString m_hint; /// Paraphrase QString m_paraphrase; - /// A synonyme for a word: sick and ill, student and pupil - QString m_synonym; /// An example QString m_example; - /// An antonym - the opposite: hot - cold - QString m_antonym; /// Pronunciation QString m_pronunciation; /// Image url @@ -67,8 +63,13 @@ public: KEduVocDeclension* m_declension; - /// One false friend string per other language - QMap m_falseFriends; + // connections to other translations + /// Synonyms for a word: sick and ill, student and pupil + QList< KEduVocTranslation* > m_synonyms; + /// An antonym - the opposite: hot - cold + QList< KEduVocTranslation* > m_antonyms; + /// List of false friends + QList< KEduVocTranslation* > m_falseFriends; }; @@ -101,18 +102,20 @@ KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other ) d->m_wordType = other.d->m_wordType; d->m_comment = other.d->m_comment; d->m_paraphrase = other.d->m_paraphrase; - d->m_synonym = other.d->m_synonym; d->m_example = other.d->m_example; - d->m_antonym = other.d->m_antonym; d->m_pronunciation = other.d->m_pronunciation; d->m_conjugations = other.d->m_conjugations; d->m_comparative = other.d->m_comparative; d->m_superlative = other.d->m_superlative; d->m_multipleChoice = other.d->m_multipleChoice; - d->m_falseFriends = other.d->m_falseFriends; d->m_imageUrl = other.d->m_imageUrl; d->m_soundUrl = other.d->m_soundUrl; - /// @todo add declensions + d->m_synonyms = other.d->m_synonyms; + d->m_antonyms = other.d->m_antonyms; + d->m_falseFriends = other.d->m_falseFriends; + if (other.d->m_declension) { + d->m_declension = new KEduVocDeclension(*other.d->m_declension); + } } KEduVocTranslation::~KEduVocTranslation() @@ -124,20 +127,21 @@ KEduVocTranslation::~KEduVocTranslation() bool KEduVocTranslation::operator == ( const KEduVocTranslation & translation ) const { return KEduVocText::operator==(translation) && - d->m_wordType == translation.d->m_wordType && - d->m_comment == translation.d->m_comment && - d->m_paraphrase == translation.d->m_paraphrase && - d->m_synonym == translation.d->m_synonym && - d->m_example == translation.d->m_example && - d->m_antonym == translation.d->m_antonym && - d->m_pronunciation == translation.d->m_pronunciation && - d->m_imageUrl == translation.d->m_imageUrl && - d->m_soundUrl == translation.d->m_soundUrl && - d->m_comparative == translation.d->m_comparative && - d->m_superlative == translation.d->m_superlative && - d->m_multipleChoice == translation.d->m_multipleChoice && - d->m_falseFriends == translation.d->m_falseFriends && - d->m_conjugations == translation.d->m_conjugations; + d->m_wordType == translation.d->m_wordType && + d->m_comment == translation.d->m_comment && + d->m_paraphrase == translation.d->m_paraphrase && + d->m_example == translation.d->m_example && + d->m_pronunciation == translation.d->m_pronunciation && + d->m_imageUrl == translation.d->m_imageUrl && + d->m_soundUrl == translation.d->m_soundUrl && + d->m_comparative == translation.d->m_comparative && + d->m_superlative == translation.d->m_superlative && + d->m_multipleChoice == translation.d->m_multipleChoice && + d->m_synonyms == translation.d->m_synonyms && + d->m_antonyms == translation.d->m_antonyms && + d->m_falseFriends == translation.d->m_falseFriends && + d->m_conjugations == translation.d->m_conjugations; + /// @todo check and include declensions d->m_declension == translation.d->m_declension; } KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & translation ) @@ -147,9 +151,7 @@ KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & d->m_wordType = translation.d->m_wordType; d->m_comment = translation.d->m_comment; d->m_paraphrase = translation.d->m_paraphrase; - d->m_synonym = translation.d->m_synonym; d->m_example = translation.d->m_example; - d->m_antonym = translation.d->m_antonym; d->m_pronunciation = translation.d->m_pronunciation; d->m_imageUrl = translation.d->m_imageUrl; d->m_soundUrl = translation.d->m_soundUrl; @@ -157,7 +159,12 @@ KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & d->m_superlative = translation.d->m_superlative; d->m_multipleChoice = translation.d->m_multipleChoice; d->m_falseFriends = translation.d->m_falseFriends; + d->m_synonyms = translation.d->m_synonyms; + d->m_antonyms = translation.d->m_antonyms; d->m_conjugations = translation.d->m_conjugations; + if (translation.d->m_declension) { + d->m_declension = new KEduVocDeclension(*translation.d->m_declension); + } return *this; } @@ -174,63 +181,63 @@ void KEduVocTranslation::setComment( const QString & expr ) } -void KEduVocTranslation::setFalseFriend( int indexFrom, const QString & expr ) +void KEduVocTranslation::addFalseFriend( KEduVocTranslation* falseFriend ) { - d->m_falseFriends[indexFrom] = expr.simplified(); + d->m_falseFriends.append(falseFriend); } -QString KEduVocTranslation::falseFriend( int indexFrom ) const +QList< KEduVocTranslation* > KEduVocTranslation::falseFriends() const { - return d->m_falseFriends.value( indexFrom ); + return d->m_falseFriends; } -void KEduVocTranslation::setSynonym( const QString & expr ) +void KEduVocTranslation::addSynonym( KEduVocTranslation* synonym ) { - d->m_synonym = expr.simplified(); + d->m_synonyms.append(synonym); } -QString KEduVocTranslation::synonym() const +QList KEduVocTranslation::synonyms() const { - return d->m_synonym; + return d->m_synonyms; } -void KEduVocTranslation::setExample( const QString & expr ) +void KEduVocTranslation::addAntonym( KEduVocTranslation* antonym ) { - d->m_example = expr.simplified(); + d->m_antonyms.append(antonym); } -QString KEduVocTranslation::example() const +QList KEduVocTranslation::antonyms() const { - return d->m_example; + return d->m_antonyms; } -void KEduVocTranslation::setParaphrase( const QString & expr ) +void KEduVocTranslation::setExample( const QString & expr ) { - d->m_paraphrase = expr.simplified(); + d->m_example = expr.simplified(); } -QString KEduVocTranslation::paraphrase() const +QString KEduVocTranslation::example() const { - return d->m_paraphrase; + return d->m_example; } -void KEduVocTranslation::setAntonym( const QString & expr ) +void KEduVocTranslation::setParaphrase( const QString & expr ) { - d->m_antonym = expr.simplified(); + d->m_paraphrase = expr.simplified(); } -QString KEduVocTranslation::antonym() const +QString KEduVocTranslation::paraphrase() const { - return d->m_antonym; + return d->m_paraphrase; } @@ -383,17 +390,14 @@ void KEduVocTranslation::toKVTML2(QDomElement & parent) // KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PRONUNCIATION, pronunciation() ); - // - KEduVocKvtml2Writer::appendTextElement( parent, KVTML_ANTONYM, antonym() ); - - // - KEduVocKvtml2Writer::appendTextElement( parent, KVTML_SYNONYM, synonym() ); - // KEduVocKvtml2Writer::appendTextElement( parent, KVTML_EXAMPLE, example() ); // KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PARAPHRASE, paraphrase() ); + + ///@todo synonyms, antonyms + ///@todo false friends } void KEduVocTranslation::fromKVTML2(QDomElement & parent) @@ -406,19 +410,12 @@ void KEduVocTranslation::fromKVTML2(QDomElement & parent) setPronunciation( parent.firstChildElement( KVTML_PRONUNCIATION ).text() ); - // - setAntonym( parent.firstChildElement( KVTML_ANTONYM ).text() ); - - // - setSynonym( parent.firstChildElement( KVTML_SYNONYM ).text() ); - // setExample( parent.firstChildElement( KVTML_EXAMPLE ).text() ); // setParaphrase( parent.firstChildElement( KVTML_PARAPHRASE ).text() ); - // conjugations QDomElement conjugationElement = parent.firstChildElement( KVTML_CONJUGATION ); while ( !conjugationElement.isNull() ) { @@ -430,5 +427,7 @@ void KEduVocTranslation::fromKVTML2(QDomElement & parent) conjugationElement = conjugationElement.nextSiblingElement( KVTML_CONJUGATION ); } + ///@todo synonyms, antonym + ///@todo false friends } diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index eef8344..1b4b5ea 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -77,29 +77,6 @@ public: */ void setComment( const QString & expr ); - /** sets false friend of this expression - * @param indexFrom index of original translation - * @param expression false friend of this index - */ - void setFalseFriend( int indexFrom, const QString & expression ); - - /** - * returns false friend of this expression - * @param indexFrom index of original translation - * @return false friend or "" if no string available - */ - QString falseFriend( int indexFrom ) const; - - /** sets synonym this expression - * @param expression synonym of this index - */ - void setSynonym( const QString & expression ); - - /** returns synonym of this expression - * @return synonym or "" if no string available - */ - QString synonym() const; - /** sets example this expression * @param expression example of this index */ @@ -221,6 +198,42 @@ public: */ void setImageUrl(const KUrl &url); + /** + * add a false friend + * @param falseFriend false friend of this index + */ + void addFalseFriend( KEduVocTranslation* falseFriend ); + + /** + * returns false friends of this expression + * @return list of false friends + */ + QList falseFriends() const; + + /** + * add a synonym + * @param synonym + */ + void addSynonym( KEduVocTranslation* synonym ); + + /** + * returns synonyms of this expression + * @return synonyms + */ + QList synonyms() const; + + /** + * add a antonym + * @param antonym + */ + void addAntonym( KEduVocTranslation* antonym ); + + /** + * returns antonyms of this expression + * @return antonyms + */ + QList antonyms() const; + /** * Equal operator to assing a translation to another one. * @param translation translation to be copied -- 2.47.3