diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-07-31 19:51:49 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-07-31 19:51:49 +0000 |
commit | 4ae0c208b66e0f7954e194384464fe2d0a2c56dd (patch) | |
tree | b0a7cd1c184f0003c0292eb416ed27f674f9cc43 /kbabel/kbabeldict/modules/dbsearchengine2/database.cpp | |
parent | 1964ea0fb4ab57493ca2ebb709c8d3b5395fd653 (diff) | |
download | tdesdk-4ae0c208b66e0f7954e194384464fe2d0a2c56dd.tar.gz tdesdk-4ae0c208b66e0f7954e194384464fe2d0a2c56dd.zip |
Trinity Qt initial conversion
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1157652 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kbabel/kbabeldict/modules/dbsearchengine2/database.cpp')
-rw-r--r-- | kbabel/kbabeldict/modules/dbsearchengine2/database.cpp | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/kbabel/kbabeldict/modules/dbsearchengine2/database.cpp b/kbabel/kbabeldict/modules/dbsearchengine2/database.cpp index ea0e8379..0631f7ad 100644 --- a/kbabel/kbabeldict/modules/dbsearchengine2/database.cpp +++ b/kbabel/kbabeldict/modules/dbsearchengine2/database.cpp @@ -8,8 +8,8 @@ License: GPLv2 #include <math.h> #include "database.h" -#include <qregexp.h> -#include <qdict.h> +#include <tqregexp.h> +#include <tqdict.h> #include <kapplication.h> #include <kdebug.h> #include <kmessagebox.h> @@ -21,7 +21,7 @@ License: GPLv2 -DataBase::DataBase(QString dbpath,QString dbname, QString dblang) : Db(0,DB_CXX_NO_EXCEPTIONS) +DataBase::DataBase(TQString dbpath,TQString dbname, TQString dblang) : Db(0,DB_CXX_NO_EXCEPTIONS) { filename=dbpath+"."+dblang+".db"; @@ -59,11 +59,11 @@ unsigned int DataBase::getLast() -QueryResult::QueryResult(QString r) +QueryResult::QueryResult(TQString r) { res=r; } -QueryResult::QueryResult(QString r,QString o,int s) +QueryResult::QueryResult(TQString r,TQString o,int s) { res=r; richr=r; @@ -80,7 +80,7 @@ QueryResult::QueryResult() -DataBaseInterface::DataBaseInterface(QString dir, DBSESettings *sets) +DataBaseInterface::DataBaseInterface(TQString dir, DBSESettings *sets) { //FIXME Better db names!! @@ -125,7 +125,7 @@ DataBaseInterface::~DataBaseInterface() } -DataBase *DataBaseInterface::openMyDataBase(const QString& prefix,const QString& name,const QString& l,DBTYPE tt) +DataBase *DataBaseInterface::openMyDataBase(const TQString& prefix,const TQString& name,const TQString& l,DBTYPE tt) { DataBase *aDb = new DataBase(prefix,name,l); @@ -163,7 +163,7 @@ DataBase *DataBaseInterface::openMyDataBase(const QString& prefix,const QString& */ -DataBaseInterface::MainEntry DataBaseInterface::get(const QString& query,SearchFilter *filter) +DataBaseInterface::MainEntry DataBaseInterface::get(const TQString& query,SearchFilter *filter) { static int counter=1; counter++; @@ -184,11 +184,11 @@ DataBaseInterface::MainEntry DataBaseInterface::get(const QString& query,SearchF */ -bool DataBaseInterface::addEntry(QString original,QString translated,InputInfo *info) +bool DataBaseInterface::addEntry(TQString original,TQString translated,InputInfo *info) { DBItemMainKey mk(original); DBItemMainData md; - QMap<QString, int> correlationDiff; + TQMap<TQString, int> correlationDiff; bool newentry=false; //try to get kdDebug(0) << "Inserting the pair:" << endl; @@ -220,8 +220,8 @@ bool DataBaseInterface::addEntry(QString original,QString translated,InputInfo * alpha->put(&ka,&in); kdDebug(0) << "Updating the word index " << endl; //Update words index - QStringList ws=words(original); - for(QStringList::iterator it = ws.begin(); it!=ws.end(); ++it) + TQStringList ws=words(original); + for(TQStringList::iterator it = ws.begin(); it!=ws.end(); ++it) { DBItemMainKey word(*it); DBItemMultiIndex win; @@ -240,8 +240,8 @@ bool DataBaseInterface::addEntry(QString original,QString translated,InputInfo * //Update sentence index - QStringList so=sentences(original); - QStringList st=sentences(translated); + TQStringList so=sentences(original); + TQStringList st=sentences(translated); if(so.count()==st.count() && st.count() >1 ) //we already hav a database for single string. { kdDebug(0) << "inside sentence loop" << endl; @@ -276,11 +276,11 @@ bool DataBaseInterface::addEntry(QString original,QString translated,InputInfo * if(!translated.isEmpty()) { //loop on all translations to update correlation - QStringList tmpTranslations=md.getTranslations(); - for(QStringList::iterator otIt=tmpTranslations.begin(); otIt!=tmpTranslations.end();++otIt) + TQStringList tmpTranslations=md.getTranslations(); + for(TQStringList::iterator otIt=tmpTranslations.begin(); otIt!=tmpTranslations.end();++otIt) { - QStringList wt=words(*otIt); - for(QStringList::iterator it = wt.begin(); it!=wt.end(); ++it) + TQStringList wt=words(*otIt); + for(TQStringList::iterator it = wt.begin(); it!=wt.end(); ++it) { if(correlationDiff.contains(*it)) correlationDiff[*it]--; @@ -294,10 +294,10 @@ bool DataBaseInterface::addEntry(QString original,QString translated,InputInfo * md.addTranslation(translated,info->ref()); tmpTranslations=md.getTranslations(); - for(QStringList::iterator otIt=tmpTranslations.begin(); otIt!=tmpTranslations.end();++otIt) + for(TQStringList::iterator otIt=tmpTranslations.begin(); otIt!=tmpTranslations.end();++otIt) { - QStringList wt=words(*otIt); - for(QStringList::iterator it = wt.begin(); it!=wt.end(); ++it) + TQStringList wt=words(*otIt); + for(TQStringList::iterator it = wt.begin(); it!=wt.end(); ++it) { if(correlationDiff.contains(*it)) correlationDiff[*it]++; @@ -316,7 +316,7 @@ bool DataBaseInterface::addEntry(QString original,QString translated,InputInfo * } -bool DataBaseInterface::removeEntry(QString original) +bool DataBaseInterface::removeEntry(TQString original) { DBItemMainKey mk(original); DBItemMainData md; @@ -346,8 +346,8 @@ bool DataBaseInterface::removeEntry(QString original) alpha->put(&ka,&in); //Update words index - QStringList ws=words(original); - for(QStringList::iterator it = ws.begin(); it!=ws.end(); it++) + TQStringList ws=words(original); + for(TQStringList::iterator it = ws.begin(); it!=ws.end(); it++) { DBItemMainKey word(*it); DBItemMultiIndex win; @@ -357,8 +357,8 @@ bool DataBaseInterface::removeEntry(QString original) } //Update sentence index - QStringList so=sentences(original); - QStringList st=sentences(translated); + TQStringList so=sentences(original); + TQStringList st=sentences(translated); if(so.count()==st.count() && st.count() >1 ) //we already hav a database for single string. { for(int i=0; i< so.count() ; i++) @@ -380,16 +380,16 @@ bool DataBaseInterface::removeEntry(QString original) -QMap<QString,float> DataBaseInterface::correlation(QString word,SearchFilter *filter,bool notify, float minSign) +TQMap<TQString,float> DataBaseInterface::correlation(TQString word,SearchFilter *filter,bool notify, float minSign) { - QDict<unsigned int> res; + TQDict<unsigned int> res; // res.setAutoDelete(true); - QMap<QString, float>final; + TQMap<TQString, float>final; DBItemMultiIndex::IndexList il; unsigned int tot=0; unsigned int background=0; unsigned int nocck; - QString sword=simple(word); + TQString sword=simple(word); DBItemMainKey *k = new DBItemMainKey(sword); DBItemMultiIndex *d = new DBItemMultiIndex(); if(wordsindex->get(k,d)!=DB_NOTFOUND) @@ -398,29 +398,29 @@ QMap<QString,float> DataBaseInterface::correlation(QString word,SearchFilter *fi il=d->getList(); kdDebug(0) << il.count()<<endl; tot=0; - for(QValueList<unsigned int>::iterator it=il.begin();it!=il.end();++it) + for(TQValueList<unsigned int>::iterator it=il.begin();it!=il.end();++it) { numindex->get(*it,k); - // QValueList<QueryResult> trad=exactMatch(k->getString(),filter); + // TQValueList<QueryResult> trad=exactMatch(k->getString(),filter); MainEntry e=get(k->getString(),filter); - QStringList trad=e.second.getTranslations(); + TQStringList trad=e.second.getTranslations(); nocck=words(k->getString()).contains(sword); - for( QStringList::iterator it2=trad.begin();it2!=trad.end();++it2) + for( TQStringList::iterator it2=trad.begin();it2!=trad.end();++it2) { - QStringList w=words(*it2); + TQStringList w=words(*it2); unsigned int numWords = w.count()*10+1; unsigned int wei=100000/sqrt(numWords); //weight (is the best one?) background+=(numWords-nocck)*wei; - QDict<uint> count; + TQDict<uint> count; //count.setAutoDelete(true); //FIXME:SET AUTODELETE FOR ALL DICTS - for(QStringList::iterator it1=w.begin();it1!=w.end();it1++) + for(TQStringList::iterator it1=w.begin();it1!=w.end();it1++) { uint *ip; if(!(ip=count[*it1])) count.insert(*it1,new uint(1)); @@ -428,7 +428,7 @@ QMap<QString,float> DataBaseInterface::correlation(QString word,SearchFilter *fi (*ip)++; } - for(QStringList::iterator it1=w.begin();it1!=w.end();it1++) + for(TQStringList::iterator it1=w.begin();it1!=w.end();it1++) { uint *ip; if(*(count[*it1])==nocck) //add only if same number of entry (it cuts articles) @@ -442,7 +442,7 @@ QMap<QString,float> DataBaseInterface::correlation(QString word,SearchFilter *fi unsigned int sqrBG=sqrt((1.0*background+1)/10000); - for(QDictIterator<uint> it(res) ; it.current(); ++it) + for(TQDictIterator<uint> it(res) ; it.current(); ++it) { float sign=1.0*(*(it.current()))/(10000.0*sqrBG); if(sign >minSign){ @@ -457,15 +457,15 @@ QMap<QString,float> DataBaseInterface::correlation(QString word,SearchFilter *fi return final; } -QStringList DataBaseInterface::words(QString s) +TQStringList DataBaseInterface::words(TQString s) { - QString str=simple(s); - QStringList list; + TQString str=simple(s); + TQStringList list; int pos; do { - pos=str.find(QRegExp("\\s")); + pos=str.find(TQRegExp("\\s")); // if(!simple(str.left(pos)).isEmpty()) // list.append(simple(str.left(pos))); if(!str.left(pos).isEmpty()) @@ -476,24 +476,24 @@ QStringList DataBaseInterface::words(QString s) return list; } -QString DataBaseInterface::simple(QString str,bool ck) +TQString DataBaseInterface::simple(TQString str,bool ck) { - QString res; + TQString res; if(ck) res=str; //case keep else res=str.lower(); //lowercase //FIXME: uncoment the foll. line (check speed) - res=res.replace(QRegExp("(<(.*)>)(.*)(</\\2>)"),"\\3"); //remove enclosing tags + res=res.replace(TQRegExp("(<(.*)>)(.*)(</\\2>)"),"\\3"); //remove enclosing tags //Try to get rid of regexps. - // res=res.replace(QRegExp("(('|-|_|\\s|[^\\w%])+)")," "); //strip non-word char - // res=res.replace(QRegExp("(('|-|_)+)")," "); //strip non-word char - // res=res.replace(QRegExp("[^\\w\\s%]"),""); //strip non-word char + // res=res.replace(TQRegExp("(('|-|_|\\s|[^\\w%])+)")," "); //strip non-word char + // res=res.replace(TQRegExp("(('|-|_)+)")," "); //strip non-word char + // res=res.replace(TQRegExp("[^\\w\\s%]"),""); //strip non-word char - QString r; - QChar c; + TQString r; + TQChar c; bool wasSpace=true; uint len=res.length(); for(uint i=0; i<len;i++) @@ -540,10 +540,10 @@ QString DataBaseInterface::simple(QString str,bool ck) return res; } -QStringList DataBaseInterface::sentences(QString s) +TQStringList DataBaseInterface::sentences(TQString s) { - QString str=s; - QStringList list; + TQString str=s; + TQStringList list; // kdDebug(0) << s << endl; @@ -551,7 +551,7 @@ QStringList DataBaseInterface::sentences(QString s) do { - QRegExp re("((\\.|;|\\?|\\!|:)( |$|\\\\n\\n))"); + TQRegExp re("((\\.|;|\\?|\\!|:)( |$|\\\\n\\n))"); pos=re.search(str); if(!str.left(pos).isEmpty()) list.append(str.left(pos).stripWhiteSpace()); @@ -565,20 +565,20 @@ QStringList DataBaseInterface::sentences(QString s) return list; } -QStringList DataBaseInterface::sentencesSeparator(QString s) +TQStringList DataBaseInterface::sentencesSeparator(TQString s) { - QString str=s; - QStringList list; + TQString str=s; + TQStringList list; // kdDebug(0) << s << endl; int pos; do { - QRegExp re; + TQRegExp re; re.setPattern("([.:?!;]( |$|\\\\n\\n))"); pos = re.search(str); - QString separator=re.cap(1); + TQString separator=re.cap(1); if(pos!=-1){ list.append(separator); } @@ -589,26 +589,26 @@ QStringList DataBaseInterface::sentencesSeparator(QString s) return list; } -bool DataBaseInterface::isUpper(QChar s) +bool DataBaseInterface::isUpper(TQChar s) { return s==s.upper(); } -bool DataBaseInterface::isLower(QChar s) +bool DataBaseInterface::isLower(TQChar s) { return s==s.lower(); } -QString DataBaseInterface::format(QString _s,QString t) +TQString DataBaseInterface::format(TQString _s,TQString t) { //FIXME use settings //FIXME use regexp - QString s=_s; - QString noTagT=t.replace(QRegExp("(<(.*)>)(.*)(</\\2>)"),"\\3"); - QChar first=noTagT[noTagT.find(QRegExp("\\w"))]; + TQString s=_s; + TQString noTagT=t.replace(TQRegExp("(<(.*)>)(.*)(</\\2>)"),"\\3"); + TQChar first=noTagT[noTagT.find(TQRegExp("\\w"))]; bool firstCapital=isUpper(first); /* @@ -643,9 +643,9 @@ if(columnAtEnd) if(allupper) s=s.upper(); - int pos=t.find(QRegExp("&")); + int pos=t.find(TQRegExp("&")); if(pos>=0) { - QChar accel=t[t.find(QRegExp("&"))+1]; + TQChar accel=t[t.find(TQRegExp("&"))+1]; if(accel!='&') { @@ -667,32 +667,32 @@ if(columnAtEnd) } -QString DataBaseInterface::formatRegExp(QString _s, QString t, QString tre,QString stringSearch,QString stringReplace) +TQString DataBaseInterface::formatRegExp(TQString _s, TQString t, TQString tre,TQString stringSearch,TQString stringReplace) { - QString s=_s; - QRegExp templateRegExp(tre); - //QString stringSearch = "(.*)!@CAP1@$"; // use @CAP1.. fot caps in templates - //QString stringReplace = "\\1@CAP1@"; // use \1, \2 for caps in str and @CAP1 fot caps in template + TQString s=_s; + TQRegExp templateRegExp(tre); + //TQString stringSearch = "(.*)!@CAP1@$"; // use @CAP1.. fot caps in templates + //TQString stringReplace = "\\1@CAP1@"; // use \1, \2 for caps in str and @CAP1 fot caps in template if(templateRegExp.exactMatch(t)) { - QStringList caps=templateRegExp.capturedTexts(); + TQStringList caps=templateRegExp.capturedTexts(); int i=0; - for(QStringList::iterator capit=caps.begin();capit!=caps.end();++capit) + for(TQStringList::iterator capit=caps.begin();capit!=caps.end();++capit) { - QString phRegExp="(?!\\\\)@CAP"+QString::number(i)+"@"; + TQString phRegExp="(?!\\\\)@CAP"+TQString::number(i)+"@"; //kdDebug(0) << "phRegExp: " << phRegExp << endl; //kdDebug(0) << "cap[" << i << "]: "<< *capit<< endl; - stringReplace = stringReplace.replace(QRegExp(phRegExp),*capit); - stringSearch = stringSearch.replace(QRegExp(phRegExp),*capit); + stringReplace = stringReplace.replace(TQRegExp(phRegExp),*capit); + stringSearch = stringSearch.replace(TQRegExp(phRegExp),*capit); i++; } // kdDebug(0) << "stringSearch " << stringSearch << endl; // kdDebug(0) << "stringReplace " << stringReplace << endl; - QRegExp stringSearchRegExp = QRegExp(stringSearch); + TQRegExp stringSearchRegExp = TQRegExp(stringSearch); // kdDebug(0) << "before: "<<s<<endl; s = s.replace(stringSearchRegExp,stringReplace); // kdDebug(0) << "after: "<<s<<endl; @@ -702,7 +702,7 @@ QString DataBaseInterface::formatRegExp(QString _s, QString t, QString tre,QStri return s; } -DBItemMultiIndex::IndexList DataBaseInterface::getAlpha( const QString & query ) +DBItemMultiIndex::IndexList DataBaseInterface::getAlpha( const TQString & query ) { DBItemMainKey *k = new DBItemMainKey(simple(query)); DBItemMultiIndex *d = new DBItemMultiIndex(); @@ -718,7 +718,7 @@ DataBaseInterface::MainEntry DataBaseInterface::getFromIndex( uint i ) return get(k.getString(),0); //FIXME: this is a BUG right now but the filter should be removed } -DataBaseInterface::MainEntry DataBaseInterface::getSentence( const QString & query ) +DataBaseInterface::MainEntry DataBaseInterface::getSentence( const TQString & query ) { static int counter=1; @@ -731,7 +731,7 @@ DataBaseInterface::MainEntry DataBaseInterface::getSentence( const QString & que } -DBItemMultiIndex::IndexList DataBaseInterface::getWordIndex( const QString & query ) +DBItemMultiIndex::IndexList DataBaseInterface::getWordIndex( const TQString & query ) { DBItemMainKey k = DBItemMainKey(query); DBItemMultiIndex d = DBItemMultiIndex(); @@ -740,7 +740,7 @@ DBItemMultiIndex::IndexList DataBaseInterface::getWordIndex( const QString & que } else { - QValueList<unsigned int> tmpList; + TQValueList<unsigned int> tmpList; return tmpList; } |