added stem expansion mode to term explorer

This commit is contained in:
dockes 2006-11-21 08:47:51 +00:00
parent da07a169fe
commit eec85a9372
6 changed files with 116 additions and 52 deletions

View File

@ -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 <algorithm>
#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 <qsettings.h>
#include <qstringlist.h>
bool getStemLangs(list<string>& 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";

View File

@ -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<string>& langs);
/** Start a browser on the help document */
extern bool startHelpBrowser(const string& url = "");

View File

@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>-1</width>
<height>-1</height>
<width>298</width>
<height>295</height>
</rect>
</property>
<property name="sizePolicy">
@ -35,7 +35,7 @@
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout5</cstring>
<cstring>layout4</cstring>
</property>
<vbox>
<property name="name">
@ -43,36 +43,19 @@
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout4</cstring>
<cstring>layout3</cstring>
</property>
<hbox>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>Label1</cstring>
</property>
<property name="frameShape">
<enum>NoFrame</enum>
</property>
<property name="frameShadow">
<enum>Plain</enum>
</property>
<property name="text">
<string>Enter word to expand</string>
</property>
<property name="buddy" stdset="0">
<cstring>baseWordLE</cstring>
</property>
</widget>
<widget class="QLineEdit">
<widget class="QLineEdit" row="0" column="1" rowspan="1" colspan="2">
<property name="name">
<cstring>baseWordLE</cstring>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<width>100</width>
<height>0</height>
</size>
</property>
@ -83,18 +66,16 @@
<enum>Sunken</enum>
</property>
</widget>
<widget class="QComboBox">
<property name="name">
<cstring>expTypeCMB</cstring>
</property>
</widget>
<widget class="QPushButton">
<widget class="QPushButton" row="1" column="1">
<property name="name">
<cstring>expandPB</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>NoFocus</enum>
</property>
<property name="text">
<string>&amp;Expand </string>
</property>
@ -102,13 +83,26 @@
<string>Alt+E</string>
</property>
</widget>
<widget class="QPushButton">
<widget class="QComboBox" row="1" column="0">
<property name="name">
<cstring>stemLangCMB</cstring>
</property>
</widget>
<widget class="QComboBox" row="0" column="0">
<property name="name">
<cstring>expTypeCMB</cstring>
</property>
</widget>
<widget class="QPushButton" row="1" column="2">
<property name="name">
<cstring>dismissPB</cstring>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>NoFocus</enum>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
@ -116,7 +110,7 @@
<string>Alt+C</string>
</property>
</widget>
</hbox>
</grid>
</widget>
<widget class="QTextEdit">
<property name="name">
@ -128,10 +122,33 @@
<height>200</height>
</size>
</property>
<property name="focusPolicy">
<enum>TabFocus</enum>
</property>
<property name="textFormat">
<enum>PlainText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
</widget>
</vbox>
</widget>
</vbox>
</widget>
<tabstops>
<tabstop>baseWordLE</tabstop>
<tabstop>expandPB</tabstop>
<tabstop>suggsTE</tabstop>
<tabstop>dismissPB</tabstop>
<tabstop>expTypeCMB</tabstop>
<tabstop>stemLangCMB</tabstop>
</tabstops>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@ -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<string> langs;
if (!getStemLangs(langs)) {
QMessageBox::warning(0, "Recoll",
tr("error retrieving stemming languages"));
}
for (list<string>::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<string> 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<string>::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);
}

View File

@ -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);

View File

@ -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<string> 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<string>::const_iterator it = langs.begin();
it != langs.end(); it++) {