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"
17 #include "support/lstrings.h"
19 #include "frontends/alert.h"
26 #ifdef HAVE_LIBAIKSAURUS
27 using support::bformat
;
33 Thesaurus::Thesaurus()
38 Thesaurus::~Thesaurus()
44 Thesaurus::Meanings
Thesaurus::lookup(docstring
const & t
)
48 // aiksaurus is for english text only, therefore it does not work
49 // with non-ascii strings.
50 // The interface of the Thesaurus class uses docstring because a
51 // non-english thesaurus is possible in theory.
52 if (!support::isAscii(t
))
53 // to_ascii() would assert
56 string
const text
= to_ascii(t
);
58 docstring error
= from_ascii(aik_
->error());
60 static bool sent_error
= false;
62 frontend::Alert::error(_("Thesaurus failure"),
63 bformat(_("Aiksaurus returned the following error:\n\n%1$s."),
69 if (!aik_
->find(text
.c_str()))
74 int prev_meaning
= -1;
78 // correct, returns "" at the end
79 string ret
= aik_
->next(cur_meaning
);
81 while (!ret
.empty()) {
82 if (cur_meaning
!= prev_meaning
) {
83 meaning
= from_ascii(ret
);
84 ret
= aik_
->next(cur_meaning
);
85 prev_meaning
= cur_meaning
;
88 meanings
[meaning
].push_back(from_ascii(ret
));
91 ret
= aik_
->next(cur_meaning
);
94 for (Meanings::iterator it
= meanings
.begin();
95 it
!= meanings
.end(); ++it
)
96 sort(it
->second
.begin(), it
->second
.end());
103 Thesaurus::Thesaurus()
108 Thesaurus::~Thesaurus()
113 Thesaurus::Meanings
Thesaurus::lookup(docstring
const &)
118 #endif // HAVE_LIBAIKSAURUS