2 This file is part of Kiten, a KDE Japanese Reference Tool...
3 Copyright (C) 2001 Jason Katz-Brown <jason@katzbrown.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 #include <kstandarddirs.h>
23 #include <kmessagebox.h>
27 #include <qtextcodec.h>
35 void Deinf::Index::load()
40 KStandardDirs
*dirs
= KGlobal::dirs();
41 QString vconj
= dirs
->findResource("data", "kiten/vconj");
44 KMessageBox::error(0, i18n("Verb deinflection information not found, so verb deinflection cannot be used."));
50 if (!f
.open(IO_ReadOnly
))
52 KMessageBox::error(0, i18n("Verb deinflection information could not be loaded, so verb deinflection cannot be used."));
57 t
.setCodec(QTextCodec::codecForName("eucJP"));
59 for(QString text
= t
.readLine(); !t
.eof() && text
.at(0) != '$'; text
= t
.readLine())
63 unsigned int number
= text
.left(2).stripWhiteSpace().toUInt();
64 QString name
= text
.right(text
.length() - 2).stripWhiteSpace();
69 for(QString text
= t
.readLine(); !text
.isEmpty(); text
= t
.readLine())
73 QStringList
things(QStringList::split(QChar('\t'), text
));
76 conj
.ending
= things
.first();
77 conj
.replace
= (*things
.at(1));
78 conj
.num
= things
.last().toUInt();
90 QStringList
possibleConjugations(const QString
&text
)
93 for (unsigned i
= 0; i
< text
.length(); ++i
)
94 endings
.append(text
.right(i
));
99 QStringList
Deinf::Index::deinflect(const QString
&text
, QStringList
&name
)
102 QStringList endings
= possibleConjugations(text
);
105 for (QValueListIterator
<Conjugation
> it
= list
.begin(); it
!= list
.end(); ++it
)
107 QStringList
matches(endings
.grep(QRegExp(QString("^") + (*it
).ending
)));
109 if (matches
.size() > 0) // a match
111 name
.append(names
[(*it
).num
]);
113 //kdDebug() << "match ending: " << (*it).ending << "; replace: " << (*it).replace << "; name: " << names[(*it).num] << endl;
116 tmp
.replace(QRegExp((*it
).ending
+ "*", false, true), (*it
).replace
);