]> git.lyx.org Git - lyx.git/blob - src/Thesaurus.C
Point fix, earlier forgotten
[lyx.git] / src / Thesaurus.C
1 /**
2  * \file Thesaurus.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Thesaurus.h"
14
15 #ifdef HAVE_LIBAIKSAURUS
16
17 #include <algorithm>
18
19 using std::sort;
20
21 Thesaurus::Thesaurus()
22 {
23         aik_ = new Aiksaurus;
24 }
25
26
27 Thesaurus::~Thesaurus()
28 {
29         delete aik_;
30 }
31
32
33 Thesaurus::Meanings Thesaurus::lookup(string const & text)
34 {
35         Meanings meanings;
36
37         if (!aik_->find(text.c_str()))
38                 return meanings;
39
40         // weird api, but ...
41
42         int prev_meaning = -1;
43         int cur_meaning;
44         string meaning;
45
46         // correct, returns "" at the end
47         string ret = aik_->next(cur_meaning);
48
49         while (!ret.empty()) {
50                 if (cur_meaning != prev_meaning) {
51                         meaning = ret;
52                         ret = aik_->next(cur_meaning);
53                         prev_meaning = cur_meaning;
54                 } else {
55                         if (ret != text) {
56                                 meanings[meaning].push_back(ret);
57                         }
58                 }
59
60                 ret = aik_->next(cur_meaning);
61         }
62
63         for (Meanings::iterator it = meanings.begin();
64                 it != meanings.end(); ++it) {
65                         sort(it->second.begin(), it->second.end());
66         }
67
68         return meanings;
69 }
70
71 #else
72
73 Thesaurus::Thesaurus()
74 {
75 }
76
77
78 Thesaurus::~Thesaurus()
79 {
80 }
81
82
83 Thesaurus::Meanings Thesaurus::lookup(string const &)
84 {
85         return Meanings();
86 }
87
88 #endif // HAVE_LIBAIKSAURUS
89
90 // Global instance
91 Thesaurus thesaurus;