From: Jeremy Paul Whiting Date: Thu, 12 Jul 2007 17:41:13 +0000 (+0000) Subject: updated reader can read entries group entry items translations so far X-Git-Tag: v3.92.0~35 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=c895f8d35f1209737ec472050995f80967a01675;p=libqmvoc.git updated reader can read entries group entry items translations so far svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=687009 --- diff --git a/kdeeducore/animals2.kvtml b/kdeeducore/animals2.kvtml deleted file mode 100644 index 46124de..0000000 --- a/kdeeducore/animals2.kvtml +++ /dev/null @@ -1,177 +0,0 @@ - - - - - kanagram - Animals - Animals from across the planet - - - - - language - en - bear - Large heavy animal with thick fur - 150 - - - - dolphin - Sea mammal - - - African animal with black and white stripes - zebra - - - Australian jumping animal - kangaroo - - - Very large sea mammal - whale - - - Four-legged animal used for riding - horse - - - Closely related to humans - monkey - - - Bird that drills through wood - woodpecker - - - Reptile with no legs - snake - - - Long-necked African animal - giraffe - - - Largest living land animal with a trunk - elephant - - - Small rodent with a long tail - mouse - - - Animal with no backbone or limbs - worm - - - Large insect with transparent wings - dragonfly - - - Sea bird of the Antarctic regions - penguin - - - Burrowing animal with long ears - rabbit - - - Small mouse-like rodent, kept as pets - hamster - - - Fierce, wild animal of the dog family - wolf - - - Large, powerful animal of the cat family - lion - - - Large Asian animal of the cat family - tiger - - - Sea animal with eight long tentacles - octopus - - - Large, thick-skinned animal of Africa - rhinoceros - - - Small, with a back covered in stiff spines - hedgehog - - - Deer with large antlers - reindeer - - - Small tree-climbing animal with a bushy tail - squirrel - - - A slow-moving, four-footed reptile - tortoise - - - Large African river animal - hippopotamus - - - Extinct reptile - dinosaur - - - Large bird of prey - eagle - - - Large sea fish with a triangular fin - shark - - - Swimming bird - duck - - - Live in water - fish - - - Can repeat your words - parrot - - - Small green jumping animal - frog - - - Slow-moving, has a spiral shell - snail - - - Can survive a long time in the desert - camel - - - Reptile of the crocodile family - alligator - - - Its bite spreads malaria - mosquito - - - Grass-eating animal with a thick fleecy coat - sheep - - - Water animal that has a shell - shellfish - - - - diff --git a/kdeeducore/keduvockvtml2reader.cpp b/kdeeducore/keduvockvtml2reader.cpp index 75fc95d..a8a9dd3 100644 --- a/kdeeducore/keduvockvtml2reader.cpp +++ b/kdeeducore/keduvockvtml2reader.cpp @@ -41,8 +41,6 @@ KEduVocKvtml2Reader::KEduVocKvtml2Reader(QIODevice *file) bool KEduVocKvtml2Reader::readDoc(KEduVocDocument *doc) { m_doc = doc; - m_cols = 0; - m_lines = 0; QDomDocument domDoc("KEduVocDocument"); @@ -79,46 +77,8 @@ bool KEduVocKvtml2Reader::readDoc(KEduVocDocument *doc) QDomElement info = domElementKvtml.firstChildElement(KVTML_INFORMATION); if (!info.isNull()) { - // read the generator - QDomElement generator = info.firstChildElement(KVTML_GENERATOR); - if (!generator.isNull()) - { - m_doc->setGenerator(generator.text()); - // add the version if it's there - int pos = m_doc->generator().lastIndexOf(KVD_VERS_PREFIX); - if (pos >= 0) - { - m_doc->setVersion(m_doc->generator().remove(0, pos + 2)); - } - } - - // read the title - QDomElement title = info.firstChildElement(KVTML_TITLE); - if (!title.isNull()) - { - m_doc->setTitle(title.text()); - } - - // read the comment - QDomElement comment = info.firstChildElement(KVTML_COMMENT); - if (!comment.isNull()) - { - m_doc->setDocumentRemark(comment.text()); - } - - // read the author - QDomElement author = info.firstChildElement(KVTML_AUTHOR); - if (!author.isNull()) - { - m_doc->setAuthor(author.text()); - } - - // read the license - QDomElement license = info.firstChildElement(KVTML_LICENSE); - if (!license.isNull()) - { - m_doc->setLicense(license.text()); - } + if (!readInformation(info)) + return false; } @@ -131,37 +91,106 @@ bool KEduVocKvtml2Reader::readDoc(KEduVocDocument *doc) // Children //------------------------------------------------------------------------- - bool result = readBody(domElementKvtml); // read vocabulary + bool result = readGroups(domElementKvtml); // read vocabulary return result; } +bool KEduVocKvtml2Reader::readInformation(QDomElement &informationElement) +{ + // read the generator + QDomElement currentElement = informationElement.firstChildElement(KVTML_GENERATOR); + if (!currentElement.isNull()) + { + m_doc->setGenerator(currentElement.text()); + // add the version if it's there + int pos = m_doc->generator().lastIndexOf(KVD_VERS_PREFIX); + if (pos >= 0) + { + m_doc->setVersion(m_doc->generator().remove(0, pos + 2)); + } + } + + // read the title + currentElement = informationElement.firstChildElement(KVTML_TITLE); + if (!currentElement.isNull()) + { + m_doc->setTitle(currentElement.text()); + } + + // read the author + currentElement = informationElement.firstChildElement(KVTML_AUTHOR); + if (!currentElement.isNull()) + { + m_doc->setAuthor(currentElement.text()); + } + + // read the license + currentElement = informationElement.firstChildElement(KVTML_LICENSE); + if (!currentElement.isNull()) + { + m_doc->setLicense(currentElement.text()); + } -bool KEduVocKvtml2Reader::readBody(QDomElement &domElementParent) + // read the comment + currentElement = informationElement.firstChildElement(KVTML_COMMENT); + if (!currentElement.isNull()) + { + m_doc->setDocumentRemark(currentElement.text()); + } + + return true; +} + +bool KEduVocKvtml2Reader::readGroups(QDomElement &domElementParent) { bool result = false; - QDomElement identifiers = domElementParent.firstChildElement(KVTML_IDENTIFIERS); QDomElement currentElement; - if (!identifiers.isNull()) + QDomElement groupElement = domElementParent.firstChildElement(KVTML_IDENTIFIERS); + if (!groupElement.isNull()) { - QDomNodeList entryList = identifiers.elementsByTagName(KVTML_IDENTIFIER); + QDomNodeList entryList = groupElement.elementsByTagName(KVTML_IDENTIFIER); if (entryList.length() <= 0) + { + m_errorMessage = i18n("missing identifiers"); return false; + } for (int i = 0; i < entryList.count(); ++i) { currentElement = entryList.item(i).toElement(); - if (currentElement.parentNode() == identifiers) + if (currentElement.parentNode() == groupElement) { - result = readExpression(currentElement); + result = readIdentifier(currentElement); if (!result) return false; } } } + groupElement = domElementParent.firstChildElement(KVTML_ENTRIES); + if (!groupElement.isNull()) + { + QDomNodeList entryList = groupElement.elementsByTagName(KVTML_ENTRY); + if (entryList.length() <= 0) + { + m_errorMessage = i18n("no entries found"); + return false; // at least one entry is required + } + + for (int i = 0; i < entryList.count(); ++i) + { + currentElement = entryList.item(i).toElement(); + if (currentElement.parentNode() == groupElement) + { + result = readEntry(currentElement); + if (!result) + return false; + } + } + } // old code for kvtml //QDomElement currentElement; @@ -222,9 +251,237 @@ bool KEduVocKvtml2Reader::readBody(QDomElement &domElementParent) // return false; //} + return true; +} + +bool KEduVocKvtml2Reader::readIdentifier(QDomElement &identifierElement) +{ + bool result = true; + int id = identifierElement.attribute(KVTML_ID).toInt(&result); + if (!result) + { + m_errorMessage = i18n("identifier missing id"); + return false; + } + + QDomElement currentElement = identifierElement.firstChildElement(KVTML_TYPE); + if (!currentElement.isNull()) + { + + } return result; } +bool KEduVocKvtml2Reader::readEntry(QDomElement &entryElement) +{ + KEduVocExpression expr; + QDomElement currentElement; + bool result = true; + + // get entry id + + // read info tags: inactive, inquery, and sizehint + + // read translation children + QDomNodeList translationList = entryElement.elementsByTagName(KVTML_TRANSLATION); + if (translationList.length() <= 0) + { + m_errorMessage = i18n("no translations found"); + return false; // at least one entry is required + } + + for (int i = 0; i < translationList.count(); ++i) + { + currentElement = translationList.item(i).toElement(); + if (currentElement.parentNode() == entryElement) + { + result = readTranslation(currentElement, expr, i); + if (!result) + return false; + } + } + + m_doc->appendEntry(&expr); + return result; +} + +bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement, + KEduVocExpression &expr, int index) +{ + QDomElement currentElement = translationElement.firstChildElement(KVTML_TEXT); + if (!currentElement.isNull()) + { + expr.translation(index).setTranslation(currentElement.text()); + } + + currentElement = translationElement.firstChildElement(KVTML_COMMENT); + if (!currentElement.isNull()) + { + expr.translation(index).setComment(currentElement.text()); + } + + currentElement = translationElement.firstChildElement(KVTML_TYPE); + if (!currentElement.isNull()) + { + expr.translation(index).setType(currentElement.text()); + } + +// 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; +// } + +// while (!currentElement.isNull()) { +// type = exprtype; // seems like type can be in the parent element and overwritten in the children here :( + +// //----------- +// // Attributes +// //----------- + +// // 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; + +// 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; + +// if (m_doc->entryCount() == 0) +// { +// // only accept in first entry +// if (width >= 0) +// m_doc->setSizeHint(i, width); + +// if (query_id == KV_O) +// q_org = lang; + +// if (query_id == KV_T) + +// 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; +// } +// } + +// //--------- +// // Children + +// currentChild = currentElement.firstChildElement(KV_CONJUG_GRP); +// if (!currentChild.isNull()) { +// conjug.clear(); +// if (!readConjug(currentChild, conjug)) +// return false; +// } + +// currentChild = currentElement.firstChildElement(KV_COMPARISON_GRP); +// if (!currentChild.isNull()) { +// comparison.clear(); +// if (!readComparison(currentChild, comparison)) +// return false; +// } + +// currentChild = currentElement.firstChildElement(KV_MULTIPLECHOICE_GRP); +// if (!currentChild.isNull()) { +// mc.clear(); +// if (!readMultipleChoice(currentChild, mc)) +// return false; +// } + +// 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); +// } + +// 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); +// expr.translation(i).gradeFrom(0).setBadCount(bcount); +// expr.translation(0).gradeFrom(i).setBadCount(r_bcount); +// expr.translation(i).gradeFrom(0).setQueryDate(qdate); +// expr.translation(0).gradeFrom(i).setQueryDate(r_qdate); +// } +////kDebug() << "KEduVocKvtml2Reader::readExpression(): id: " << i << " translation: " << textstr << endl; + +// // Next translation +// currentElement = currentElement.nextSiblingElement(KV_TRANS); +// i++; +// } + + //if (m_doc->entryCount() == 0) + // m_doc->setQueryIdentifier(q_org, q_trans); + return true; +} bool KEduVocKvtml2Reader::readLesson(QDomElement &domElementParent) { @@ -1057,298 +1314,5 @@ bool KEduVocKvtml2Reader::readExpressionChildAttributes( QDomElement &domElement } -bool KEduVocKvtml2Reader::readExpression(QDomElement &expressionElement) -{ - //grade_t grade; - //grade_t r_grade; - //int qcount; - //int r_qcount; - //int bcount; - //int r_bcount; - QString comment; - //QString pronunciation; - //QDateTime qdate; - //QDateTime r_qdate; - //bool inquery; - //bool active; - //QString lang; - QString textstr; - //QString exprtype; - //QString q_org; - //QString q_trans; - //QString query_id; - //int lesson = 0; - //int width; - //QString type; - //QString faux_ami_f; - //QString faux_ami_t; - //QString synonym; - //QString example; - //QString antonym; - //QString usage; - //QString paraphrase; - //QList conjug; - //KEduVocComparison comparison; - //KEduVocMultipleChoice mc; - KEduVocExpression expr; - - QDomAttr attribute; - QDomElement currentElement; - QDomElement currentChild; - - //------------------------------------------------------------------------- - // Attributes - //------------------------------------------------------------------------- - - //attribute = domElementParent.attributeNode(KV_LESS_MEMBER); - //if (!attribute.isNull()) - // lesson = attribute.value().toInt(); - - //if (lesson && lesson > m_doc->lessonDescriptions().count()) - //{ - // // description missing ? - // QString s; - // QStringList sl = m_doc->lessonDescriptions(); - // for (int i = m_doc->lessonDescriptions().count(); i < lesson; i++) - // { - // s.setNum(i + 1); - // s.prepend("#"); //create descriptions from number - // sl.append(s); - // } - // m_doc->setLessonDescriptions(sl); - //} - - //attribute = domElementParent.attributeNode(KV_SELECTED); - //if (!attribute.isNull()) - // inquery = attribute.value() == "1" ? true : false; - //else - // inquery = false; - - //attribute = domElementParent.attributeNode(KV_INACTIVE); - //if (!attribute.isNull()) - // active = attribute.value() == "1" ? false : true; - //else - // active = true; - - //attribute = domElementParent.attributeNode(KV_EXPRTYPE); - //if (!attribute.isNull()) - //{ - // exprtype = attribute.value(); - // if (exprtype == "1") - // exprtype = QM_VERB; - // else if (exprtype == "2") // convert from pre-0.5 versions - // exprtype = QM_NOUN; - // else if (exprtype == "3") - // exprtype = QM_NAME; - - // if (exprtype.length() != 0 && exprtype.left(1) == QM_USER_TYPE) - // { - // int num = qMin(exprtype.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); - // } - // } - //} - - //------------------------------------------------------------------------- - // Children 'Translation' - //------------------------------------------------------------------------- - - //QDomNodeList translationList = domElementParent.elementsByTagName(KV_TRANS); - - // count which translation we are on - int i=0; - - currentElement = expressionElement.firstChildElement(KVTML_NAME); - if (!currentElement.isNull()) - { - expr = KEduVocExpression(currentElement.text()); - } - - currentElement = expressionElement.firstChildElement(KVTML_COMMENT); - if (!currentElement.isNull()) - { - expr.translation(0).setComment(currentElement.text()); - } - - currentElement = expressionElement.firstChildElement(KVTML_TYPE); - if (!currentElement.isNull()) - { - expr.translation(0).setType(currentElement.text()); - } - - currentElement = expressionElement.firstChildElement(KVTML_LOCALE); - if (!currentElement.isNull()) - { - } - - // 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; -// } - -// while (!currentElement.isNull()) { -// type = exprtype; // seems like type can be in the parent element and overwritten in the children here :( - -// //----------- -// // Attributes -// //----------- - -// // 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; - -// 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; - -// if (m_doc->entryCount() == 0) -// { -// // only accept in first entry -// if (width >= 0) -// m_doc->setSizeHint(i, width); - -// if (query_id == KV_O) -// q_org = lang; - -// if (query_id == KV_T) - -// 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; -// } -// } - -// //--------- -// // Children - -// currentChild = currentElement.firstChildElement(KV_CONJUG_GRP); -// if (!currentChild.isNull()) { -// conjug.clear(); -// if (!readConjug(currentChild, conjug)) -// return false; -// } - -// currentChild = currentElement.firstChildElement(KV_COMPARISON_GRP); -// if (!currentChild.isNull()) { -// comparison.clear(); -// if (!readComparison(currentChild, comparison)) -// return false; -// } - -// currentChild = currentElement.firstChildElement(KV_MULTIPLECHOICE_GRP); -// if (!currentChild.isNull()) { -// mc.clear(); -// if (!readMultipleChoice(currentChild, mc)) -// return false; -// } - -// 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); -// } - -// 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); -// expr.translation(i).gradeFrom(0).setBadCount(bcount); -// expr.translation(0).gradeFrom(i).setBadCount(r_bcount); -// expr.translation(i).gradeFrom(0).setQueryDate(qdate); -// expr.translation(0).gradeFrom(i).setQueryDate(r_qdate); -// } -////kDebug() << "KEduVocKvtml2Reader::readExpression(): id: " << i << " translation: " << textstr << endl; - -// // Next translation -// currentElement = currentElement.nextSiblingElement(KV_TRANS); -// i++; -// } - - //if (m_doc->entryCount() == 0) - // m_doc->setQueryIdentifier(q_org, q_trans); - m_doc->appendEntry(&expr); - - return true; -} #include "keduvockvtml2reader.moc" diff --git a/kdeeducore/keduvockvtml2reader.h b/kdeeducore/keduvockvtml2reader.h index 255043d..74dc55d 100644 --- a/kdeeducore/keduvockvtml2reader.h +++ b/kdeeducore/keduvockvtml2reader.h @@ -64,15 +64,45 @@ class KEduVocDocument; #define UL_USER_USAGE "#" // designates number of user type /** -@author Eric Pignet +* @brief class to read kvtml2 data files into keduvocdocument +@author Jeremy Whiting */ class KEduVocKvtml2Reader : public QObject { Q_OBJECT public: + /** default constructor + * @param file file to read from + */ KEduVocKvtml2Reader(QIODevice *file); + /** read the document + * @param doc document object to store the data in + */ bool readDoc(KEduVocDocument *doc); + + /** read information entries + * @param informationElement QDomElement + */ + bool readInformation(QDomElement &informationElement); + + /** read group elements: identifiers, entries, types, usages, lessons */ + bool readGroups(QDomElement &domElementParent); + + /** read an identifier + * @param identifierElement QDomElement for the identifier to read + */ + bool readIdentifier(QDomElement &identifierElement); + + /** read an entry + * @param entryElement QDomElement for the entry to read + */ + bool readEntry(QDomElement &entryElement); + + /** read a translation + * @param translationElement QDomElement for the translation to read + */ + bool readTranslation(QDomElement &translationElement, KEduVocExpression &expr, int index); bool readLesson(QDomElement &domElementParent); bool readArticle(QDomElement &domElementParent); @@ -101,17 +131,19 @@ public: QString &antonym, QString &usage, QString ¶phrase); - bool readExpression(QDomElement &expressionElement); - bool readBody(QDomElement &domElementParent); QString errorMessage() const {return m_errorMessage;} private: + + /** pre-opened QIODevice to read from */ QIODevice *m_inputFile; + + /** KEduVocDocument to read to */ KEduVocDocument *m_doc; + + /** error message */ QString m_errorMessage; - int m_cols; - int m_lines; }; #endif diff --git a/kdeeducore/kvtml2defs.h b/kdeeducore/kvtml2defs.h index aa12f18..4423847 100644 --- a/kdeeducore/kvtml2defs.h +++ b/kdeeducore/kvtml2defs.h @@ -18,6 +18,7 @@ #define KVTML_TAG "kvtml" #define KVTML_VERSION "version" +#define KVTML_ID "id" #define KVTML_INFORMATION "information" @@ -56,20 +57,21 @@ #define KVTML_QUERY "query" #define KVTML_CURRENT "current" +#define KVTML_ENTRIES "entries" #define KVTML_ENTRY "entry" #define KVTML_INACTIVE "inactive" #define KVTML_INQUERY "inquery" -#define KVTML_TRANS "translation" +#define KVTML_TRANSLATION "translation" #define KVTML_TEXT "text" -#define KVTML_PRONUNC "pronunciation" -#define KVTML_FFF "falsefriendfrom" -#define KVTML_FFT "falsefriendto" -#define KVTML_FF "falsefriend" -#define KVTML_ANT "antonym" -#define KVTML_SYN "synonym" -#define KVTML_EX "example" -#define KVTML_PAR "paraphrase" +#define KVTML_PRONUNCIATION "pronunciation" +#define KVTML_FALSEFRIENDFROM "falsefriendfrom" +#define KVTML_FALSEFRIENDTO "falsefriendto" +#define KVTML_FALSEFRIEND "falsefriend" +#define KVTML_ANTONYM "antonym" +#define KVTML_SYNONYM "synonym" +#define KVTML_EXAMPLE "example" +#define KVTML_PARAPHRASE "paraphrase" #define KVTML_COMPARISON "comparison" #define KVTML_ABS "absolute" diff --git a/kdeeducore/kvtml_empty_sample.kvtml b/kdeeducore/kvtml_empty_sample.kvtml index c0fb08f..07c06e8 100644 --- a/kdeeducore/kvtml_empty_sample.kvtml +++ b/kdeeducore/kvtml_empty_sample.kvtml @@ -64,59 +64,61 @@ professional usage + + + true to deactivate an entry (won't be queried) + true + 25 + + Kniebeugen + + 1 + + + + + + + + + + + + gut + besser + am besten + + + + + + + + + + 1 + 1 + 1 + 949757271 + + + + genuflect + + 0.8 + 6 + 1 + 949757271 + + + + Lesson with grades example true true - - true to deactivate an entry (won't be queried) - true - 25 - - Kniebeugen - - 1 - - - - - - - - - - - - gut - besser - am besten - - - - - - - - - - 1 - 1 - 1 - 949757271 - - - - genuflect - - 0.8 - 6 - 1 - 949757271 - - -