1 /* $Id: conjugation.cpp,v 1.12 2011/01/25 02:29:44 sarrazip Exp $
2 conjugation.cpp - Generic conjugation interface
4 verbiste - French conjugation system
5 Copyright (C) 2003-2006 Pierre Sarrazin <http://sarrazip.com/>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "conjugation.h"
26 #define _(x) gettext(x)
33 using namespace verbiste;
37 getConjugation(const FrenchVerbDictionary &fvd,
38 const string &infinitive,
47 qDebug() << " *>> Inside getConjugation " << timer.elapsed();
49 const TemplateSpec *templ = fvd.getTemplate(tname);
55 static const struct { Mode m; Tense t; } table[] =
57 { INFINITIVE_MODE, PRESENT_TENSE },
58 { INDICATIVE_MODE, PRESENT_TENSE },
59 { INDICATIVE_MODE, IMPERFECT_TENSE },
60 { INDICATIVE_MODE, FUTURE_TENSE },
61 { INDICATIVE_MODE, PAST_TENSE },
62 { CONDITIONAL_MODE, PRESENT_TENSE },
63 { SUBJUNCTIVE_MODE, PRESENT_TENSE },
64 { SUBJUNCTIVE_MODE, IMPERFECT_TENSE },
65 { IMPERATIVE_MODE, PRESENT_TENSE },
66 { PARTICIPLE_MODE, PRESENT_TENSE },
67 { PARTICIPLE_MODE, PAST_TENSE },
68 { GERUND_MODE, PRESENT_TENSE }, // italian only
69 { INVALID_MODE, INVALID_TENSE } // marks the end
73 string radical = FrenchVerbDictionary::getRadical(infinitive, tname);
75 bool isItalian = (fvd.getLanguage() == FrenchVerbDictionary::ITALIAN);
77 for (int j = 0; table[j].m != INVALID_MODE; j++)
79 if (table[j].m == GERUND_MODE && !isItalian)
82 dest.push_back(VVS());
83 VVS &tenseDest = dest.back();
86 fvd.generateTense(radical, *templ, table[j].m, table[j].t, conjug,
88 fvd.isVerbStartingWithAspirateH(infinitive),
91 for (VVS::const_iterator p = conjug.begin(); p != conjug.end(); p++)
93 tenseDest.push_back(VS());
94 for (VS::const_iterator i = p->begin(); i != p->end(); i++)
97 tenseDest.back().push_back(s);
102 catch (logic_error &e)
110 static const char *tn[16] =
127 N_("gerund pres."), // italian only
131 string getTenseNameForTableCell(int row, int col, bool isItalian)
133 if (row < 0 || row > 3 || col < 0 || col > 3)
139 if (row == 3 && col == 3 && !isItalian)
142 return _(tn[row * 4 + col]);
148 removePronoun(const string &s)
150 string::size_type start = 0;
151 if (s.find("que ") == 0)
153 else if (s.find("qu'") == 0)
155 else if (s.find("che ") == 0) // Italian
158 static const char *pronouns[] =
160 "je ", "j'", "tu ", "il ", "nous ", "vous ", "ils ",
161 "io ", "tu ", "egli ", "noi ", "voi ", "essi ", // Italian
165 for (size_t i = 0; pronouns[i] != NULL; i++)
167 size_t len = strlen(pronouns[i]);
168 if (s.find(pronouns[i], start) == start)
175 return string(s, start, string::npos);
180 createTableCellText(verbiste::FrenchVerbDictionary &fvd,
182 const string &lowerCaseUTF8UserText,
183 const string &openMark,
184 const string &closeMark)
186 string userTextWOAccents = fvd.removeUTF8Accents(lowerCaseUTF8UserText);
189 for (VVS::const_iterator it = tense.begin(); it != tense.end(); it++)
191 const VS &person = *it;
193 if (it != tense.begin())
196 for (VS::const_iterator i = person.begin(); i != person.end(); i++)
198 if (i != person.begin())
201 string inflection = fvd.removeUTF8Accents(removePronoun(*i));
202 if (inflection == userTextWOAccents)
203 persons += openMark + *i + closeMark;
213 * Qt version of createTableCellText() above.
214 * Return a vertor of QStrings, which are conjugations.
216 QVector<QString> qgetConjugates(verbiste::FrenchVerbDictionary &fvd,
218 const string &lowerCaseUTF8UserText,
219 const string &openMark,
220 const string &closeMark)
222 string userTextWOAccents = fvd.removeUTF8Accents(lowerCaseUTF8UserText);
223 QVector<QString> persons(0);
224 for (VVS::const_iterator it = tense.begin(); it != tense.end(); it++)
226 const VS &person = *it;
229 // if (it != tense.begin())
232 for (VS::const_iterator i = person.begin(); i != person.end(); i++)
234 if (i != person.begin())
237 string inflection = fvd.removeUTF8Accents(removePronoun(*i));
238 if (inflection == userTextWOAccents) {
239 const std::string wrapped = openMark + *i + closeMark;
240 ver.append(QString::fromUtf8(wrapped.c_str()));
243 const char *str = (*i).c_str();
244 ver.append(QString::fromUtf8(str));