]> git.lyx.org Git - lyx.git/blob - src/Thesaurus.C
ws changes only
[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 #include <algorithm>
16 #include <string>
17
18 using std::string;
19
20 #ifdef HAVE_LIBAIKSAURUS
21
22 using std::sort;
23
24
25 Thesaurus::Thesaurus()
26 {
27         aik_ = new Aiksaurus;
28 }
29
30
31 Thesaurus::~Thesaurus()
32 {
33         delete aik_;
34 }
35
36
37 Thesaurus::Meanings Thesaurus::lookup(string const & text)
38 {
39         Meanings meanings;
40
41         if (!aik_->find(text.c_str()))
42                 return meanings;
43
44         // weird api, but ...
45
46         int prev_meaning = -1;
47         int cur_meaning;
48         string meaning;
49
50         // correct, returns "" at the end
51         string ret = aik_->next(cur_meaning);
52
53         while (!ret.empty()) {
54                 if (cur_meaning != prev_meaning) {
55                         meaning = ret;
56                         ret = aik_->next(cur_meaning);
57                         prev_meaning = cur_meaning;
58                 } else {
59                         if (ret != text) {
60                                 meanings[meaning].push_back(ret);
61                         }
62                 }
63
64                 ret = aik_->next(cur_meaning);
65         }
66
67         for (Meanings::iterator it = meanings.begin();
68                 it != meanings.end(); ++it) {
69                         sort(it->second.begin(), it->second.end());
70         }
71
72         return meanings;
73 }
74
75 #else
76
77 Thesaurus::Thesaurus()
78 {
79 }
80
81
82 Thesaurus::~Thesaurus()
83 {
84 }
85
86
87 Thesaurus::Meanings Thesaurus::lookup(string const &)
88 {
89         return Meanings();
90 }
91
92 #endif // HAVE_LIBAIKSAURUS
93
94 // Global instance
95 Thesaurus thesaurus;