00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "keduvockvtmlreader.h"
00021
00022 #include <QtCore/QTextStream>
00023 #include <QtCore/QList>
00024 #include <QtCore/QIODevice>
00025
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 #include <kglobal.h>
00029
00030 #include "keduvocdocument.h"
00031 #include "keduvoclesson.h"
00032 #include "keduvocwordtype.h"
00033 #include "kvtmldefs.h"
00034 #include "keduvoccommon_p.h"
00035
00036 KEduVocKvtmlReader::KEduVocKvtmlReader( QIODevice *file )
00037 {
00038
00039 m_inputFile = file;
00040 m_errorMessage = "";
00041 kDebug() << "KEduVocKvtmlReader for kvtml version 1 files started.";
00042 }
00043
00044
00045 bool KEduVocKvtmlReader::readDoc( KEduVocDocument *doc )
00046 {
00047 m_doc = doc;
00048 m_cols = 0;
00049 m_lines = 0;
00050
00051 QDomDocument domDoc( "KEduVocDocument" );
00052
00053 if ( !domDoc.setContent( m_inputFile, &m_errorMessage ) )
00054 return false;
00055
00056 QDomElement domElementKvtml = domDoc.documentElement();
00057 if ( domElementKvtml.tagName() != KV_DOCTYPE ) {
00058 m_errorMessage = i18n( "This is not a KDE Vocabulary document." );
00059 return false;
00060 }
00061
00062
00063
00064
00065
00066 QDomAttr documentAttribute;
00067 documentAttribute = domElementKvtml.attributeNode( KV_ENCODING );
00068 if ( !documentAttribute.isNull() ) {
00069
00070
00071 }
00072
00073 documentAttribute = domElementKvtml.attributeNode( KV_TITLE );
00074 if ( !documentAttribute.isNull() )
00075 m_doc->setTitle( documentAttribute.value() );
00076
00077 documentAttribute = domElementKvtml.attributeNode( KV_AUTHOR );
00078 if ( !documentAttribute.isNull() )
00079 m_doc->setAuthor( documentAttribute.value() );
00080
00081 documentAttribute = domElementKvtml.attributeNode( KV_LICENSE );
00082 if ( !documentAttribute.isNull() )
00083 m_doc->setLicense( documentAttribute.value() );
00084
00085 documentAttribute = domElementKvtml.attributeNode( KV_DOC_REM );
00086 if ( !documentAttribute.isNull() )
00087 m_doc->setDocumentComment( documentAttribute.value() );
00088
00089 documentAttribute = domElementKvtml.attributeNode( KV_GENERATOR );
00090 if ( !documentAttribute.isNull() ) {
00091 m_doc->setGenerator( documentAttribute.value() );
00092 int pos = m_doc->generator().lastIndexOf( KVD_VERS_PREFIX );
00093 if ( pos >= 0 )
00094 m_doc->setVersion( m_doc->generator().remove( 0, pos + 2 ) );
00095 }
00096
00097 documentAttribute = domElementKvtml.attributeNode( KV_COLS );
00098 if ( !documentAttribute.isNull() )
00099 m_cols = documentAttribute.value().toInt();
00100
00101 documentAttribute = domElementKvtml.attributeNode( KV_LINES );
00102 if ( !documentAttribute.isNull() )
00103 m_lines = documentAttribute.value().toInt();
00104
00105
00106
00107
00108
00109 bool result = readBody( domElementKvtml );
00110
00111 return result;
00112 }
00113
00114
00115 bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent )
00116 {
00117 bool result = false;
00118
00119 QDomElement currentElement;
00120
00121 currentElement = domElementParent.firstChildElement( KV_LESS_GRP );
00122 if ( !currentElement.isNull() ) {
00123 result = readLesson( currentElement );
00124 if ( !result )
00125 return false;
00126 }
00127
00128 currentElement = domElementParent.firstChildElement( KV_ARTICLE_GRP );
00129 if ( !currentElement.isNull() ) {
00130 result = readArticle( currentElement );
00131 if ( !result )
00132 return false;
00133 }
00134
00135 currentElement = domElementParent.firstChildElement( KV_CONJUG_GRP );
00136 if ( !currentElement.isNull() ) {
00137 int count = 0;
00138
00139 QDomElement domElementConjugChild = currentElement.firstChildElement(KV_CON_ENTRY);
00140 while ( !domElementConjugChild.isNull() ) {
00141 QString lang;
00142 QDomAttr domAttrLang = domElementConjugChild.attributeNode( KV_LANG );
00143
00144 if (!addLanguage(count, domAttrLang.value())) {
00145 return false;
00146 }
00147
00148 KEduVocPersonalPronoun pronouns;
00149 if (! readPersonalPronouns( domElementConjugChild, pronouns ) ) {
00150 return false;
00151 }
00152 m_doc->identifier(count).setPersonalPronouns( pronouns );
00153
00154 count ++;
00155
00156 domElementConjugChild = domElementConjugChild.nextSiblingElement( KV_CON_ENTRY );
00157 }
00158 }
00159
00160
00161 m_doc->wordTypes().createDefaultWordTypes();
00162 currentElement = domElementParent.firstChildElement( KV_TYPE_GRP );
00163 if ( !currentElement.isNull() ) {
00164 result = readType( currentElement );
00165 if ( !result )
00166 return false;
00167 }
00168
00169 currentElement = domElementParent.firstChildElement( KV_TENSE_GRP );
00170 if ( !currentElement.isNull() ) {
00171 result = readTense( currentElement );
00172 if ( !result )
00173 return false;
00174 }
00175
00176 currentElement = domElementParent.firstChildElement( KV_USAGE_GRP );
00177 if ( !currentElement.isNull() ) {
00178 result = readUsage( currentElement );
00179 if ( !result )
00180 return false;
00181 }
00182
00183 QDomNodeList entryList = domElementParent.elementsByTagName( KV_EXPR );
00184 if ( entryList.length() <= 0 )
00185 return false;
00186
00187 for ( int i = 0; i < entryList.count(); ++i ) {
00188 currentElement = entryList.item( i ).toElement();
00189 if ( currentElement.parentNode() == domElementParent ) {
00190 result = readExpression( currentElement );
00191 if ( !result )
00192 return false;
00193 }
00194 }
00195
00196 m_doc->setTenseDescriptions(m_compability.documentTenses());
00197
00198 return true;
00199 }
00200
00201
00202 bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent )
00203 {
00204 QString s;
00205 QDomAttr attribute;
00206 QDomElement currentElement;
00207
00208
00209
00210
00211
00212 attribute = domElementParent.attributeNode( KV_SIZEHINT );
00213 if ( !attribute.isNull() )
00214 m_doc->setSizeHint( -1, attribute.value().toInt() );
00215
00216
00217
00218
00219
00220 QDomNodeList entryList = domElementParent.elementsByTagName( KV_LESS_DESC );
00221 if ( entryList.length() <= 0 )
00222 return false;
00223
00224 for ( int i = 0; i < entryList.count(); ++i ) {
00225 currentElement = entryList.item( i ).toElement();
00226 if ( currentElement.parentNode() == domElementParent ) {
00227 int no = -1;
00228
00229 attribute = currentElement.attributeNode( KV_LESS_NO );
00230 if ( !attribute.isNull() ) {
00231 no = attribute.value().toInt();
00232 }
00233
00234 attribute = currentElement.attributeNode( KV_LESS_CURR );
00235 if ( !attribute.isNull() ) {
00236 if ( no != -1 && attribute.value().toInt() != 0 ) {
00237 m_doc->setCurrentLesson( no );
00238 }
00239 }
00240
00241 bool inQuery = false;
00242 attribute = currentElement.attributeNode( KV_LESS_QUERY );
00243 if ( !attribute.isNull() ) {
00244 inQuery = (attribute.value().toInt() != 0);
00245 }
00246
00247 s = currentElement.text();
00248 int index = m_doc->appendLesson( s, inQuery );
00249 if ( index != no-1 ) {
00250 kDebug() << "Warning! Lesson order may be confused. Are all lessons in order in the file?";
00251 }
00252 }
00253 }
00254
00255 return true;
00256 }
00257
00258
00259 bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent )
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 {
00273
00274 QString s;
00275 QDomAttr attribute;
00276 QDomElement currentElement;
00277 QDomElement article;
00278
00279 QDomNodeList entryList = domElementParent.elementsByTagName( KV_ART_ENTRY );
00280 if ( entryList.length() <= 0 )
00281 return false;
00282
00283 for ( int i = 0; i < entryList.count(); ++i ) {
00284
00285
00286 currentElement = entryList.item( i ).toElement();
00287 if ( currentElement.parentNode() == domElementParent ) {
00288 QString lang;
00289 attribute = currentElement.attributeNode( KV_LANG );
00290
00291 if (!addLanguage(i, attribute.value())) {
00292 return false;
00293 }
00294
00295
00296
00297
00298 QString fem_def = "";
00299 QString mal_def = "";
00300 QString nat_def = "";
00301 QString fem_indef = "";
00302 QString mal_indef = "";
00303 QString nat_indef = "";
00304
00305 article = currentElement.firstChildElement( KV_ART_FD );
00306 if ( !article.isNull() ) {
00307 fem_def = article.text();
00308 if ( fem_def.isNull() )
00309 fem_def = "";
00310 }
00311
00312 article = currentElement.firstChildElement( KV_ART_FI );
00313 if ( !article.isNull() ) {
00314 fem_indef = article.text();
00315 if ( fem_indef.isNull() )
00316 fem_indef = "";
00317 }
00318
00319 article = currentElement.firstChildElement( KV_ART_MD );
00320 if ( !article.isNull() ) {
00321 mal_def = article.text();
00322 if ( mal_def.isNull() )
00323 mal_def = "";
00324 }
00325
00326 article = currentElement.firstChildElement( KV_ART_MI );
00327 if ( !article.isNull() ) {
00328 mal_indef = article.text();
00329 if ( mal_indef.isNull() )
00330 mal_indef = "";
00331 }
00332
00333 article = currentElement.firstChildElement( KV_ART_ND );
00334 if ( !article.isNull() ) {
00335 nat_def = article.text();
00336 if ( nat_def.isNull() )
00337 nat_def = "";
00338 }
00339
00340 article = currentElement.firstChildElement( KV_ART_NI );
00341 if ( !article.isNull() ) {
00342 nat_indef = article.text();
00343 if ( nat_indef.isNull() )
00344 nat_indef = "";
00345 }
00346
00347 m_doc->identifier(i).setArticle( KEduVocArticle( fem_def, fem_indef, mal_def, mal_indef, nat_def, nat_indef ) );
00348 }
00349 }
00350
00351 return true;
00352 }
00353
00354
00355 bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslation &translation ) {
00356
00357 QString tense;
00358
00359 QDomElement domElementConjugChild = domElementParent.firstChildElement(KV_CON_TYPE);
00360 while ( !domElementConjugChild.isNull() )
00361 {
00362
00363 QDomAttr domAttrLang = domElementConjugChild.attributeNode( KV_CON_NAME );
00364 QString oldShortTense = domAttrLang.value();
00365
00366 tense = m_compability.tenseFromKvtml1( oldShortTense );
00367 KEduVocConjugation conjugation;
00368 readConjugation(domElementConjugChild, conjugation);
00369 translation.setConjugation(tense, conjugation);
00370
00371 domElementConjugChild = domElementConjugChild.nextSiblingElement( KV_CON_TYPE );
00372 }
00373 return true;
00374 }
00375
00376 bool KEduVocKvtmlReader::readConjugation( QDomElement &domElementParent, KEduVocConjugation& conjugation )
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 {
00409
00410 bool p3_common;
00411 bool s3_common;
00412 QString pers1_sing;
00413 QString pers2_sing;
00414 QString pers3_m_sing;
00415 QString pers3_f_sing;
00416 QString pers3_n_sing;
00417 QString pers1_plur;
00418 QString pers2_plur;
00419 QString pers3_m_plur;
00420 QString pers3_f_plur;
00421 QString pers3_n_plur;
00422
00423 p3_common = false;
00424 s3_common = false;
00425
00426
00427 QDomElement domElementConjugGrandChild = domElementParent.firstChild().toElement();
00428 while ( !domElementConjugGrandChild.isNull() ) {
00429 if ( domElementConjugGrandChild.tagName() == KV_CON_P1S ) {
00430 pers1_sing = domElementConjugGrandChild.text();
00431 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P2S ) {
00432 pers2_sing = domElementConjugGrandChild.text();
00433 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SF ) {
00434 QDomAttr domAttrCommon = domElementConjugGrandChild.attributeNode( KV_CONJ_COMMON );
00435 if ( !domAttrCommon.isNull() )
00436 s3_common = domAttrCommon.value().toInt();
00437 pers3_f_sing = domElementConjugGrandChild.text();
00438
00439 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SM ) {
00440 pers3_m_sing = domElementConjugGrandChild.text();
00441
00442 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SN ) {
00443 pers3_n_sing = domElementConjugGrandChild.text();
00444
00445 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P1P ) {
00446 pers1_plur = domElementConjugGrandChild.text();
00447
00448 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P2P ) {
00449 pers2_plur = domElementConjugGrandChild.text();
00450
00451 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PF ) {
00452 QDomAttr domAttrCommon = domElementConjugGrandChild.attributeNode( KV_CONJ_COMMON );
00453 if ( !domAttrCommon.isNull() )
00454 p3_common = domAttrCommon.value().toInt();
00455
00456 pers3_f_plur = domElementConjugGrandChild.text();
00457
00458 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PM ) {
00459 pers3_m_plur = domElementConjugGrandChild.text();
00460
00461 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PN ) {
00462 pers3_n_plur = domElementConjugGrandChild.text();
00463
00464 } else {
00465 return false;
00466 }
00467
00468 domElementConjugGrandChild = domElementConjugGrandChild.nextSibling().toElement();
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479 const KEduVocConjugation::ConjugationNumber numS = KEduVocConjugation::Singular;
00480 const KEduVocConjugation::ConjugationNumber numP = KEduVocConjugation::Plural;
00481
00482 conjugation.setConjugation( pers1_sing, KEduVocConjugation::First, numS);
00483 conjugation.setConjugation( pers2_sing, KEduVocConjugation::Second, numS);
00484 conjugation.setConjugation( pers1_plur, KEduVocConjugation::First, numP);
00485 conjugation.setConjugation( pers2_plur, KEduVocConjugation::Second, numP);
00486
00487 if ( s3_common ) {
00488 conjugation.setConjugation( pers3_f_sing, KEduVocConjugation::ThirdNeutralCommon, KEduVocConjugation::Singular );
00489 } else {
00490 conjugation.setConjugation( pers3_m_sing,
00491 KEduVocConjugation::ThirdMale, KEduVocConjugation::Singular );
00492 conjugation.setConjugation( pers3_f_sing,
00493 KEduVocConjugation::ThirdFemale, KEduVocConjugation::Singular );
00494 conjugation.setConjugation( pers3_n_sing,
00495 KEduVocConjugation::ThirdNeutralCommon, KEduVocConjugation::Singular );
00496 }
00497
00498 if ( p3_common ) {
00499 conjugation.setConjugation( pers3_f_plur, KEduVocConjugation::ThirdNeutralCommon, KEduVocConjugation::Plural );
00500 } else {
00501 conjugation.setConjugation( pers3_m_plur,
00502 KEduVocConjugation::ThirdMale, KEduVocConjugation::Plural );
00503 conjugation.setConjugation( pers3_f_plur,
00504 KEduVocConjugation::ThirdFemale, KEduVocConjugation::Plural );
00505 conjugation.setConjugation( pers3_n_plur,
00506 KEduVocConjugation::ThirdNeutralCommon, KEduVocConjugation::Plural );
00507 }
00508
00509 return true;
00510 }
00511
00512
00513
00514
00515 bool KEduVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, KEduVocPersonalPronoun& pronouns )
00516 {
00517
00518 bool p3_common;
00519 bool s3_common;
00520 QString pers1_sing;
00521 QString pers2_sing;
00522 QString pers3_m_sing;
00523 QString pers3_f_sing;
00524 QString pers3_n_sing;
00525 QString pers1_plur;
00526 QString pers2_plur;
00527 QString pers3_m_plur;
00528 QString pers3_f_plur;
00529 QString pers3_n_plur;
00530
00531 p3_common = false;
00532 s3_common = false;
00533
00534
00535 QDomElement domElementConjugGrandChild = domElementParent.firstChild().toElement();
00536 while ( !domElementConjugGrandChild.isNull() ) {
00537 if ( domElementConjugGrandChild.tagName() == KV_CON_P1S ) {
00538 pers1_sing = domElementConjugGrandChild.text();
00539 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P2S ) {
00540 pers2_sing = domElementConjugGrandChild.text();
00541 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SF ) {
00542 QDomAttr domAttrCommon = domElementConjugGrandChild.attributeNode( KV_CONJ_COMMON );
00543 if ( !domAttrCommon.isNull() )
00544 s3_common = domAttrCommon.value().toInt();
00545 pers3_f_sing = domElementConjugGrandChild.text();
00546
00547 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SM ) {
00548 pers3_m_sing = domElementConjugGrandChild.text();
00549
00550 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3SN ) {
00551 pers3_n_sing = domElementConjugGrandChild.text();
00552
00553 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P1P ) {
00554 pers1_plur = domElementConjugGrandChild.text();
00555
00556 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P2P ) {
00557 pers2_plur = domElementConjugGrandChild.text();
00558
00559 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PF ) {
00560 QDomAttr domAttrCommon = domElementConjugGrandChild.attributeNode( KV_CONJ_COMMON );
00561 if ( !domAttrCommon.isNull() )
00562 p3_common = domAttrCommon.value().toInt();
00563
00564 pers3_f_plur = domElementConjugGrandChild.text();
00565
00566 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PM ) {
00567 pers3_m_plur = domElementConjugGrandChild.text();
00568
00569 } else if ( domElementConjugGrandChild.tagName() == KV_CON_P3PN ) {
00570 pers3_n_plur = domElementConjugGrandChild.text();
00571
00572 } else {
00573 return false;
00574 }
00575
00576 domElementConjugGrandChild = domElementConjugGrandChild.nextSibling().toElement();
00577 }
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587 const KEduVocConjugation::ConjugationNumber numS = KEduVocConjugation::Singular;
00588 pronouns.setMaleFemaleDifferent(false);
00589 pronouns.setPersonalPronoun( pers1_sing, KEduVocConjugation::First, numS );
00590 pronouns.setPersonalPronoun( pers2_sing, KEduVocConjugation::Second, numS );
00591
00592
00593 if ( s3_common ) {
00594 pronouns.setPersonalPronoun( pers3_f_sing, KEduVocConjugation::ThirdNeutralCommon, numS );
00595 } else {
00596 pronouns.setPersonalPronoun( pers3_m_sing,
00597 KEduVocConjugation::ThirdMale, numS );
00598 pronouns.setPersonalPronoun( pers3_f_sing,
00599 KEduVocConjugation::ThirdFemale, numS );
00600 pronouns.setPersonalPronoun( pers3_n_sing,
00601 KEduVocConjugation::ThirdNeutralCommon, numS );
00602 pronouns.setMaleFemaleDifferent(true);
00603 }
00604
00605 const KEduVocConjugation::ConjugationNumber numP = KEduVocConjugation::Plural;
00606
00607 pronouns.setPersonalPronoun( pers1_plur, KEduVocConjugation::First, numP );
00608 pronouns.setPersonalPronoun( pers2_plur, KEduVocConjugation::Second, numP );
00609 if ( p3_common ) {
00610 pronouns.setPersonalPronoun( pers3_f_plur, KEduVocConjugation::ThirdNeutralCommon, numP );
00611 } else {
00612 pronouns.setPersonalPronoun( pers3_m_plur,
00613 KEduVocConjugation::ThirdMale, numP );
00614 pronouns.setPersonalPronoun( pers3_f_plur,
00615 KEduVocConjugation::ThirdFemale, numP );
00616 pronouns.setPersonalPronoun( pers3_n_plur,
00617 KEduVocConjugation::ThirdNeutralCommon, numP );
00618 pronouns.setMaleFemaleDifferent(true);
00619 }
00620
00621 return true;
00622 }
00623
00624
00625 bool KEduVocKvtmlReader::readType( QDomElement &domElementParent )
00626 {
00627 QString s;
00628 QDomElement currentElement;
00629
00630 QDomNodeList entryList = domElementParent.elementsByTagName( KV_TYPE_DESC );
00631 if ( entryList.length() <= 0 )
00632 return false;
00633
00634 for ( int i = 0; i < entryList.count(); ++i ) {
00635 currentElement = entryList.item( i ).toElement();
00636 if ( currentElement.parentNode() == domElementParent ) {
00637
00638
00639
00640 kDebug() << "Adding old self defined type: " << currentElement.text();
00641
00642 m_doc->wordTypes().addType( currentElement.text() );
00643
00644
00645 m_oldSelfDefinedTypes.append( currentElement.text() );
00646 }
00647 }
00648
00649 return true;
00650 }
00651
00652
00653 bool KEduVocKvtmlReader::readTense( QDomElement &domElementParent )
00654 {
00655 QDomElement currentElement;
00656
00657 QDomNodeList entryList = domElementParent.elementsByTagName( KV_TENSE_DESC );
00658 if ( entryList.length() <= 0 )
00659 return false;
00660
00661 for ( int i = 0; i < entryList.count(); ++i ) {
00662 currentElement = entryList.item( i ).toElement();
00663 if ( currentElement.parentNode() == domElementParent ) {
00664 m_compability.addUserdefinedTense( currentElement.text() );
00665 }
00666 }
00667
00668 return true;
00669 }
00670
00671
00672 bool KEduVocKvtmlReader::readUsage( QDomElement &domElementParent )
00673 {
00674
00675
00676 QDomElement currentElement;
00677
00678 QDomNodeList entryList = domElementParent.elementsByTagName( KV_USAGE_DESC );
00679 if ( entryList.length() <= 0 ) {
00680 return false;
00681 }
00682
00683
00684 for ( int i = 0; i < entryList.count(); ++i ) {
00685 currentElement = entryList.item( i ).toElement();
00686 if ( currentElement.parentNode() == domElementParent ) {
00687 m_compability.addUserdefinedUsage( currentElement.text() );
00688 }
00689 }
00690
00691 foreach( QString usage, m_compability.documentUsages() ) {
00692 m_doc->addUsage( usage );
00693 }
00694
00695 return true;
00696 }
00697
00698
00699 bool KEduVocKvtmlReader::readComparison( QDomElement &domElementParent, KEduVocComparison &comp )
00700
00701
00702
00703
00704
00705
00706
00707 {
00708 QString s;
00709 comp.clear();
00710
00711 QDomElement currentElement;
00712
00713 currentElement = domElementParent.firstChildElement( KV_COMP_L1 );
00714 if ( !currentElement.isNull() ) {
00715 s = currentElement.text();
00716 if ( s.isNull() )
00717 s = "";
00718 comp.setL1( s );
00719 }
00720
00721 currentElement = domElementParent.firstChildElement( KV_COMP_L2 );
00722 if ( !currentElement.isNull() ) {
00723 s = currentElement.text();
00724 if ( s.isNull() )
00725 s = "";
00726 comp.setL2( s );
00727 }
00728
00729 currentElement = domElementParent.firstChildElement( KV_COMP_L3 );
00730 if ( !currentElement.isNull() ) {
00731 s = currentElement.text();
00732 if ( s.isNull() )
00733 s = "";
00734 comp.setL3( s );
00735 }
00736 return true;
00737 }
00738
00739
00740 bool KEduVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, KEduVocMultipleChoice &mc )
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751 {
00752 QString s;
00753 mc.clear();
00754
00755 QDomElement currentElement;
00756
00757 currentElement = domElementParent.firstChildElement( KV_MC_1 );
00758 if ( !currentElement.isNull() ) {
00759 s = currentElement.text();
00760 mc.appendChoice( s );
00761 }
00762
00763 currentElement = domElementParent.firstChildElement( KV_MC_2 );
00764 if ( !currentElement.isNull() ) {
00765 s = currentElement.text();
00766 mc.appendChoice( s );
00767 }
00768
00769 currentElement = domElementParent.firstChildElement( KV_MC_3 );
00770 if ( !currentElement.isNull() ) {
00771 s = currentElement.text();
00772 mc.appendChoice( s );
00773 }
00774
00775 currentElement = domElementParent.firstChildElement( KV_MC_4 );
00776 if ( !currentElement.isNull() ) {
00777 s = currentElement.text();
00778 mc.appendChoice( s );
00779 }
00780
00781 currentElement = domElementParent.firstChildElement( KV_MC_5 );
00782 if ( !currentElement.isNull() ) {
00783 s = currentElement.text();
00784 mc.appendChoice( s );
00785 }
00786
00787 return true;
00788 }
00789
00790
00791 bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementExpressionChild,
00792 QString &lang,
00793 grade_t &grade, grade_t &rev_grade,
00794 int &count, int &rev_count,
00795 QDateTime &date, QDateTime &rev_date,
00796 QString &remark,
00797 int &bcount, int &rev_bcount,
00798 QString &query_id,
00799 QString &pronunciation,
00800 int &width,
00801 QString &type,
00802 QString &subType,
00803 QString &faux_ami_f,
00804 QString &faux_ami_t,
00805 QString &synonym,
00806 QString &example,
00807 QString &antonym,
00808 QSet<QString> &usages,
00809 QString ¶phrase )
00810 {
00811 int pos;
00812 QDomAttr attribute;
00813
00814 lang = "";
00815 attribute = domElementExpressionChild.attributeNode( KV_LANG );
00816 if ( !attribute.isNull() )
00817 lang = attribute.value();
00818
00819 width = -1;
00820 attribute = domElementExpressionChild.attributeNode( KV_SIZEHINT );
00821 if ( !attribute.isNull() )
00822 width = attribute.value().toInt();
00823
00824 grade = KV_NORM_GRADE;
00825 rev_grade = KV_NORM_GRADE;
00826 attribute = domElementExpressionChild.attributeNode( KV_GRADE );
00827 if ( !attribute.isNull() ) {
00828 QString s = attribute.value();
00829 if (( pos = s.indexOf( ';' ) ) >= 1 ) {
00830 grade = s.left( pos ).toInt();
00831 rev_grade = s.mid( pos + 1, s.length() ).toInt();
00832 } else
00833 grade = s.toInt();
00834 }
00835
00836 count = 0;
00837 rev_count = 0;
00838 attribute = domElementExpressionChild.attributeNode( KV_COUNT );
00839 if ( !attribute.isNull() ) {
00840 QString s = attribute.value();
00841 if (( pos = s.indexOf( ';' ) ) >= 1 ) {
00842 count = s.left( pos ).toInt();
00843 rev_count = s.mid( pos + 1, s.length() ).toInt();
00844 } else
00845 count = s.toInt();
00846 }
00847
00848 bcount = 0;
00849 rev_bcount = 0;
00850 attribute = domElementExpressionChild.attributeNode( KV_BAD );
00851 if ( !attribute.isNull() ) {
00852 QString s = attribute.value();
00853 if (( pos = s.indexOf( ';' ) ) >= 1 ) {
00854 bcount = s.left( pos ).toInt();
00855 rev_bcount = s.mid( pos + 1, s.length() ).toInt();
00856 } else
00857 bcount = s.toInt();
00858 }
00859
00860 date.setTime_t( 0 );
00861 rev_date.setTime_t( 0 );
00862 attribute = domElementExpressionChild.attributeNode( KV_DATE );
00863 if ( !attribute.isNull() ) {
00864 QString s = attribute.value();
00865 if (( pos = s.indexOf( ';' ) ) >= 1 ) {
00866 date.setTime_t( s.left( pos ).toInt() );
00867 rev_date.setTime_t( s.mid( pos + 1, s.length() ).toInt() );
00868 } else
00869 date.setTime_t( s.toInt() );
00870 }
00871
00872 attribute = domElementExpressionChild.attributeNode( KV_DATE2 );
00873 if ( !attribute.isNull() ) {
00874
00875 }
00876
00877 remark = "";
00878 attribute = domElementExpressionChild.attributeNode( KV_REMARK );
00879 if ( !attribute.isNull() )
00880 remark = attribute.value();
00881
00882 faux_ami_f = "";
00883 attribute = domElementExpressionChild.attributeNode( KV_FAUX_AMI_F );
00884 if ( !attribute.isNull() )
00885 faux_ami_f = attribute.value();
00886
00887 faux_ami_t = "";
00888 attribute = domElementExpressionChild.attributeNode( KV_FAUX_AMI_T );
00889 if ( !attribute.isNull() )
00890 faux_ami_t = attribute.value();
00891
00892 synonym = "";
00893 attribute = domElementExpressionChild.attributeNode( KV_SYNONYM );
00894 if ( !attribute.isNull() )
00895 synonym = attribute.value();
00896
00897 example = "";
00898 attribute = domElementExpressionChild.