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