aspell checkpoint

This commit is contained in:
dockes
2006-10-09 16:37:08 +00:00
parent 57b468f58a
commit 8283ca3bfc
12 changed files with 264 additions and 119 deletions
+56 -2
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.79 2006-09-29 08:26:02 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.80 2006-10-09 16:37:08 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -890,7 +890,7 @@ static void stringToXapianQueries(const string &iq,
dumb_string(term, term1);
// Possibly perform stem compression/expansion
if (!nostemexp && (opts & Db::QO_STEM)) {
exp = m_ndb->stemExpand(stemlang,term1);
exp = m_ndb->stemExpand(stemlang, term1);
} else {
exp.push_back(term1);
}
@@ -1117,6 +1117,60 @@ list<string> Db::completions(const string &root, const string &lang, int max)
return res;
}
/** Term list walking. */
class TermIter {
public:
Xapian::TermIterator it;
Xapian::Database db;
};
TermIter *Db::termWalkOpen()
{
if (!m_ndb || !m_ndb->m_isopen)
return 0;
TermIter *tit = new TermIter;
if (tit) {
tit->db = m_ndb->m_iswritable ? m_ndb->wdb: m_ndb->db;
tit->it = tit->db.allterms_begin();
}
return tit;
}
bool Db::termWalkNext(TermIter *tit, string &term)
{
if (tit && tit->it != tit->db.allterms_end()) {
term = *(tit->it)++;
return true;
}
return false;
}
void Db::termWalkClose(TermIter *tit)
{
delete tit;
}
bool Db::termExists(const string& word)
{
if (!m_ndb || !m_ndb->m_isopen)
return 0;
Xapian::Database db = m_ndb->m_iswritable ? m_ndb->wdb: m_ndb->db;
if (!db.term_exists(word))
return false;
return true;
}
bool Db::stemDiffers(const string& lang, const string& word,
const string& base)
{
Xapian::Stem stemmer(lang);
if (!stemmer.stem_word(word).compare(stemmer.stem_word(base))) {
LOGDEB2(("Rcl::Db::stemDiffers: same for %s and %s\n",
word.c_str(), base.c_str()));
return false;
}
return true;
}
bool Db::getQueryTerms(list<string>& terms)
{
if (!m_ndb)
+15 -1
View File
@@ -16,7 +16,7 @@
*/
#ifndef _DB_H_INCLUDED_
#define _DB_H_INCLUDED_
/* @(#$Id: rcldb.h,v 1.36 2006-09-13 13:53:35 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: rcldb.h,v 1.37 2006-10-09 16:37:08 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
@@ -105,6 +105,7 @@ class Doc {
class AdvSearchData;
class Native;
class TermIter;
/**
* Wrapper class for the native database.
@@ -170,9 +171,22 @@ class Db {
/** Get a list of existing stemming databases */
std::list<std::string> getStemLangs();
/** Retrieve main database directory */
string getDbDir();
/** Set parameters for synthetic abstract generation */
void setAbstractParams(int idxTrunc, int synthLen, int syntCtxLen);
/** Whole term list walking. */
TermIter *termWalkOpen();
bool termWalkNext(TermIter *, string &term);
void termWalkClose(TermIter *);
/** Test term existence */
bool termExists(const string& term);
/** Test if terms stem to different roots. */
bool stemDiffers(const string& lang, const string& term,
const string& base);
private:
string m_filterTopDir; // Current query filter on subtree top directory
+3 -2
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: stemdb.cpp,v 1.4 2006-09-20 06:21:43 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: stemdb.cpp,v 1.5 2006-10-09 16:37:08 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/**
@@ -254,7 +254,8 @@ list<string> stemExpand(const string& dbdir, const string& lang,
LOGDEB(("stemExpand: %s -> %s\n", stem.c_str(),
stringlistdisp(explist).c_str()));
} catch (...) {
LOGERR(("stemExpand: error accessing stem db\n"));
LOGERR(("stemExpand: error accessing stem db. dbdir [%s] lang [%s]\n",
dbdir.c_str(), lang.c_str()));
explist.push_back(term);
return explist;
}