From: Jeremy Paul Whiting Date: Sat, 21 Jul 2007 06:07:04 +0000 (+0000) Subject: read most of translation parts excluding falsefriends and grades for now, also read... X-Git-Tag: v3.92.0~21 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=d6524061545b3202a6e0cf5cb7c77e0d820c43a4;p=libqmvoc.git read most of translation parts excluding falsefriends and grades for now, also read conjugation reads the conjugation type, and readComparison is done also svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=690454 --- diff --git a/kdeeducore/keduvockvtml2reader.cpp b/kdeeducore/keduvockvtml2reader.cpp index 0102426..419566f 100644 --- a/kdeeducore/keduvockvtml2reader.cpp +++ b/kdeeducore/keduvockvtml2reader.cpp @@ -274,9 +274,8 @@ bool KEduVocKvtml2Reader::readIdentifier(QDomElement &identifierElement) if (!currentElement.isNull()) { KEduVocConjugation personalPronouns; - readConjug(currentElement, personalPronouns); + readConjugation(currentElement, personalPronouns); m_doc->setConjugation(id, personalPronouns); - // TODO: do something with these personalpronouns } return result; } @@ -375,144 +374,141 @@ bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement, { expr.translation(index).setType(currentElement.text()); } + + currentElement = translationElement.firstChildElement(KVTML_INQUERY); + if (!currentElement.isNull()) + { + // TODO: ask fregl what inquery is for, and do something with it + } -// kvtml 1: we always have an original element (required) -// currentElement = domElementParent.firstChildElement(KV_ORG); -// if (currentElement.isNull()) { // sanity check -// m_errorMessage = i18n("Data for original language missing"); -// return false; -// } + // + currentElement = translationElement.firstChildElement(KVTML_PRONUNCIATION); + if (!currentElement.isNull()) + { + expr.translation(index).setPronunciation(currentElement.text()); + } + + // + currentElement = translationElement.firstChildElement(KVTML_FALSEFRIENDFROM); + if (!currentElement.isNull()) + { + // TODO: figure out what to do with falsefriend information + } -// while (!currentElement.isNull()) { -// type = exprtype; // seems like type can be in the parent element and overwritten in the children here :( + // + currentElement = translationElement.firstChildElement(KVTML_FALSEFRIENDTO); + if (!currentElement.isNull()) + { + } -// //----------- -// // Attributes -// //----------- + // + currentElement = translationElement.firstChildElement(KVTML_FALSEFRIEND); + if (!currentElement.isNull()) + { + // TODO: figure out what to do with falsefriend information + } -// // read attributes - the order of the query grades is interchanged! -// if (i == 0 && !readExpressionChildAttributes( currentElement, lang, grade, r_grade, qcount, r_qcount, qdate, r_qdate, remark, bcount, r_bcount, query_id, -// pronunciation, width, type, faux_ami_t, faux_ami_f, synonym, example, antonym, usage, paraphrase)) -// return false; + // + currentElement = translationElement.firstChildElement(KVTML_ANTONYM); + if (!currentElement.isNull()) + { + // TODO: figure out what to do with falsefriend information + } -// if (i != 0 && !readExpressionChildAttributes( currentElement, lang, grade, r_grade, qcount, r_qcount, qdate, r_qdate, remark, bcount, r_bcount, query_id, -// pronunciation, width, type, faux_ami_f, faux_ami_t, synonym, example, antonym, usage, paraphrase)) -// return false; + // + currentElement = translationElement.firstChildElement(KVTML_SYNONYM); + if (!currentElement.isNull()) + { + expr.translation(index).setSynonym(currentElement.text()); + } -// if (m_doc->entryCount() == 0) -// { -// // only accept in first entry -// if (width >= 0) -// m_doc->setSizeHint(i, width); + // + currentElement = translationElement.firstChildElement(KVTML_EXAMPLE); + if (!currentElement.isNull()) + { + expr.translation(index).setExample(currentElement.text()); + } -// if (query_id == KV_O) -// q_org = lang; + // + currentElement = translationElement.firstChildElement(KVTML_USAGE); + if (!currentElement.isNull()) + { + expr.translation(index).setUsageLabel(currentElement.text()); + } -// if (query_id == KV_T) + // + currentElement = translationElement.firstChildElement(KVTML_PARAPHRASE); + if (!currentElement.isNull()) + { + expr.translation(index).setParaphrase(currentElement.text()); + } -// q_trans = lang; -// } -////kDebug() << " TranslationList.count(): " << translationList.count() << " Entry count: " << m_doc->entryCount() << endl; -// if (m_doc->entryCount() == 0) { // this is because in kvtml the languages are saved in the FIRST ENTRY ONLY. -//kDebug() << " Read Expression with identifiers: " << i << endl; -// // new translation -// if (lang.isEmpty()) { -// if (i == 0) { -// lang = "original"; -// } else { -// // no definition in first entry ? -// lang.setNum(m_doc->identifierCount()); -// lang.prepend("translation "); -// } -// m_doc->appendIdentifier(lang); -// } -// } -// else -// { -// if (lang != m_doc->identifier(i) && !lang.isEmpty()) -// { -// // different language ? -// m_errorMessage = i18n("ambiguous definition of language code"); -// return false; -// } -// } + // conjugations + currentElement = translationElement.firstChildElement(KVTML_CONJUGATION); + KEduVocConjugation conjugation; + while (!currentElement.isNull()) + { + // read any conjugations (NOTE: this will overwrite any conjugations of the same type for this + // translation, as the type is used as the key + readConjugation(currentElement, conjugation); + currentElement = currentElement.nextSiblingElement(KVTML_CONJUGATION); + } + if (conjugation.entryCount() > 0) + { + expr.translation(index).setConjugation(conjugation); + } -// //--------- -// // Children + // comparisons + currentElement = translationElement.firstChildElement(KVTML_COMPARISON); + if (!currentElement.isNull()) + { + KEduVocComparison comparison; + readComparison(currentElement, comparison); + expr.translation(index).setComparison(comparison); + } -// currentChild = currentElement.firstChildElement(KV_CONJUG_GRP); -// if (!currentChild.isNull()) { -// conjug.clear(); -// if (!readConjug(currentChild, conjug)) -// return false; -// } + // multiple choice + currentElement = translationElement.firstChildElement(KVTML_MULTIPLECHOICE); + if (!currentElement.isNull()) + { + KEduVocMultipleChoice mc; + readMultipleChoice(currentElement, mc); + expr.translation(index).setMultipleChoice(mc); + } -// currentChild = currentElement.firstChildElement(KV_COMPARISON_GRP); -// if (!currentChild.isNull()) { -// comparison.clear(); -// if (!readComparison(currentChild, comparison)) -// return false; -// } + // image + currentElement = translationElement.firstChildElement(KVTML_IMAGE); + if (!currentElement.isNull()) + { + // TODO: do something with the image + } -// currentChild = currentElement.firstChildElement(KV_MULTIPLECHOICE_GRP); -// if (!currentChild.isNull()) { -// mc.clear(); -// if (!readMultipleChoice(currentChild, mc)) -// return false; -// } + // sound + currentElement = translationElement.firstChildElement(KVTML_SOUND); + if (!currentElement.isNull()) + { + // TODO: do something with the sound + } -// textstr = currentElement.lastChild().toText().data(); -// if (textstr.isNull()) -// textstr = ""; - -// if (i == 0) { -// expr = KEduVocExpression(textstr); -// expr.setLesson(lesson); -// expr.setInQuery(inquery); -// expr.setActive(active); -// } else { -// expr.setTranslation(i, textstr); -// } + // grade + currentElement = translationElement.firstChildElement(KVTML_GRADE); + if (!currentElement.isNull()) + { + // TODO: read grade + } + +// if (query_id == KV_O) +// q_org = lang; + +// if (query_id == KV_T) + +// q_trans = lang; -// if (conjug.size() > 0) { -// for ( int conjugationIndex = 0; conjugationIndex < conjug.size(); conjugationIndex++ ) { -// expr.translation(i).setConjugation(conjug[conjugationIndex]); -// } -// //expr.setConjugation(i, conjug[0]); ///@todo check if this is better than the above! -// conjug.clear(); -// } -// if (!comparison.isEmpty()) -// { -// expr.translation(i).setComparison(comparison); -// comparison.clear(); -// } -// if (!mc.isEmpty()) -// { -// expr.translation(i).setMultipleChoice(mc); -// mc.clear(); -// } -// if (!type.isEmpty() ) -// expr.translation(i).setType (type); -// if (!remark.isEmpty() ) -// expr.translation(i).setComment (remark); -// if (!pronunciation.isEmpty() ) -// expr.translation(i).setPronunciation(pronunciation); // if (!faux_ami_f.isEmpty() ) // expr.translation(i).setFalseFriend (0, faux_ami_f); // if (!faux_ami_t.isEmpty() ) // expr.translation(0).setFalseFriend (i, faux_ami_t); -// if (!synonym.isEmpty() ) -// expr.translation(i).setSynonym (synonym); -// if (!example.isEmpty() ) -// expr.translation(i).setExample (example); -// if (!usage.isEmpty() ) -// expr.translation(i).setUsageLabel (usage); -// if (!paraphrase.isEmpty() ) -// expr.translation(i).setParaphrase (paraphrase); -// if (!antonym.isEmpty() ) -// expr.translation(i).setAntonym (antonym); - // if ( i != 0 ) { // expr.translation(i).gradeFrom(0).setQueryCount(qcount); // expr.translation(0).gradeFrom(i).setQueryCount(r_qcount); @@ -669,7 +665,7 @@ bool KEduVocKvtml2Reader::readArticle(QDomElement &articleElement, int identifie } -bool KEduVocKvtml2Reader::readConjug(QDomElement &conjugElement, KEduVocConjugation &curr_conjug) +bool KEduVocKvtml2Reader::readConjugation(QDomElement &conjugElement, KEduVocConjugation &curr_conjug) /* @@ -704,6 +700,12 @@ bool KEduVocKvtml2Reader::readConjug(QDomElement &conjugElement, KEduVocConjugat QString plurthirdfemale; QString plurthirdneutral; QString type; + + QDomElement typeElement = conjugElement.firstChildElement(KVTML_TYPE); + if (!typeElement.isNull()) + { + type = typeElement.text(); + } QDomElement currentGroup = conjugElement.firstChildElement(KVTML_SINGULAR); if (!currentGroup.isNull()) @@ -883,39 +885,29 @@ bool KEduVocKvtml2Reader::readUsages(QDomElement &usagesElement) bool KEduVocKvtml2Reader::readComparison(QDomElement &domElementParent, KEduVocComparison &comp) /* - good - better - best + good + better + best */ { - QString s; - comp.clear(); - QDomElement currentElement; - currentElement = domElementParent.firstChildElement(KV_COMP_L1); + currentElement = domElementParent.firstChildElement(KVTML_ABSOLUTE); if (!currentElement.isNull()) { - s = currentElement.text(); - if (s.isNull()) - s = ""; - comp.setL1(s); + comp.setL1(currentElement.text()); } - currentElement = domElementParent.firstChildElement(KV_COMP_L2); - if (!currentElement.isNull()) { - s = currentElement.text(); - if (s.isNull()) - s = ""; - comp.setL2(s); + currentElement = domElementParent.firstChildElement(KVTML_COMPARATIVE); + if (!currentElement.isNull()) + { + comp.setL2(currentElement.text()); } - currentElement = domElementParent.firstChildElement(KV_COMP_L3); - if (!currentElement.isNull()) { - s = currentElement.text(); - if (s.isNull()) - s = ""; - comp.setL3(s); + currentElement = domElementParent.firstChildElement(KVTML_SUPERLATIVE); + if (!currentElement.isNull()) + { + comp.setL3(currentElement.text()); } return true; } diff --git a/kdeeducore/keduvockvtml2reader.h b/kdeeducore/keduvockvtml2reader.h index 6e243b0..17b5916 100644 --- a/kdeeducore/keduvockvtml2reader.h +++ b/kdeeducore/keduvockvtml2reader.h @@ -67,7 +67,7 @@ public: * @param conjugElement QDomElement for the conjugation group * @param curr_conjug conjugation object to populate */ - bool readConjug(QDomElement &conjugElement, KEduVocConjugation &curr_conjug); + bool readConjugation(QDomElement &conjugElement, KEduVocConjugation &curr_conjug); /** read the types * @param typesElement QDomElement for the types group @@ -94,7 +94,16 @@ public: */ bool readTranslation(QDomElement &translationElement, KEduVocExpression &expr, int index); + /** read a comparison + * @param comparisonElement comparison group element + * @param comp comparison object to read into + */ bool readComparison(QDomElement &comparisonElement, KEduVocComparison &comp); + + /** read a multiple choice group + * @param multipleChoiceElement element to read from + * @param mc KEduVocMultipleChoice object to read to + */ bool readMultipleChoice(QDomElement &multipleChoiceElement, KEduVocMultipleChoice &mc); bool readGrade(QDomElement &gradeElement); diff --git a/kdeeducore/kvtml2defs.h b/kdeeducore/kvtml2defs.h index 3fa33fe..d20cb17 100644 --- a/kdeeducore/kvtml2defs.h +++ b/kdeeducore/kvtml2defs.h @@ -80,15 +80,15 @@ #define KVTML_PARAPHRASE "paraphrase" #define KVTML_COMPARISON "comparison" -#define KVTML_ABS "absolute" -#define KVTML_COMP "comparative" -#define KVTML_SUPER "superlative" +#define KVTML_ABSOLUTE "absolute" +#define KVTML_COMPARATIVE "comparative" +#define KVTML_SUPERLATIVE "superlative" -#define KVTML_MULTI "multiplechoice" +#define KVTML_MULTIPLECHOICE "multiplechoice" #define KVTML_CHOICE "choice" -#define KVTML_IMG "image" -#define KVTML_SND "sound" +#define KVTML_IMAGE "image" +#define KVTML_SOUND "sound" #define KVTML_GRADE "grade" #define KVTML_CURRENTGRADE "currentgradeint" diff --git a/kdeeducore/kvtml2todo b/kdeeducore/kvtml2todo index 2b095f6..fa91a77 100644 --- a/kdeeducore/kvtml2todo +++ b/kdeeducore/kvtml2todo @@ -2,9 +2,9 @@ Temporary todo for kvtml2 reader: read lessons - read translations - read translation sub-parts - store identifier sub-parts + read falsefriend tags + read grades + store identifier name, sizehint and type? (need a place to store it first) writer: everything diff --git a/kdeeducore/kvtml_empty_sample.kvtml b/kdeeducore/kvtml_empty_sample.kvtml index 15f8d59..60f0023 100644 --- a/kdeeducore/kvtml_empty_sample.kvtml +++ b/kdeeducore/kvtml_empty_sample.kvtml @@ -104,9 +104,9 @@ - gut - besser - am besten + gut + besser + am besten