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