00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "keduvockvtmlcompability.h"
00025
00026 #include <KDebug>
00027
00028 const QString KEduVocKvtmlCompability::KVTML_1_USER_DEFINED = QString( "#" );
00029 const QString KEduVocKvtmlCompability::KVTML_1_SEPERATOR = QString( ":" );
00030
00031
00032 KEduVocKvtmlCompability::KEduVocKvtmlCompability()
00033 {
00034 m_usages = usageMap();
00035 m_userdefinedUsageCounter = 0;
00036 m_userdefinedTenseCounter = 0;
00037
00038 initOldTypeLists();
00039 initOldTenses();
00040 }
00041
00042
00043 QSet<QString> KEduVocKvtmlCompability::usageFromKvtml1( const QString & oldUsage ) const
00044 {
00045 QSet<QString> usages;
00046 foreach( QString usage , oldUsage.split( KVTML_1_SEPERATOR, QString::SkipEmptyParts ) ) {
00047 usages.insert( m_usages[usage] );
00048 }
00049 return usages;
00050 }
00051
00052
00053 QMap< QString, QString > KEduVocKvtmlCompability::usageMap()
00054 {
00055 QMap< QString, QString > usages;
00056
00057 usages["Am" ] = i18nc("usage label - context in which a word is used", "Americanism" );
00058 usages["abbr" ] = i18nc("usage label - context in which a word is used", "abbreviation" );
00059 usages["anat" ] = i18nc("usage label - context in which a word is used", "anatomy" );
00060 usages["astr" ] = i18nc("usage label - context in which a word is used", "astronomy" );
00061 usages["biol" ] = i18nc("usage label - context in which a word is used", "biology" );
00062 usages["bs" ] = i18nc("usage label - context in which a word is used", "bad sense" );
00063 usages["contp" ] = i18nc("usage label - context in which a word is used", "contemptuously" );
00064 usages["eccl" ] = i18nc("usage label - context in which a word is used", "ecclesiastical" );
00065 usages["fig" ] = i18nc("usage label - context in which a word is used", "figuratively" );
00066 usages["geol" ] = i18nc("usage label - context in which a word is used", "geology" );
00067 usages["hist" ] = i18nc("usage label - context in which a word is used", "historical" );
00068 usages["icht" ] = i18nc("usage label - context in which a word is used", "ichthyology" );
00069 usages["ifm" ] = i18nc("usage label - context in which a word is used", "informal" );
00070 usages["iro" ] = i18nc("usage label - context in which a word is used", "ironic" );
00071 usages["irr" ] = i18nc("usage label - context in which a word is used", "irregular" );
00072 usages["lit" ] = i18nc("usage label - context in which a word is used", "literary" );
00073 usages["metal" ] = i18nc("usage label - context in which a word is used", "metallurgy" );
00074 usages["meteo" ] = i18nc("usage label - context in which a word is used", "meteorology" );
00075 usages["miner" ] = i18nc("usage label - context in which a word is used", "mineralogy" );
00076 usages["mot" ] = i18nc("usage label - context in which a word is used", "motoring" );
00077 usages["mount" ] = i18nc("usage label - context in which a word is used", "mountaineering" );
00078 usages["myth" ] = i18nc("usage label - context in which a word is used", "mythology" );
00079 usages["npr" ] = i18nc("usage label - context in which a word is used", "proper name" );
00080 usages["opt" ] = i18nc("usage label - context in which a word is used", "optics" );
00081 usages["orn" ] = i18nc("usage label - context in which a word is used", "ornithology" );
00082 usages["os" ] = i18nc("usage label - context in which a word is used", "oneself" );
00083 usages["p" ] = i18nc("usage label - context in which a word is used", "person" );
00084 usages["parl" ] = i18nc("usage label - context in which a word is used", "parliamentary" );
00085 usages["pharm" ] = i18nc("usage label - context in which a word is used", "pharmacy" );
00086 usages["phls" ] = i18nc("usage label - context in which a word is used", "philosophy" );
00087 usages["phot" ] = i18nc("usage label - context in which a word is used", "photography" );
00088 usages["phys" ] = i18nc("usage label - context in which a word is used", "physics" );
00089 usages["physio"] = i18nc("usage label - context in which a word is used", "physiology" );
00090 usages["pl" ] = i18nc("usage label - context in which a word is used", "plural" );
00091 usages["poet" ] = i18nc("usage label - context in which a word is used", "poetry" );
00092 usages["pol" ] = i18nc("usage label - context in which a word is used", "politics" );
00093 usages["prov" ] = i18nc("usage label - context in which a word is used", "provincialism" );
00094 usages["psych" ] = i18nc("usage label - context in which a word is used", "psychology" );
00095 usages["rhet" ] = i18nc("usage label - context in which a word is used", "rhetoric" );
00096 usages["surv" ] = i18nc("usage label - context in which a word is used", "surveying" );
00097 usages["telg" ] = i18nc("usage label - context in which a word is used", "telegraphy" );
00098 usages["telph" ] = i18nc("usage label - context in which a word is used", "telephony" );
00099 usages["thea" ] = i18nc("usage label - context in which a word is used", "theater" );
00100 usages["typo" ] = i18nc("usage label - context in which a word is used", "typography" );
00101 usages["univ" ] = i18nc("usage label - context in which a word is used", "university" );
00102 usages["vet" ] = i18nc("usage label - context in which a word is used", "veterinary medicine" );
00103 usages["zoo" ] = i18nc("usage label - context in which a word is used", "zoology" );
00104
00105 return usages;
00106 }
00107
00108 void KEduVocKvtmlCompability::addUserdefinedUsage( const QString & usage )
00109 {
00110
00111 m_userdefinedUsageCounter++;
00112 m_usages[KVTML_1_USER_DEFINED + QString::number( m_userdefinedUsageCounter )] = usage;
00113 }
00114
00115 QSet< QString > KEduVocKvtmlCompability::documentUsages() const
00116 {
00117 return QSet<QString>::fromList( m_usages.values() );
00118 }
00119
00120
00121
00123 void KEduVocKvtmlCompability::initOldTypeLists()
00124 {
00125
00126 m_oldMainTypeNames.clear();
00127 m_oldMainTypeNames.insert( "v", i18nc( "@item:inlistbox The grammatical type of a word", "Verb" ) );
00128 m_oldMainTypeNames.insert( "n", i18nc( "@item:inlistbox The grammatical type of a word", "Noun" ) );
00129 m_oldMainTypeNames.insert( "nm", i18nc( "@item:inlistbox The grammatical type of a word", "Name" ) );
00130 m_oldMainTypeNames.insert( "ar", i18nc( "@item:inlistbox The grammatical type of a word", "Article" ) );
00131 m_oldMainTypeNames.insert( "aj", i18nc( "@item:inlistbox The grammatical type of a word", "Adjective" ) );
00132 m_oldMainTypeNames.insert( "av", i18nc( "@item:inlistbox The grammatical type of a word", "Adverb" ) );
00133 m_oldMainTypeNames.insert( "pr", i18nc( "@item:inlistbox The grammatical type of a word", "Pronoun" ) );
00134 m_oldMainTypeNames.insert( "ph", i18nc( "@item:inlistbox The grammatical type of an entry", "Phrase" ) );
00135 m_oldMainTypeNames.insert( "num", i18nc( "@item:inlistbox The grammatical type of a word", "Numeral" ) );
00136 m_oldMainTypeNames.insert( "con", i18nc( "@item:inlistbox The grammatical type of a word", "Conjunction" ) );
00137 m_oldMainTypeNames.insert( "pre", i18nc( "@item:inlistbox The grammatical type of a word", "Preposition" ) );
00138 m_oldMainTypeNames.insert( "qu", i18nc( "@item:inlistbox The grammatical type of an entry", "Question" ) );
00139
00140
00141 m_oldSubTypeNames.clear();
00142 m_oldSubTypeNames.insert( "ord", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (one, two, three, ...)","Ordinal" ) );
00143 m_oldSubTypeNames.insert( "crd", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (first, second, third, ...)","Cardinal" ) );
00144 m_oldSubTypeNames.insert( "def", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ) );
00145 m_oldSubTypeNames.insert( "ind", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ) );
00146 m_oldSubTypeNames.insert( "re", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ) );
00147 m_oldSubTypeNames.insert( "ir", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ) );
00148 m_oldSubTypeNames.insert( "pos", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ) );
00149 m_oldSubTypeNames.insert( "per", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ) );
00150 m_oldSubTypeNames.insert( "m", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ) );
00151 m_oldSubTypeNames.insert( "f", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ) );
00152 m_oldSubTypeNames.insert( "s", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ) );
00153 }
00154
00155
00156 QString KEduVocKvtmlCompability::mainTypeFromOldFormat( const QString & typeSubtypeString ) const
00157 {
00158 QString mainType;
00159 int i;
00160
00161 if (( i = typeSubtypeString.indexOf( KVTML_1_SEPERATOR ) ) >= 0 )
00162 mainType = typeSubtypeString.left( i );
00163 else
00164 mainType = typeSubtypeString;
00165
00166
00167
00168 if ( mainType == "1" ) {
00169 mainType = QM_VERB;
00170 } else if ( mainType == "2" ) {
00171 mainType = QM_NOUN;
00172 } else if ( mainType == "3" ) {
00173 mainType = QM_NAME;
00174 }
00175
00176 QString wt = m_oldMainTypeNames.value( mainType );
00177 if ( wt == QString() ) {
00178 kDebug() << "Unknown old maintype: " << typeSubtypeString;
00179 return typeSubtypeString;
00180 }
00181 return wt;
00182 }
00183
00184
00185 QString KEduVocKvtmlCompability::subTypeFromOldFormat( const QString & typeSubtypeString ) const
00186 {
00187 int i;
00188 QString t = typeSubtypeString;
00189 if (( i = t.indexOf( KVTML_1_SEPERATOR ) ) >= 0 ) {
00190 t.remove( 0, i+1 );
00191 } else {
00192 return QString();
00193 }
00194
00195 QString wt = m_oldSubTypeNames.value( t );
00196 if ( wt == QString() ) {
00197 kDebug() << "Unknown old maintype: " << typeSubtypeString;
00198 return typeSubtypeString;
00199 }
00200 return wt;
00201 }
00202
00203 QString KEduVocKvtmlCompability::oldType( const QString & mainType, const QString & subType ) const
00204 {
00205 QString oldType;
00206 QString oldSubType;
00207 oldType = m_oldMainTypeNames.key( mainType );
00208 oldSubType = m_oldSubTypeNames.key( subType );
00209 if ( !oldSubType.isEmpty() ) {
00210 return oldType + KVTML_1_SEPERATOR + oldSubType;
00211 }
00212 return oldType;
00213
00214 }
00215
00216 void KEduVocKvtmlCompability::initOldTenses()
00217 {
00218 m_oldTenses["PrSi"] = i18n( "Simple Present" );
00219 m_oldTenses["PrPr"] = i18n( "Present Progressive" );
00220 m_oldTenses["PrPe"] = i18n( "Present Perfect" );
00221 m_oldTenses["PaSi"] = i18n( "Simple Past" );
00222 m_oldTenses["PaPr"] = i18n( "Past Progressive" );
00223 m_oldTenses["PaPa"] = i18n( "Past Participle" );
00224 m_oldTenses["FuSi"] = i18n( "Future" );
00225 }
00226
00227
00228 void KEduVocKvtmlCompability::addUserdefinedTense(const QString & tense)
00229 {
00230 m_userdefinedTenseCounter++;
00231 m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
00232 m_tenses.insert(tense);
00233
00234 kDebug() << " Add tense: " << KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter ) << " - " << tense;
00235 }
00236
00237
00238 QString KEduVocKvtmlCompability::tenseFromKvtml1(const QString & oldTense)
00239 {
00240
00241 if (!m_oldTenses.keys().contains(oldTense)) {
00242 m_oldTenses[oldTense] = oldTense;
00243 kDebug() << "Warning, tense not found in document!";
00244 }
00245 m_tenses.insert(m_oldTenses.value(oldTense));
00246 return m_oldTenses.value(oldTense);
00247 }
00248
00249
00250 QStringList KEduVocKvtmlCompability::documentTenses() const
00251 {
00252 return m_tenses.values();
00253 }
00254
00255
00256 QString KEduVocKvtmlCompability::oldTense(const QString & tense)
00257 {
00259 if ( !m_oldTenses.values().contains(tense) ) {
00260 m_userdefinedTenseCounter++;
00261 m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
00262 }
00263 return m_oldTenses.key(tense);
00264 }