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,
43 const TemplateSpec *templ = fvd.getTemplate(tname);
49 static const struct { Mode m; Tense t; } table[] =
51 { INFINITIVE_MODE, PRESENT_TENSE },
52 { INDICATIVE_MODE, PRESENT_TENSE },
53 { INDICATIVE_MODE, IMPERFECT_TENSE },
54 { INDICATIVE_MODE, FUTURE_TENSE },
55 { INDICATIVE_MODE, PAST_TENSE },
56 { CONDITIONAL_MODE, PRESENT_TENSE },
57 { SUBJUNCTIVE_MODE, PRESENT_TENSE },
58 { SUBJUNCTIVE_MODE, IMPERFECT_TENSE },
59 { IMPERATIVE_MODE, PRESENT_TENSE },
60 { PARTICIPLE_MODE, PRESENT_TENSE },
61 { PARTICIPLE_MODE, PAST_TENSE },
62 { GERUND_MODE, PRESENT_TENSE }, // italian only
63 { INVALID_MODE, INVALID_TENSE } // marks the end
67 string radical = FrenchVerbDictionary::getRadical(infinitive, tname);
69 bool isItalian = (fvd.getLanguage() == FrenchVerbDictionary::ITALIAN);
71 for (int j = 0; table[j].m != INVALID_MODE; j++)
73 if (table[j].m == GERUND_MODE && !isItalian)
76 dest.push_back(VVS());
77 VVS &tenseDest = dest.back();
80 fvd.generateTense(radical, *templ, table[j].m, table[j].t, conjug,
82 fvd.isVerbStartingWithAspirateH(infinitive),
85 for (VVS::const_iterator p = conjug.begin(); p != conjug.end(); p++)
87 tenseDest.push_back(VS());
88 for (VS::const_iterator i = p->begin(); i != p->end(); i++)
91 tenseDest.back().push_back(s);
96 catch (logic_error &e)
104 static const char *tn[16] =
121 N_("gerund pres."), // italian only
125 string getTenseNameForTableCell(int row, int col, bool isItalian)
127 if (row < 0 || row > 3 || col < 0 || col > 3)
133 if (row == 3 && col == 3 && !isItalian)
136 return _(tn[row * 4 + col]);
142 removePronoun(const string &s)
144 string::size_type start = 0;
145 if (s.find("que ") == 0)
147 else if (s.find("qu'") == 0)
149 else if (s.find("che ") == 0) // Italian
152 static const char *pronouns[] =
154 "je ", "j'", "tu ", "il ", "nous ", "vous ", "ils ",
155 "io ", "tu ", "egli ", "noi ", "voi ", "essi ", // Italian
159 for (size_t i = 0; pronouns[i] != NULL; i++)
161 size_t len = strlen(pronouns[i]);
162 if (s.find(pronouns[i], start) == start)
169 return string(s, start, string::npos);
174 createTableCellText(verbiste::FrenchVerbDictionary &fvd,
176 const string &lowerCaseUTF8UserText,
177 const string &openMark,
178 const string &closeMark)
180 string userTextWOAccents = fvd.removeUTF8Accents(lowerCaseUTF8UserText);
183 for (VVS::const_iterator it = tense.begin(); it != tense.end(); it++)
185 const VS &person = *it;
187 if (it != tense.begin())
190 for (VS::const_iterator i = person.begin(); i != person.end(); i++)
192 if (i != person.begin())
195 string inflection = fvd.removeUTF8Accents(removePronoun(*i));
196 if (inflection == userTextWOAccents)
197 persons += openMark + *i + closeMark;
207 * Qt version of createTableCellText() above.
208 * Return a vertor of QStrings, which are conjugations.
210 QVector<QString> qgetConjugates(verbiste::FrenchVerbDictionary &fvd,
212 const string &lowerCaseUTF8UserText,
213 const string &openMark,
214 const string &closeMark)
216 string userTextWOAccents = fvd.removeUTF8Accents(lowerCaseUTF8UserText);
217 QVector<QString> persons(0);
218 for (VVS::const_iterator it = tense.begin(); it != tense.end(); it++)
220 const VS &person = *it;
223 // if (it != tense.begin())
226 for (VS::const_iterator i = person.begin(); i != person.end(); i++)
228 if (i != person.begin())
231 string inflection = fvd.removeUTF8Accents(removePronoun(*i));
232 if (inflection == userTextWOAccents) {
233 const std::string wrapped = openMark + *i + closeMark;
234 ver.append(QString::fromUtf8(wrapped.c_str()));
237 const char *str = (*i).c_str();
238 ver.append(QString::fromUtf8(str));