]> Git trees. - libqmvoc.git/commitdiff
read most of translation parts excluding falsefriends and grades for now, also read...
authorJeremy Paul Whiting <jpwhiting@kde.org>
Sat, 21 Jul 2007 06:07:04 +0000 (06:07 +0000)
committerJeremy Paul Whiting <jpwhiting@kde.org>
Sat, 21 Jul 2007 06:07:04 +0000 (06:07 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=690454

kdeeducore/keduvockvtml2reader.cpp
kdeeducore/keduvockvtml2reader.h
kdeeducore/kvtml2defs.h
kdeeducore/kvtml2todo
kdeeducore/kvtml_empty_sample.kvtml

index 01024269c8a99ca9d5adc4abce7a6699f4849954..419566f008027452d9b048f1999868e3dfe27f1d 100644 (file)
@@ -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;
-//    }
+  //<pronunciation></pronunciation>
+  currentElement = translationElement.firstChildElement(KVTML_PRONUNCIATION);
+  if (!currentElement.isNull())
+  {
+    expr.translation(index).setPronunciation(currentElement.text());
+  }
+  
+  //<falsefriendfrom></falsefriendfrom>
+  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 :(
+  //<falsefriendto></falsefriendto>
+  currentElement = translationElement.firstChildElement(KVTML_FALSEFRIENDTO);
+  if (!currentElement.isNull())
+  {
+  }
 
-//      //-----------
-//      // Attributes
-//      //-----------
+  //<falsefriend></falsefriend>
+  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;
+  //<antonym></antonym>
+  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;
+  //<synonym></synonym>
+  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);
+  //<example></example>
+  currentElement = translationElement.firstChildElement(KVTML_EXAMPLE);
+  if (!currentElement.isNull())
+  {
+    expr.translation(index).setExample(currentElement.text());
+  }
 
-//        if (query_id == KV_O)
-//          q_org = lang;
+  //<usage></usage>
+  currentElement = translationElement.firstChildElement(KVTML_USAGE);
+  if (!currentElement.isNull())
+  {
+    expr.translation(index).setUsageLabel(currentElement.text());
+  }
 
-//        if (query_id == KV_T)
+  //<paraphrase></paraphrase>
+  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)
 /*
  <conjugation>
   <singular>
@@ -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)
 /*
  <comparison>
-   <l1>good</l1>
-   <l2>better</l2>
-   <l3>best</l3>
+   <absolute>good</absolute>
+   <comparative>better</comparative>
+   <superlative>best</superlative>
  </comparison>
 */
 {
-  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;
 }
index 6e243b0a6dbc1f215f6719eee369e348c14e2c8d..17b5916f24067f0f892f2324275e428cea538904 100644 (file)
@@ -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);
 
index 3fa33fed4aa7fe5209a5c6f068e1b7840294867d..d20cb172af0ed8de9591d5d67f8e5336e0bd3410 100644 (file)
 #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"
index 2b095f6fff89552eb11be60ac723f09d8c623f62..fa91a777697f5fb720f482ab5100bc863c60366f 100644 (file)
@@ -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
index 15f8d59be6a00dd63d6c0197c4e198b9fab29577..60f0023238d4cad0dd8041e3ea845f88f0161938 100644 (file)
           </plural>
         </conjugation>
         <comparison>
-          <comp1>gut</comp1>
-          <comp2>besser</comp2>
-          <comp3>am besten</comp3>
+          <absolute>gut</absolute>
+          <comparative>besser</comparative>
+          <superlative>am besten</superlative>
         </comparison>
         <multiplechoice>
           <choice></choice>