merge stemExpand into termExpand. return term frequencies from there and display in spellW

This commit is contained in:
dockes
2006-12-19 12:11:21 +00:00
parent 50b01c6ea4
commit be05eaa6e0
13 changed files with 301 additions and 201 deletions
+29 -20
View File
@@ -106,30 +106,40 @@
</widget>
</grid>
</widget>
<widget class="QTextEdit">
<widget class="QListView">
<column>
<property name="text">
<string>Term</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Count</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<property name="name">
<cstring>suggsTE</cstring>
<cstring>suggsLV</cstring>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
<property name="selectionMode">
<enum>Extended</enum>
</property>
<property name="focusPolicy">
<enum>TabFocus</enum>
</property>
<property name="textFormat">
<enum>PlainText</enum>
</property>
<property name="readOnly">
<property name="showSortIndicator">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
<property name="resizeMode">
<enum>NoColumn</enum>
</property>
</widget>
</vbox>
@@ -139,7 +149,6 @@
<tabstops>
<tabstop>baseWordLE</tabstop>
<tabstop>expandPB</tabstop>
<tabstop>suggsTE</tabstop>
<tabstop>dismissPB</tabstop>
<tabstop>expTypeCMB</tabstop>
<tabstop>stemLangCMB</tabstop>
+85 -28
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.7 2006-11-30 13:38:44 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.8 2006-12-19 12:11:21 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -25,17 +25,22 @@ static char rcsid[] = "@(#$Id: spell_w.cpp,v 1.7 2006-11-30 13:38:44 dockes Exp
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qtextedit.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qcombobox.h>
#if (QT_VERSION < 0x040000)
#include <qlistview.h>
#else
#include <q3listview.h>
#endif
#include "debuglog.h"
#include "recoll.h"
#include "spell_w.h"
#include "guiutils.h"
#include "rcldb.h"
#ifdef RCL_USE_ASPELL
#include "rclaspell.h"
@@ -79,16 +84,47 @@ void SpellW::init()
connect(baseWordLE, SIGNAL(returnPressed()), this, SLOT(doExpand()));
connect(expandPB, SIGNAL(clicked()), this, SLOT(doExpand()));
connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
connect(suggsTE, SIGNAL(doubleClicked(int, int)),
this, SLOT(textDoubleClicked(int, int)));
connect(suggsLV,
#if (QT_VERSION < 0x040000)
SIGNAL(doubleClicked(QListViewItem *, const QPoint &, int)),
#else
SIGNAL(doubleClicked(Q3ListViewItem *, const QPoint &, int)),
#endif
this, SLOT(textDoubleClicked()));
connect(expTypeCMB, SIGNAL(activated(int)),
this, SLOT(modeSet(int)));
suggsLV->setColumnWidth(0, 200);
suggsLV->setColumnWidth(1, 100);
// No initial sorting: user can choose to establish one
suggsLV->setSorting(100, false);
}
// Subclass qlistviewitem for numeric sorting on column 1
class MyListViewItem : public QListViewItem
{
public:
MyListViewItem(QListView *listView, const QString& s1, const QString& s2)
: QListViewItem(listView, s1, s2)
{ }
int compare(QListViewItem * i, int col, bool ascending) const {
if (col == 0)
return i->text(0).compare(text(0));
if (col == 1)
return i->text(1).toInt() - text(1).toInt();
// ??
return 0;
}
};
/* Expand term according to current mode */
void SpellW::doExpand()
{
suggsTE->clear();
suggsLV->clear();
if (baseWordLE->text().isEmpty())
return;
@@ -100,26 +136,27 @@ 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 0: mt = Rcl::Db::ET_WILD; break;
case 1:mt = Rcl::Db::ET_REGEXP; break;
case 2:mt = Rcl::Db::ET_STEM; break;
}
list<Rcl::TermMatchEntry> entries;
switch (expTypeCMB->currentItem()) {
case 1: mt = Rcl::Db::ET_REGEXP;
/* FALLTHROUGH */
case 0:
if (!rcldb->termMatch(mt, expr, suggs, prefs.queryStemLang.ascii(),
case 1:
case 2: {
if (!rcldb->termMatch(mt, prefs.queryStemLang.ascii(), expr, entries,
200)) {
LOGERR(("SpellW::doExpand:rcldb::termMatch failed\n"));
return;
}
break;
case 2:
{
string stemlang = (const char *)stemLangCMB->currentText().utf8();
suggs = rcldb->stemExpand(stemlang,expr);
}
}
break;
#ifdef RCL_USE_ASPELL
@@ -132,24 +169,37 @@ void SpellW::doExpand()
LOGDEB(("SpellW::doExpand: aspell init error\n"));
return;
}
list<string> suggs;
if (!aspell->suggest(*rcldb, expr, suggs, reason)) {
QMessageBox::warning(0, "Recoll",
tr("Aspell expansion error. "));
LOGERR(("SpellW::doExpand:suggest failed: %s\n", reason.c_str()));
}
for (list<string>::const_iterator it = suggs.begin();
it != suggs.end(); it++)
entries.push_back(Rcl::TermMatchEntry(*it));
}
#endif
}
if (suggs.empty()) {
suggsTE->append(tr("No expansion found"));
if (entries.empty()) {
new MyListViewItem(suggsLV, tr("No expansion found"), "");
} else {
for (list<string>::iterator it = suggs.begin();
it != suggs.end(); it++) {
suggsTE->append(QString::fromUtf8(it->c_str()));
// Seems that need to use a reverse iterator to get same order in
// listview and input list ??
for (list<Rcl::TermMatchEntry>::reverse_iterator it = entries.rbegin();
it != entries.rend(); it++) {
LOGDEB(("SpellW::expand: %6d [%s]\n", it->wcf, it->term.c_str()));
char num[20];
if (it->wcf)
sprintf(num, "%d", it->wcf);
else
num[0] = 0;
new MyListViewItem(suggsLV,
QString::fromUtf8(it->term.c_str()),
QString::fromAscii(num));
}
suggsTE->setCursorPosition(0,0);
suggsTE->ensureCursorVisible();
}
}
@@ -157,17 +207,24 @@ void SpellW::wordChanged(const QString &text)
{
if (text.isEmpty()) {
expandPB->setEnabled(false);
suggsTE->clear();
suggsLV->clear();
} else {
expandPB->setEnabled(true);
}
}
void SpellW::textDoubleClicked(int para, int)
void SpellW::textDoubleClicked()
{
suggsTE->setSelection(para, 0, para, 1000);
if (suggsTE->hasSelectedText())
emit(wordSelect(suggsTE->selectedText()));
QListViewItemIterator it(suggsLV);
while (it.current()) {
QListViewItem *item = it.current();
if (!item->isSelected()) {
++it;
continue;
}
emit(wordSelect((const char *)item->text(0)));
++it;
}
}
void SpellW::modeSet(int mode)
+2 -2
View File
@@ -1,6 +1,6 @@
#ifndef _ASPELL_W_H_INCLUDED_
#define _ASPELL_W_H_INCLUDED_
/* @(#$Id: spell_w.h,v 1.5 2006-12-04 09:56:26 dockes Exp $ (C) 2006 J.F.Dockes */
/* @(#$Id: spell_w.h,v 1.6 2006-12-19 12:11:21 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
@@ -54,7 +54,7 @@ public:
public slots:
virtual void doExpand();
virtual void wordChanged(const QString&);
virtual void textDoubleClicked(int, int);
virtual void textDoubleClicked();
virtual void modeSet(int);
signals:
+9 -9
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.16 2006-12-14 13:53:43 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.17 2006-12-19 12:11:21 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -169,11 +169,9 @@ void SSearch::completion()
// Query database
const int max = 100;
list<string> strs;
if (!rcldb->termMatch(Rcl::Db::ET_WILD, s, strs,
prefs.queryStemLang.ascii(),max)
|| strs.size() == 0) {
list<Rcl::TermMatchEntry> strs;
if (!rcldb->termMatch(Rcl::Db::ET_WILD, prefs.queryStemLang.ascii(),
s, strs, max) || strs.size() == 0) {
QApplication::beep();
return;
}
@@ -186,12 +184,14 @@ void SSearch::completion()
QString res;
bool ok = false;
if (strs.size() == 1) {
res = QString::fromUtf8(strs.begin()->c_str());
res = QString::fromUtf8(strs.begin()->term.c_str());
ok = true;
} else {
QStringList lst;
for (list<string>::iterator it=strs.begin(); it != strs.end(); it++)
lst.push_back(QString::fromUtf8(it->c_str()));
for (list<Rcl::TermMatchEntry>::iterator it=strs.begin();
it != strs.end(); it++) {
lst.push_back(QString::fromUtf8(it->term.c_str()));
}
res = QInputDialog::getItem(tr("Completions"),
tr("Select an item:"), lst, 0,
FALSE, &ok, this);
-6
View File
@@ -59,9 +59,6 @@
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="resizePolicy">
<enum>Manual</enum>
</property>
<property name="selectionMode">
<enum>Extended</enum>
</property>
@@ -71,9 +68,6 @@
<property name="showSortIndicator">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>LastColumn</enum>
</property>
<property name="toolTip" stdset="0">
<string>Select one or several file types, then click Change Action to modify the program used to open them</string>
</property>
+2 -8
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: viewaction_w.cpp,v 1.3 2006-12-18 16:45:52 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: viewaction_w.cpp,v 1.4 2006-12-19 12:11:21 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -37,6 +37,7 @@ using namespace std;
#include <qmessagebox.h>
#include <qinputdialog.h>
#include <qlayout.h>
#include "recoll.h"
#include "debuglog.h"
@@ -55,13 +56,6 @@ void ViewAction::init()
SIGNAL(doubleClicked(Q3ListViewItem *, const QPoint &, int)),
#endif
this, SLOT(editAction()));
// Note: could get the column width setting to work in qt4
actionsLV->setColumnWidthMode(0, QListView::Manual);
actionsLV->setColumnWidth(0, 300);
actionsLV->setColumnWidthMode(1, QListView::Manual);
actionsLV->setColumnWidth(1, 120);
fillLists();
resize(QSize(450, 250).expandedTo(minimumSizeHint()) );
}