small touchups to the aspell suggestions code
This commit is contained in:
parent
8f1b706b81
commit
4f0ccb69b7
2 changed files with 22 additions and 26 deletions
|
@ -258,8 +258,11 @@ public:
|
||||||
{}
|
{}
|
||||||
void newData() {
|
void newData() {
|
||||||
while (m_db.termWalkNext(m_tit, *m_input)) {
|
while (m_db.termWalkNext(m_tit, *m_input)) {
|
||||||
if (!Rcl::Db::isSpellingCandidate(*m_input))
|
LOGDEB2(("Aspell::buildDict: term: [%s]\n", m_input->c_str()));
|
||||||
|
if (!Rcl::Db::isSpellingCandidate(*m_input)) {
|
||||||
|
LOGDEB2(("Aspell::buildDict: SKIP\n"));
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
#ifndef RCL_INDEX_STRIPCHARS
|
#ifndef RCL_INDEX_STRIPCHARS
|
||||||
if (!o_index_stripchars) {
|
if (!o_index_stripchars) {
|
||||||
string lower;
|
string lower;
|
||||||
|
@ -270,7 +273,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
// Got a non-empty sort-of appropriate term, let's send it to
|
// Got a non-empty sort-of appropriate term, let's send it to
|
||||||
// aspell
|
// aspell
|
||||||
LOGDEB2(("ASpExecPv: [%s]\n", m_input->c_str()));
|
LOGDEB2(("Apell::buildDict: SEND\n"));
|
||||||
m_input->append("\n");
|
m_input->append("\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -411,14 +414,13 @@ bool Aspell::suggest(Rcl::Db &db, const string &_term,
|
||||||
AspellStringEnumeration *els = aapi.aspell_word_list_elements(wl);
|
AspellStringEnumeration *els = aapi.aspell_word_list_elements(wl);
|
||||||
const char *word;
|
const char *word;
|
||||||
while ((word = aapi.aspell_string_enumeration_next(els)) != 0) {
|
while ((word = aapi.aspell_string_enumeration_next(els)) != 0) {
|
||||||
// stemDiffers checks that the word exists (we don't want
|
// Check that the word exists in the index (we don't want
|
||||||
// aspell computed stuff, only exact terms from the dictionary),
|
// aspell computed stuff, only exact terms from the
|
||||||
// and that it stems differently to the base word (else it's not
|
// dictionary). We used to also check that it stems
|
||||||
// useful to expand the search). Or is it ?
|
// differently from the base word but this is complicated
|
||||||
// ******** This should depend if
|
// (stemming on/off + language), so we now leave this to the
|
||||||
// stemming is turned on or not for querying *******
|
// caller.
|
||||||
string sw(word);
|
if (db.termExists(word))
|
||||||
if (db.termExists(sw) && db.stemDiffers("english", sw, mterm))
|
|
||||||
suggestions.push_back(word);
|
suggestions.push_back(word);
|
||||||
}
|
}
|
||||||
aapi.delete_aspell_string_enumeration(els);
|
aapi.delete_aspell_string_enumeration(els);
|
||||||
|
|
|
@ -190,32 +190,26 @@ void QtGuiResListPager::suggest(const vector<string>uterms,
|
||||||
LOGERR(("QtGuiResListPager:: aspell not initialized\n"));
|
LOGERR(("QtGuiResListPager:: aspell not initialized\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<string>::const_iterator uit = uterms.begin();
|
for (vector<string>::const_iterator uit = uterms.begin();
|
||||||
uit != uterms.end(); uit++) {
|
uit != uterms.end(); uit++) {
|
||||||
list<string> asuggs;
|
list<string> asuggs;
|
||||||
string reason;
|
string reason;
|
||||||
|
|
||||||
// If the term is in the index, we don't suggest alternatives.
|
// If the term is in the dictionary, Aspell::suggest won't
|
||||||
// Actually, we may want to check the frequencies and propose something
|
// list alternatives. In fact we may want to check the
|
||||||
// anyway if a possible variation is much more common (as google does)
|
// frequencies and propose something anyway if a possible
|
||||||
#warning need to take case and diacs sensibility into account somehow
|
// variation is much more common (as google does) ?
|
||||||
// Maybe use the xapian index instead ? How to retrieve the
|
|
||||||
// sensitivity flags ?
|
|
||||||
|
|
||||||
// We used to call aspell->check() here and continue if it
|
|
||||||
// succeeded. but this does not work if we are in
|
|
||||||
// case-sensitive mode and the term was not found because of a
|
|
||||||
// case difference (our aspell is all lowercase).
|
|
||||||
// if (aspell->check(*uit, reason))
|
|
||||||
// continue;
|
|
||||||
// else if (!reason.empty())
|
|
||||||
// return;
|
|
||||||
|
|
||||||
if (!aspell->suggest(*rcldb, *uit, asuggs, reason)) {
|
if (!aspell->suggest(*rcldb, *uit, asuggs, reason)) {
|
||||||
LOGERR(("QtGuiResListPager::suggest: aspell failed: %s\n",
|
LOGERR(("QtGuiResListPager::suggest: aspell failed: %s\n",
|
||||||
reason.c_str()));
|
reason.c_str()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We should check that the term stems differently from the
|
||||||
|
// base word (else it's not useful to expand the search). Or
|
||||||
|
// is it ? This should depend if stemming is turned on or not
|
||||||
|
|
||||||
if (!asuggs.empty()) {
|
if (!asuggs.empty()) {
|
||||||
sugg[*uit] = vector<string>(asuggs.begin(), asuggs.end());
|
sugg[*uit] = vector<string>(asuggs.begin(), asuggs.end());
|
||||||
if (sugg[*uit].size() > 5)
|
if (sugg[*uit].size() > 5)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue