2001-07-29 10:42:11 +00:00
|
|
|
/**
|
|
|
|
* \file Thesaurus.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*/
|
|
|
|
|
2001-12-20 15:11:51 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-07-29 10:42:11 +00:00
|
|
|
#include "Thesaurus.h"
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
#ifdef HAVE_LIBAIKSAURUS
|
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::sort;
|
2001-07-29 10:42:11 +00:00
|
|
|
|
|
|
|
Thesaurus::Thesaurus()
|
|
|
|
{
|
2002-01-13 01:46:33 +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 ...
|
|
|
|
|
|
|
|
int prev_meaning = -1;
|
|
|
|
int cur_meaning;
|
|
|
|
string meaning;
|
2001-07-29 10:42:11 +00:00
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
// correct, returns "" at the end
|
|
|
|
string ret = aik_->next(cur_meaning);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return meanings;
|
2001-07-29 10:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
Thesaurus::Thesaurus()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Thesaurus::~Thesaurus()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
Thesaurus thesaurus;
|