2001-07-29 10:42:11 +00:00
|
|
|
/**
|
|
|
|
* \file Thesaurus.C
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-07-29 10:42:11 +00:00
|
|
|
*
|
|
|
|
* \author John Levon
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-07-29 10:42:11 +00:00
|
|
|
*/
|
|
|
|
|
2001-12-20 15:11:51 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-07-29 10:42:11 +00:00
|
|
|
#include "Thesaurus.h"
|
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
#include <algorithm>
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBAIKSAURUS
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::sort;
|
2001-07-29 10:42:11 +00:00
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
2001-07-29 10:42:11 +00:00
|
|
|
Thesaurus::Thesaurus()
|
2003-11-03 17:47:28 +00:00
|
|
|
: aik_(new Aiksaurus)
|
|
|
|
{}
|
2001-07-29 10:42:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
Thesaurus::~Thesaurus()
|
|
|
|
{
|
|
|
|
delete aik_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
Thesaurus::Meanings Thesaurus::lookup(string const & text)
|
2001-07-29 10:42:11 +00:00
|
|
|
{
|
2002-01-13 01:46:33 +00:00
|
|
|
Meanings meanings;
|
2001-07-29 10:42:11 +00:00
|
|
|
|
|
|
|
if (!aik_->find(text.c_str()))
|
2002-01-13 01:46:33 +00:00
|
|
|
return meanings;
|
2001-07-29 10:42:11 +00:00
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
// weird api, but ...
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
int prev_meaning = -1;
|
|
|
|
int cur_meaning;
|
|
|
|
string meaning;
|
2001-07-29 10:42:11 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
// correct, returns "" at the end
|
2002-01-13 01:46:33 +00:00
|
|
|
string ret = aik_->next(cur_meaning);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-29 10:42:11 +00:00
|
|
|
while (!ret.empty()) {
|
2002-01-13 01:46:33 +00:00
|
|
|
if (cur_meaning != prev_meaning) {
|
|
|
|
meaning = ret;
|
|
|
|
ret = aik_->next(cur_meaning);
|
|
|
|
prev_meaning = cur_meaning;
|
|
|
|
} else {
|
|
|
|
if (ret != text) {
|
|
|
|
meanings[meaning].push_back(ret);
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|
2002-01-13 01:46:33 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
ret = aik_->next(cur_meaning);
|
2001-07-29 10:42:11 +00:00
|
|
|
}
|
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
for (Meanings::iterator it = meanings.begin();
|
|
|
|
it != meanings.end(); ++it) {
|
2002-02-16 15:59:55 +00:00
|
|
|
sort(it->second.begin(), it->second.end());
|
2002-01-13 01:46:33 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
return meanings;
|
2001-07-29 10:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
Thesaurus::Thesaurus()
|
|
|
|
{
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
2001-07-29 10:42:11 +00:00
|
|
|
Thesaurus::~Thesaurus()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
Thesaurus::Meanings Thesaurus::lookup(string const &)
|
2001-07-29 10:42:11 +00:00
|
|
|
{
|
2002-01-13 01:46:33 +00:00
|
|
|
return Meanings();
|
2001-07-29 10:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAVE_LIBAIKSAURUS
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
// Global instance
|
2002-03-21 17:27:08 +00:00
|
|
|
Thesaurus thesaurus;
|