10#include "keduvockvtmlreader.h"
12#include <KLocalizedString>
19#include "keduvoccommon_p.h"
20#include "keduvoclesson.h"
21#include "keduvocwordtype.h"
28 qDebug() <<
"KEduVocKvtmlReader for kvtml version 1 files started.";
51 qDebug() <<
"Unable to load document.Parse error in line " << parseResult.errorLine <<
", col " << parseResult.errorColumn <<
": "
52 << qPrintable(parseResult.errorMessage);
57 if (domElementKvtml.
tagName() != KV_DOCTYPE) {
58 m_errorMessage =
i18n(
"This is not a KDE Vocabulary document.");
67 documentAttribute = domElementKvtml.
attributeNode(KV_ENCODING);
68 if (!documentAttribute.
isNull()) {
74 if (!documentAttribute.
isNull())
75 m_doc->setTitle(documentAttribute.
value());
78 if (!documentAttribute.
isNull())
79 m_doc->setAuthor(documentAttribute.
value());
81 documentAttribute = domElementKvtml.
attributeNode(KV_LICENSE);
82 if (!documentAttribute.
isNull())
83 m_doc->setLicense(documentAttribute.
value());
85 documentAttribute = domElementKvtml.
attributeNode(KV_DOC_REM);
86 if (!documentAttribute.
isNull())
87 m_doc->setDocumentComment(documentAttribute.
value());
89 documentAttribute = domElementKvtml.
attributeNode(KV_GENERATOR);
90 if (!documentAttribute.
isNull()) {
91 m_doc->setGenerator(documentAttribute.
value());
92 int pos = m_doc->generator().lastIndexOf(KVD_VERS_PREFIX);
94 m_doc->setVersion(m_doc->generator().remove(0, pos + 2));
98 if (!documentAttribute.
isNull())
102 if (!documentAttribute.
isNull())
109 bool result = readBody(domElementKvtml);
114bool KEduVocKvtmlReader::readBody(
QDomElement &domElementParent)
121 if (!currentElement.
isNull()) {
122 result = readLesson(currentElement);
128 if (!currentElement.
isNull()) {
129 result = readArticle(currentElement);
135 if (!currentElement.
isNull()) {
138 QDomElement domElementConjugChild = currentElement.
firstChildElement(KV_CON_ENTRY);
139 while (!domElementConjugChild.
isNull()) {
141 QDomAttr domAttrLang = domElementConjugChild.
attributeNode(KV_LANG);
147 KEduVocPersonalPronoun pronouns;
148 if (!readPersonalPronouns(domElementConjugChild, pronouns)) {
151 m_doc->identifier(count).setPersonalPronouns(pronouns);
160 m_compability.setupWordTypes(m_doc->wordTypeContainer());
163 if (!currentElement.
isNull()) {
164 result = readType(currentElement);
170 if (!currentElement.
isNull()) {
171 result = readTense(currentElement);
177 if (entryList.
length() <= 0)
180 for (
int i = 0; i < entryList.
count(); ++i) {
182 if (currentElement.
parentNode() == domElementParent) {
189 for (
int i = 0; i < m_doc->identifierCount(); i++) {
190 m_doc->identifier(i).setTenseList(m_compability.documentTenses());
196bool KEduVocKvtmlReader::readLesson(
QDomElement &domElementParent)
200 QDomElement currentElement;
207 if (entryList.
length() <= 0)
210 for (
int i = 0; i < entryList.
count(); ++i) {
212 if (currentElement.
parentNode() == domElementParent) {
216 if (!attribute.
isNull()) {
220 bool inQuery =
false;
222 if (!attribute.
isNull()) {
223 inQuery = (attribute.
value().toInt() != 0);
226 s = currentElement.
text();
227 KEduVocLesson *lesson =
new KEduVocLesson(s, m_doc->lesson());
228 lesson->setInPractice(inQuery);
229 m_doc->lesson()->appendChildContainer(lesson);
230 if (m_doc->lesson()->childContainerCount() != no - 1) {
231 qDebug() <<
"Warning! Lesson order may be confused. Are all lessons in order in the file?";
239bool KEduVocKvtmlReader::readArticle(
QDomElement &domElementParent)
255 QDomElement currentElement;
259 if (entryList.
length() <= 0)
262 for (
int i = 0; i < entryList.
count(); ++i) {
265 if (currentElement.
parentNode() == domElementParent) {
276 QString fem_def = QLatin1String(
"");
277 QString mal_def = QLatin1String(
"");
278 QString nat_def = QLatin1String(
"");
279 QString fem_indef = QLatin1String(
"");
280 QString mal_indef = QLatin1String(
"");
281 QString nat_indef = QLatin1String(
"");
285 fem_def = article.
text();
287 fem_def = QLatin1String(
"");
292 fem_indef = article.
text();
294 fem_indef = QLatin1String(
"");
299 mal_def = article.
text();
301 mal_def = QLatin1String(
"");
306 mal_indef = article.
text();
308 mal_indef = QLatin1String(
"");
313 nat_def = article.
text();
315 nat_def = QLatin1String(
"");
320 nat_indef = article.
text();
322 nat_indef = QLatin1String(
"");
325 KEduVocArticle article;
326 article.setArticle(mal_def, KEduVocWordFlag::Singular | KEduVocWordFlag::Definite | KEduVocWordFlag::Masculine);
327 article.setArticle(fem_def, KEduVocWordFlag::Singular | KEduVocWordFlag::Definite | KEduVocWordFlag::Feminine);
328 article.setArticle(nat_def, KEduVocWordFlag::Singular | KEduVocWordFlag::Definite | KEduVocWordFlag::Neuter);
329 article.setArticle(mal_indef, KEduVocWordFlag::Singular | KEduVocWordFlag::Indefinite | KEduVocWordFlag::Masculine);
330 article.setArticle(fem_indef, KEduVocWordFlag::Singular | KEduVocWordFlag::Indefinite | KEduVocWordFlag::Feminine);
331 article.setArticle(nat_indef, KEduVocWordFlag::Singular | KEduVocWordFlag::Indefinite | KEduVocWordFlag::Neuter);
332 m_doc->identifier(i).setArticle(article);
343 QDomElement domElementConjugChild = domElementParent.
firstChildElement(KV_CON_TYPE);
344 while (!domElementConjugChild.
isNull()) {
346 QDomAttr domAttrLang = domElementConjugChild.
attributeNode(KV_CON_NAME);
347 QString oldShortTense = domAttrLang.
value();
349 tense = m_compability.tenseFromKvtml1(oldShortTense);
350 KEduVocConjugation conjugation;
351 readConjugation(domElementConjugChild, conjugation);
397 QString pers3_m_sing;
398 QString pers3_f_sing;
399 QString pers3_n_sing;
402 QString pers3_m_plur;
403 QString pers3_f_plur;
404 QString pers3_n_plur;
411 while (!domElementConjugGrandChild.
isNull()) {
412 if (domElementConjugGrandChild.
tagName() == KV_CON_P1S) {
413 pers1_sing = domElementConjugGrandChild.
text();
414 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P2S) {
415 pers2_sing = domElementConjugGrandChild.
text();
416 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3SF) {
417 QDomAttr domAttrCommon = domElementConjugGrandChild.
attributeNode(KV_CONJ_COMMON);
418 if (!domAttrCommon.
isNull())
420 pers3_f_sing = domElementConjugGrandChild.
text();
422 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3SM) {
423 pers3_m_sing = domElementConjugGrandChild.
text();
425 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3SN) {
426 pers3_n_sing = domElementConjugGrandChild.
text();
428 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P1P) {
429 pers1_plur = domElementConjugGrandChild.
text();
431 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P2P) {
432 pers2_plur = domElementConjugGrandChild.
text();
434 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3PF) {
435 QDomAttr domAttrCommon = domElementConjugGrandChild.
attributeNode(KV_CONJ_COMMON);
436 if (!domAttrCommon.
isNull())
439 pers3_f_plur = domElementConjugGrandChild.
text();
441 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3PM) {
442 pers3_m_plur = domElementConjugGrandChild.
text();
444 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3PN) {
445 pers3_n_plur = domElementConjugGrandChild.
text();
462 const KEduVocWordFlags numS = KEduVocWordFlag::Singular;
463 const KEduVocWordFlags numP = KEduVocWordFlag::Plural;
465 conjugation.
setConjugation(pers1_sing, KEduVocWordFlag::First | numS);
466 conjugation.
setConjugation(pers2_sing, KEduVocWordFlag::Second | numS);
467 conjugation.
setConjugation(pers1_plur, KEduVocWordFlag::First | numP);
468 conjugation.
setConjugation(pers2_plur, KEduVocWordFlag::Second | numP);
471 conjugation.
setConjugation(pers3_f_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Singular);
473 conjugation.
setConjugation(pers3_m_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | KEduVocWordFlag::Singular);
474 conjugation.
setConjugation(pers3_f_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | KEduVocWordFlag::Singular);
475 conjugation.
setConjugation(pers3_n_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Singular);
479 conjugation.
setConjugation(pers3_f_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Plural);
481 conjugation.
setConjugation(pers3_m_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | KEduVocWordFlag::Plural);
482 conjugation.
setConjugation(pers3_f_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | KEduVocWordFlag::Plural);
483 conjugation.
setConjugation(pers3_n_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Plural);
496 QString pers3_m_sing;
497 QString pers3_f_sing;
498 QString pers3_n_sing;
501 QString pers3_m_plur;
502 QString pers3_f_plur;
503 QString pers3_n_plur;
510 while (!domElementConjugGrandChild.
isNull()) {
511 if (domElementConjugGrandChild.
tagName() == KV_CON_P1S) {
512 pers1_sing = domElementConjugGrandChild.
text();
513 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P2S) {
514 pers2_sing = domElementConjugGrandChild.
text();
515 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3SF) {
516 QDomAttr domAttrCommon = domElementConjugGrandChild.
attributeNode(KV_CONJ_COMMON);
517 if (!domAttrCommon.
isNull())
519 pers3_f_sing = domElementConjugGrandChild.
text();
521 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3SM) {
522 pers3_m_sing = domElementConjugGrandChild.
text();
524 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3SN) {
525 pers3_n_sing = domElementConjugGrandChild.
text();
527 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P1P) {
528 pers1_plur = domElementConjugGrandChild.
text();
530 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P2P) {
531 pers2_plur = domElementConjugGrandChild.
text();
533 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3PF) {
534 QDomAttr domAttrCommon = domElementConjugGrandChild.
attributeNode(KV_CONJ_COMMON);
535 if (!domAttrCommon.
isNull())
538 pers3_f_plur = domElementConjugGrandChild.
text();
540 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3PM) {
541 pers3_m_plur = domElementConjugGrandChild.
text();
543 }
else if (domElementConjugGrandChild.
tagName() == KV_CON_P3PN) {
544 pers3_n_plur = domElementConjugGrandChild.
text();
561 KEduVocWordFlags numS = KEduVocWordFlag::Singular;
562 pronouns.setMaleFemaleDifferent(
false);
563 pronouns.setPersonalPronoun(pers1_sing, KEduVocWordFlag::First | numS);
564 pronouns.setPersonalPronoun(pers2_sing, KEduVocWordFlag::Second | numS);
568 pronouns.setPersonalPronoun(pers3_f_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numS);
570 pronouns.setPersonalPronoun(pers3_m_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | numS);
571 pronouns.setPersonalPronoun(pers3_f_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | numS);
572 pronouns.setPersonalPronoun(pers3_n_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numS);
573 pronouns.setMaleFemaleDifferent(
true);
576 KEduVocWordFlags numP = KEduVocWordFlag::Plural;
578 pronouns.setPersonalPronoun(pers1_plur, KEduVocWordFlag::First | numP);
579 pronouns.setPersonalPronoun(pers2_plur, KEduVocWordFlag::Second | numP);
581 pronouns.setPersonalPronoun(pers3_f_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numP);
583 pronouns.setPersonalPronoun(pers3_m_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | numP);
584 pronouns.setPersonalPronoun(pers3_f_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | numP);
585 pronouns.setPersonalPronoun(pers3_n_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numP);
586 pronouns.setMaleFemaleDifferent(
true);
592bool KEduVocKvtmlReader::readType(
QDomElement &domElementParent)
595 QDomElement currentElement;
598 if (entryList.
length() <= 0)
601 for (
int i = 0; i < entryList.
count(); ++i) {
603 if (currentElement.
parentNode() == domElementParent) {
607 qDebug() <<
"Adding old self defined type: " << currentElement.
text();
609 KEduVocWordType *
type =
new KEduVocWordType(currentElement.
text(), m_doc->wordTypeContainer());
610 m_doc->wordTypeContainer()->appendChildContainer(type);
613 m_oldSelfDefinedTypes.append(currentElement.
text());
620bool KEduVocKvtmlReader::readTense(
QDomElement &domElementParent)
622 QDomElement currentElement;
625 while (!currentElement.
isNull()) {
626 qDebug() <<
"Reading user defined tense description: " << currentElement.
text();
627 m_compability.addUserdefinedTense(currentElement.
text());
642 QDomElement currentElement;
645 translation->setComparativeForm(currentElement.
text());
648 translation->setSuperlativeForm(currentElement.
text());
665 QDomElement currentElement;
669 if (!currentElement.
isNull()) {
674 if (!currentElement.
isNull()) {
679 if (!currentElement.
isNull()) {
684 if (!currentElement.
isNull()) {
689 if (!currentElement.
isNull()) {
698bool KEduVocKvtmlReader::readExpressionChildAttributes(
QDomElement &domElementExpressionChild,
725 lang = QLatin1String(
"");
726 attribute = domElementExpressionChild.
attributeNode(KV_LANG);
728 lang = attribute.
value();
731 attribute = domElementExpressionChild.
attributeNode(KV_SIZEHINT);
735 grade = KV_NORM_GRADE;
736 rev_grade = KV_NORM_GRADE;
737 attribute = domElementExpressionChild.
attributeNode(KV_GRADE);
738 if (!attribute.
isNull()) {
739 QString s = attribute.
value();
740 if ((pos = s.
indexOf(
';')) >= 1) {
741 grade = QStringView(s).left(pos).toInt();
742 rev_grade = QStringView(s).mid(pos + 1, s.
length()).toInt();
749 attribute = domElementExpressionChild.
attributeNode(KV_COUNT);
750 if (!attribute.
isNull()) {
751 QString s = attribute.
value();
752 if ((pos = s.
indexOf(
';')) >= 1) {
753 count = QStringView(s).left(pos).toInt();
754 rev_count = QStringView(s).mid(pos + 1, s.
length()).toInt();
762 if (!attribute.
isNull()) {
763 QString s = attribute.
value();
764 if ((pos = s.
indexOf(
';')) >= 1) {
765 bcount = QStringView(s).left(pos).toInt();
766 rev_bcount = QStringView(s).mid(pos + 1, s.
length()).toInt();
773 attribute = domElementExpressionChild.
attributeNode(KV_DATE);
774 if (!attribute.
isNull()) {
775 QString s = attribute.
value();
776 if ((pos = s.
indexOf(
';')) >= 1) {
783 attribute = domElementExpressionChild.
attributeNode(KV_DATE2);
784 if (!attribute.
isNull()) {
788 remark = QLatin1String(
"");
789 attribute = domElementExpressionChild.
attributeNode(KV_REMARK);
791 remark = attribute.
value();
793 faux_ami_f = QLatin1String(
"");
794 attribute = domElementExpressionChild.
attributeNode(KV_FAUX_AMI_F);
796 faux_ami_f = attribute.
value();
798 faux_ami_t = QLatin1String(
"");
799 attribute = domElementExpressionChild.
attributeNode(KV_FAUX_AMI_T);
801 faux_ami_t = attribute.
value();
803 synonym = QLatin1String(
"");
804 attribute = domElementExpressionChild.
attributeNode(KV_SYNONYM);
806 synonym = attribute.
value();
808 example = QLatin1String(
"");
809 attribute = domElementExpressionChild.
attributeNode(KV_EXAMPLE);
811 example = attribute.
value();
813 paraphrase = QLatin1String(
"");
814 attribute = domElementExpressionChild.
attributeNode(KV_PARAPHRASE);
816 paraphrase = attribute.
value();
818 antonym = QLatin1String(
"");
819 attribute = domElementExpressionChild.
attributeNode(KV_ANTONYM);
821 antonym = attribute.
value();
824 attribute = domElementExpressionChild.
attributeNode(KV_EXPRTYPE);
825 if (!attribute.
isNull()) {
829 pronunciation = QLatin1String(
"");
830 attribute = domElementExpressionChild.
attributeNode(KV_PRONUNCE);
832 pronunciation = attribute.
value();
834 query_id = QLatin1String(
"");
835 attribute = domElementExpressionChild.
attributeNode(KV_QUERY);
837 query_id = attribute.
value();
875 int lessonNumber = -1;
882 if (!attribute.
isNull()) {
885 if (lessonNumber > m_doc->lesson()->childContainerCount()) {
889 qDebug() <<
"Warning: lesson > m_doc->lessonCount() in readExpression.";
892 m_doc->lesson()->appendChildContainer(lesson);
910 if (!attribute.
isNull()) {
911 type = attribute.
value();
925 if (currentElement.
isNull()) {
926 m_errorMessage =
i18n(
"Data for original language missing");
932 while (!currentElement.
isNull()) {
939 && !readExpressionChildAttributes(currentElement,
965 && !readExpressionChildAttributes(currentElement,
998 if (lessonNumber != -1) {
1001 m_doc->lesson()->appendEntry(entry);
1007 if (m_doc->lesson()->entries(KEduVocLesson::Recursive).count() == 1) {
1016 if (!currentChild.
isNull()) {
1017 if (!readTranslationConjugations(currentChild, entry->
translation(i))) {
1023 if (!currentChild.
isNull()) {
1024 if (!readMultipleChoice(currentChild, entry->
translation(i))) {
1030 if (!currentChild.
isNull()) {
1031 if (!readComparison(currentChild, entry->
translation(i))) {
1036 if (!type.isEmpty()) {
1037 KEduVocWordType *wordType = m_compability.typeFromOldFormat(m_doc->wordTypeContainer(), type);
1083 if (m_doc->identifierCount() <= languageId) {
1084 m_doc->appendIdentifier();
1087 m_doc->identifier(languageId).setLocale(locale);
1093 languageName = locale;
1096 m_doc->identifier(languageId).setName(languageName);
1097 qDebug() <<
"addLanguage( " << languageId <<
", " << locale <<
"): " << languageName;
1101 if (locale != m_doc->identifier(languageId).locale()) {
1103 m_errorMessage =
i18n(
"Ambiguous definition of language code");
1111#include "moc_keduvockvtmlreader.cpp"
The conjugation of a verb.
void setConjugation(const KEduVocText &conjugation, KEduVocWordFlags flags)
Updates or creates the conjugation object for the given word flags.
The primary entry point to the hierarchy of objects describing vocabularies.
ErrorCode
the return code when opening/saving
@ InvalidXml
malformed xml or bad file formatting
@ FileTypeUnknown
unknown file type
@ FileReaderFailed
file reader failed
This class contains one vocabulary expression as an original with one or more translations.
void setTranslation(int index, const QString &expression)
Add a translation to this expression.
void setActive(bool flag=true)
set entry active (enabled for queries)
KEduVocTranslation * translation(int index)
Get a pointer to the translation.
virtual bool isParsable()
Can this reader parse this file.
bool readExpression(QDomElement &domElementParent)
KEduVocKvtmlReader(QIODevice &file)
constructor
virtual KEduVocDocument::ErrorCode read(KEduVocDocument &doc)
Parse file and write into doc.
bool addLanguage(int languageId, const QString &language)
Attempt to add a language/locale.
class to store information about a lesson
void appendEntry(KEduVocExpression *entry)
append an entry to the lesson
The conjugation of a verb.
void setPracticeCount(count_t count)
set how often this entry has been practiced as int
void setBadCount(count_t count)
set bad query count as int
void setPracticeDate(const QDateTime &date)
Set last query date.
void setGrade(grade_t grade)
sets the grade
void setExample(const QString &expression)
Sets example this expression.
QStringList getMultipleChoice() const
Returns multiple choice if available.
void setConjugation(const QString &tense, const KEduVocConjugation &conjugation)
adds conjugations or replaces them, if they exist.
void setMultipleChoice(const QStringList &choices)
Sets multiple choice.
void setParaphrase(const QString &expression)
Sets paraphrase of this expression.
void setWordType(KEduVocWordType *wordType)
Sets the word type of this expression.
void setPronunciation(const QString &expression)
Sets the pronunciation of this expression.
void setComment(const QString &expr)
Sets comment of this expression.
class to store translation word types
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
QDateTime fromSecsSinceEpoch(qint64 secs)
QString value() const const
QString data() const const
QDomElement documentElement() const const
ParseResult setContent(QAnyStringView text, ParseOptions options)
QDomAttr attributeNode(const QString &name)
QDomNodeList elementsByTagName(const QString &tagname) const const
QString tagName() const const
QString text() const const
QDomNode firstChild() const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
QDomNode lastChild() const const
QDomNode nextSibling() const const
QDomElement nextSiblingElement(const QString &tagName, const QString &namespaceURI) const const
QDomNode parentNode() const const
QDomElement toElement() const const
QDomText toText() const const
QDomNode item(int index) const const
void append(QList< T > &&value)
QString languageToString(Language language)
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
bool isNull() const const
qsizetype length() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QTextStream & left(QTextStream &stream)
QString readLine(qint64 maxlen)