2001-07-29 10:42:11 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Thesaurus.cpp
|
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"
|
|
|
|
|
2006-12-10 11:52:46 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2002-01-13 01:46:33 +00:00
|
|
|
#include <algorithm>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2007-05-28 07:56:38 +00:00
|
|
|
#ifdef HAVE_LIBAIKSAURUS
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::sort;
|
2006-12-10 11:52:46 +00:00
|
|
|
using std::string;
|
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()
|
2007-05-28 07:56:38 +00:00
|
|
|
: aik_(new Aiksaurus)
|
2003-11-03 17:47:28 +00:00
|
|
|
{}
|
2001-07-29 10:42:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
Thesaurus::~Thesaurus()
|
|
|
|
{
|
2007-05-28 07:56:38 +00:00
|
|
|
delete aik_;
|
2001-07-29 10:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-10 11:52:46 +00:00
|
|
|
Thesaurus::Meanings Thesaurus::lookup(docstring const & t)
|
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
|
|
|
|
2006-12-10 11:52:46 +00:00
|
|
|
// aiksaurus is for english text only, therefore it does not work
|
|
|
|
// with non-ascii strings.
|
|
|
|
// The interface of the Thesaurus class uses docstring because a
|
|
|
|
// non-english thesaurus is possible in theory.
|
|
|
|
if (!support::isAscii(t))
|
|
|
|
// to_ascii() would assert
|
|
|
|
return meanings;
|
|
|
|
|
|
|
|
string const text = to_ascii(t);
|
2007-05-28 07:56:38 +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;
|
2006-12-10 11:52:46 +00:00
|
|
|
docstring meaning;
|
2001-07-29 10:42:11 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
// correct, returns "" at the end
|
2007-05-28 07:56:38 +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) {
|
2006-12-10 11:52:46 +00:00
|
|
|
meaning = from_ascii(ret);
|
2007-05-28 07:56:38 +00:00
|
|
|
ret = aik_->next(cur_meaning);
|
2002-01-13 01:46:33 +00:00
|
|
|
prev_meaning = cur_meaning;
|
|
|
|
} else {
|
2006-12-10 11:52:46 +00:00
|
|
|
if (ret != text)
|
|
|
|
meanings[meaning].push_back(from_ascii(ret));
|
2002-01-13 01:46:33 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2007-05-28 07:56:38 +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();
|
2006-12-10 11:52:46 +00:00
|
|
|
it != meanings.end(); ++it)
|
|
|
|
sort(it->second.begin(), it->second.end());
|
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
|
|
|
|
2006-12-10 11:52:46 +00:00
|
|
|
Thesaurus::Meanings Thesaurus::lookup(docstring 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
|
|
|
}
|
|
|
|
|
2007-05-28 07:56:38 +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;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|