3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "Thesaurus.h"
15 #include "support/gettext.h"
17 #include "support/lstrings.h"
19 #include "frontends/alert.h"
27 #ifdef HAVE_LIBAIKSAURUS
28 using support::bformat;
31 Thesaurus::Thesaurus()
36 Thesaurus::~Thesaurus()
42 Thesaurus::Meanings Thesaurus::lookup(docstring const & t)
46 // aiksaurus is for english text only, therefore it does not work
47 // with non-ascii strings.
48 // The interface of the Thesaurus class uses docstring because a
49 // non-english thesaurus is possible in theory.
50 if (!support::isAscii(t))
51 // to_ascii() would assert
54 string const text = to_ascii(t);
56 docstring error = from_ascii(aik_->error());
58 static bool sent_error = false;
60 frontend::Alert::error(_("Thesaurus failure"),
61 bformat(_("Aiksaurus returned the following error:\n\n%1$s."),
67 if (!aik_->find(text.c_str()))
72 int prev_meaning = -1;
76 // correct, returns "" at the end
77 string ret = aik_->next(cur_meaning);
79 while (!ret.empty()) {
80 if (cur_meaning != prev_meaning) {
81 meaning = from_ascii(ret);
82 ret = aik_->next(cur_meaning);
83 prev_meaning = cur_meaning;
86 meanings[meaning].push_back(from_ascii(ret));
89 ret = aik_->next(cur_meaning);
92 for (Meanings::iterator it = meanings.begin();
93 it != meanings.end(); ++it)
94 sort(it->second.begin(), it->second.end());
101 Thesaurus::Thesaurus()
106 Thesaurus::~Thesaurus()
111 Thesaurus::Meanings Thesaurus::lookup(docstring const &)
116 #endif // HAVE_LIBAIKSAURUS