From eec85a9372eac362a8a92d83b6d4113847b6d983 Mon Sep 17 00:00:00 2001 From: dockes Date: Tue, 21 Nov 2006 08:47:51 +0000 Subject: [PATCH] added stem expansion mode to term explorer --- src/qtgui/guiutils.cpp | 16 ++++++-- src/qtgui/guiutils.h | 5 ++- src/qtgui/spell.ui | 81 +++++++++++++++++++++++++---------------- src/qtgui/spell_w.cpp | 53 ++++++++++++++++++++++----- src/qtgui/spell_w.h | 3 +- src/qtgui/uiprefs_w.cpp | 10 ++--- 6 files changed, 116 insertions(+), 52 deletions(-) diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index 17dbba18..2a78f920 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.24 2006-11-17 15:26:40 dockes Exp $ (C) 2005 Jean-Francois Dockes"; +static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.25 2006-11-21 08:47:51 dockes Exp $ (C) 2005 Jean-Francois Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -21,18 +21,28 @@ static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.24 2006-11-17 15:26:40 dockes Ex #include +#include "recoll.h" #include "debuglog.h" #include "smallut.h" -#include "recoll.h" #include "guiutils.h" #include "pathut.h" #include "base64.h" -#include "rcldb.h" #include "transcode.h" #include #include +bool getStemLangs(list& langs) +{ + string reason; + if (!maybeOpenDb(reason)) { + LOGERR(("getStemLangs: %s\n", reason.c_str())); + return false; + } + langs = rcldb->getStemLangs(); + return true; +} + static const char *htmlbrowserlist = "opera konqueror firefox mozilla netscape"; diff --git a/src/qtgui/guiutils.h b/src/qtgui/guiutils.h index 9cb33682..38bc627e 100644 --- a/src/qtgui/guiutils.h +++ b/src/qtgui/guiutils.h @@ -17,7 +17,7 @@ #ifndef _GUIUTILS_H_INCLUDED_ #define _GUIUTILS_H_INCLUDED_ /* - * @(#$Id: guiutils.h,v 1.16 2006-11-17 15:26:40 dockes Exp $ (C) 2005 Jean-Francois Dockes + * @(#$Id: guiutils.h,v 1.17 2006-11-21 08:47:51 dockes Exp $ (C) 2005 Jean-Francois Dockes * jean-francois.dockes@wanadoo.fr * * This program is free software; you can redistribute it and/or modify @@ -49,6 +49,9 @@ using std::list; using std::vector; #endif +/** Retrieve configured stemming languages */ +bool getStemLangs(list& langs); + /** Start a browser on the help document */ extern bool startHelpBrowser(const string& url = ""); diff --git a/src/qtgui/spell.ui b/src/qtgui/spell.ui index fad07b6d..048184f2 100644 --- a/src/qtgui/spell.ui +++ b/src/qtgui/spell.ui @@ -8,8 +8,8 @@ 0 0 - -1 - -1 + 298 + 295 @@ -35,7 +35,7 @@ - layout5 + layout4 @@ -43,36 +43,19 @@ - layout4 + layout3 - + unnamed - - - Label1 - - - NoFrame - - - Plain - - - Enter word to expand - - - baseWordLE - - - + baseWordLE - 200 + 100 0 @@ -83,18 +66,16 @@ Sunken - - - expTypeCMB - - - + expandPB false + + NoFocus + &Expand @@ -102,13 +83,26 @@ Alt+E - + + + stemLangCMB + + + + + expTypeCMB + + + dismissPB true + + NoFocus + &Close @@ -116,7 +110,7 @@ Alt+C - + @@ -128,10 +122,33 @@ 200 + + TabFocus + + + PlainText + + + true + + + false + + + true + + + baseWordLE + expandPB + suggsTE + dismissPB + expTypeCMB + stemLangCMB + diff --git a/src/qtgui/spell_w.cpp b/src/qtgui/spell_w.cpp index e1a7e547..4855cd9c 100644 --- a/src/qtgui/spell_w.cpp +++ b/src/qtgui/spell_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.5 2006-11-06 17:37:22 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.6 2006-11-21 08:47:51 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -43,18 +43,33 @@ static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.5 2006-11-06 17:37:22 dockes Exp void SpellW::init() { - expTypeCMB->insertItem(tr("Wildcards")); - expTypeCMB->insertItem(tr("Regexp")); - int maxtyp = 1; + // Don't change the order, or fix the rest of the code... + /*0*/expTypeCMB->insertItem(tr("Wildcards")); + /*1*/expTypeCMB->insertItem(tr("Regexp")); + /*2*/expTypeCMB->insertItem(tr("Stem expansion")); #ifdef RCL_USE_ASPELL - expTypeCMB->insertItem(tr("Spelling/Phonetic")); - maxtyp = 2; + /*3*/expTypeCMB->insertItem(tr("Spelling/Phonetic")); #endif + int typ = prefs.termMatchType; - if (typ < 0 || typ > maxtyp) + if (typ < 0 || typ > expTypeCMB->count()) typ = 0; expTypeCMB->setCurrentItem(typ); + // Stemming language combobox + stemLangCMB->clear(); + list langs; + if (!getStemLangs(langs)) { + QMessageBox::warning(0, "Recoll", + tr("error retrieving stemming languages")); + } + for (list::const_iterator it = langs.begin(); + it != langs.end(); it++) { + stemLangCMB-> + insertItem(QString::fromAscii(it->c_str(), it->length())); + } + stemLangCMB->setEnabled(false); + // signals and slots connections connect(baseWordLE, SIGNAL(textChanged(const QString&)), this, SLOT(wordChanged(const QString&))); @@ -63,6 +78,8 @@ void SpellW::init() connect(dismissPB, SIGNAL(clicked()), this, SLOT(close())); connect(suggsTE, SIGNAL(doubleClicked(int, int)), this, SLOT(textDoubleClicked(int, int))); + connect(expTypeCMB, SIGNAL(activated(int)), + this, SLOT(modeSet(int))); } /* Expand term according to current mode */ @@ -81,6 +98,7 @@ void SpellW::doExpand() string expr = string((const char *)baseWordLE->text().utf8()); list suggs; prefs.termMatchType = expTypeCMB->currentItem(); + Rcl::Db::MatchType mt = Rcl::Db::ET_WILD; switch (expTypeCMB->currentItem()) { case 1: mt = Rcl::Db::ET_REGEXP; @@ -92,8 +110,17 @@ void SpellW::doExpand() return; } break; + + + case 2: + { + string stemlang = (const char *)stemLangCMB->currentText().utf8(); + suggs = rcldb->stemExpand(stemlang,expr); + } + break; + #ifdef RCL_USE_ASPELL - case 2: { + case 3: { LOGDEB(("SpellW::doExpand: aspelling\n")); if (!aspell) { QMessageBox::warning(0, "Recoll", @@ -112,7 +139,7 @@ void SpellW::doExpand() } if (suggs.empty()) { - suggsTE->append(tr("No spelling expansion found")); + suggsTE->append(tr("No expansion found")); } else { for (list::iterator it = suggs.begin(); it != suggs.end(); it++) { @@ -139,3 +166,11 @@ void SpellW::textDoubleClicked(int para, int) if (suggsTE->hasSelectedText()) emit(wordSelect(suggsTE->selectedText())); } + +void SpellW::modeSet(int mode) +{ + if (mode == 2) + stemLangCMB->setEnabled(true); + else + stemLangCMB->setEnabled(false); +} diff --git a/src/qtgui/spell_w.h b/src/qtgui/spell_w.h index ff7d3ad5..534890e3 100644 --- a/src/qtgui/spell_w.h +++ b/src/qtgui/spell_w.h @@ -1,6 +1,6 @@ #ifndef _ASPELL_W_H_INCLUDED_ #define _ASPELL_W_H_INCLUDED_ -/* @(#$Id: spell_w.h,v 1.2 2006-10-15 13:07:45 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: spell_w.h,v 1.3 2006-11-21 08:47:51 dockes Exp $ (C) 2006 J.F.Dockes */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +37,7 @@ public slots: virtual void doExpand(); virtual void wordChanged(const QString&); virtual void textDoubleClicked(int, int); + virtual void modeSet(int); signals: void wordSelect(QString); diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index ded1b3e2..57586a24 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.10 2006-11-10 13:32:08 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.11 2006-11-21 08:47:51 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -101,12 +101,10 @@ void UIPrefsDialog::setFromPrefs() stemLangCMB->clear(); stemLangCMB->insertItem(tr("(no stemming)")); list langs; - string reason; - if (!maybeOpenDb(reason)) { - QMessageBox::critical(0, "Recoll", QString(reason.c_str())); - exit(1); + if (!getStemLangs(langs)) { + QMessageBox::warning(0, "Recoll", + tr("error retrieving stemming languages")); } - langs = rcldb->getStemLangs(); int i = 0, cur = -1; for (list::const_iterator it = langs.begin(); it != langs.end(); it++) {