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