export a KEduVocDocument to a KVTML file
-----------------------------------------------------------------------
copyright : (C) 2007 Jeremy Whiting <jeremy@scitools.com>
- (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
+ (C) 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
***************************************************************************/
/***************************************************************************
domElementKvtml.appendChild( currentElement );
}
+ writeSynonymAntonymFalseFriend(domElementKvtml);
+
m_domDoc.appendChild( domElementKvtml );
QTextStream ts( m_outputFile );
}
+
+void KEduVocKvtml2Writer::writeSynonymAntonymFalseFriend(QDomElement & parentElement)
+{
+ // synonym, antonym, false friend
+ QDomElement synonymElement = m_domDoc.createElement( KVTML_SYNONYM );
+kDebug() << "writing list of synonyms: " << m_synonyms.count();
+ while (!m_synonyms.isEmpty()) {
+ // after writing a translation, remove it from the list
+ KEduVocTranslation* translation = m_synonyms.takeAt(0);
+
+ // fill the entry element but only add later if it is valid
+ QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
+ entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(translation->entry())) );
+ // find out which id that is... silly
+ foreach(int index, translation->entry()->translationIndices()) {
+ if (translation->entry()->translation(index) == translation) {
+ // create <translation id="123">
+ QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
+ translationElement.setAttribute( KVTML_ID, QString::number(index) );
+ entryElement.appendChild(translationElement);
+ break;
+ }
+ }
+
+
+ QDomElement relatedElement;
+ foreach (KEduVocTranslation* synonym, translation->synonyms()) {
+ // if it is not in the list it has already been written and we can move on
+ if (m_synonyms.contains(synonym)) {
+ relatedElement = m_domDoc.createElement( KVTML_PAIR );
+ synonymElement.appendChild(relatedElement);
+ relatedElement.appendChild(entryElement);
+
+
+ entryElement = m_domDoc.createElement( KVTML_ENTRY );
+ entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(synonym->entry())) );
+
+ // find out which id that is
+ foreach(int index, synonym->entry()->translationIndices()) {
+ if (synonym->entry()->translation(index) == synonym) {
+ // create <translation id="123">
+ QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
+ translationElement.setAttribute( KVTML_ID, QString::number(index) );
+ entryElement.appendChild(translationElement);
+ break;
+ }
+ }
+ relatedElement.appendChild( entryElement );
+ }
+ if (relatedElement.hasChildNodes()) {
+ synonymElement.appendChild( relatedElement );
+ }
+ }
+ }
+ if (synonymElement.hasChildNodes()) {
+ parentElement.appendChild( synonymElement );
+ }
+}
+/*
+bool KEduVocKvtml2Writer::writeRelated(QDomElement & parentElement, QList< KEduVocTranslation * > relatedList)
+{
+ foreach (KEduVocTranslation* synonym, translation->synonyms()) {
+ QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
+ entryElement.setAttribute( KVTML_ID, QString::number(m_allEntries.indexOf(translation->entry())) );
+
+ // find out which id that is... silly
+ foreach(int index, translation->entry()->translationIndices()) {
+ if (translation->entry()->translation(index) == translation) {
+ // create <translation id="123">
+ QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
+ translationElement.setAttribute( KVTML_ID, QString::number(index) );
+ entryElement.appendChild(translationElement);
+ }
+ }
+ parentElement.appendChild( entryElement );
+ }
+}*/
+
bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int language )
{
///@todo only write if not empty
// so far only for KEduVocWord - text and grades
translation->toKVTML2(translationElement);
- ///@todo write false friends
- // <falsefriend fromid="0"></falsefriend>
- // 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 );
-// }
-// }
-
// comparison
if ( !(translation->comparative().isEmpty() || translation->comparative().isEmpty())) {
QDomElement comparisonElement = m_domDoc.createElement( KVTML_COMPARISON );
translationElement.appendChild( newTextElement( KVTML_SOUND, urlString ) );
}
+
+ // synonym, antonym, false friend
+ // add to the list if it has any, write later since we want them seperate
+ if (!translation->synonyms().isEmpty()) {
+ m_synonyms.append(translation);
+ }
+ if (!translation->antonyms().isEmpty()) {
+ m_antonyms.append(translation);
+ }
+ if (!translation->falseFriends().isEmpty()) {
+ m_falseFriends.append(translation);
+ }
return true;
}
+
+
+ ///@todo write false friends
+ // <falsefriend fromid="0"></falsefriend>
+ // 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 );
+// }
+// }
+
+
+
+
+
+
bool KEduVocKvtml2Writer::writeComparison( QDomElement &comparisonElement, KEduVocTranslation* translation )
/*
<comparison>
export a KEduVocDocument to a KVTML file
-----------------------------------------------------------------------
copyright : (C) 2007 Jeremy Whiting <jeremy@scitools.com>
- (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
+ (C) 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
***************************************************************************/
/***************************************************************************
bool writeDoc( KEduVocDocument *doc, const QString &generator );
+ /**
+ * Helper function, appends a new element AND a text child to @p parent
+ * Only appends if @p text is NOT empty.
+ * @param parent
+ * @param elementName
+ * @param text
+ */
+ static void appendTextElement( QDomElement &parent, const QString &elementName, const QString &text );
+
+private:
/** write information entries
* @param informationElement QDomElement information to write to
* @param generator text describing generator
*/
bool writeTenses( QDomElement &tensesElement );
- /** write usages
- * @param usagesElement QDomElement usages to write to
- */
- bool writeUsages( QDomElement &usagesElement );
-
/** write entries
* @param entriesElement QDomElement entries to write to
*/
*/
bool writeTranslation( QDomElement &translationElement, KEduVocTranslation* translation );
+ /**
+ * Used to write synonym, antonym and false friend lists
+ * @param typesElement
+ * @param parentContainer
+ * @return
+ */
+ bool writeRelated( QDomElement &parentElement, QList<KEduVocTranslation*> relatedList );
+
/** write the lesson group
* @param parentLesson the parent lesson of the current lesson
* @param lessonsElement QDomElement lessons to write to
*/
bool writeLessons( KEduVocLesson *parentLesson, QDomElement &lessonsElement );
+
+ void writeSynonymAntonymFalseFriend(QDomElement & parentElement);
+
/** write a comparison
* @param comparisonElement QDomElement comparison to write to
* @param comparison object to write
*/
bool writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation* translation );
- /**
- * Helper function, appends a new element AND a text child to @p parent
- * Only appends if @p text is NOT empty.
- * @param parent
- * @param elementName
- * @param text
- */
- static void appendTextElement( QDomElement &parent, const QString &elementName, const QString &text );
-
-private:
QDomElement newTextElement( const QString &elementName, const QString &text );
QFile *m_outputFile;
KEduVocDocument *m_doc;
QList<KEduVocExpression*> m_allEntries;
+ QList<KEduVocTranslation*> m_synonyms;
+ QList<KEduVocTranslation*> m_antonyms;
+ QList<KEduVocTranslation*> m_falseFriends;
QDomDocument m_domDoc;
};