/src/aspell/common/suggestions.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* This file is part of The New Aspell |
2 | | * Copyright (C) 2001-2002 by Kevin Atkinson under the GNU LGPL |
3 | | * license version 2.0 or 2.1. You should have received a copy of the |
4 | | * LGPL license along with this library if you did not you can find it |
5 | | * at http://www.gnu.org/. */ |
6 | | |
7 | | #ifndef ASPELL_SUGGESTIONS__HPP |
8 | | #define ASPELL_SUGGESTIONS__HPP |
9 | | |
10 | | #include "vector.hpp" |
11 | | #include "char_vector.hpp" |
12 | | #include "convert.hpp" |
13 | | |
14 | | namespace acommon { |
15 | | |
16 | | class SuggestionsData { |
17 | | public: |
18 | | virtual void get_words(Convert *, Vector<CharVector> &) = 0; |
19 | | virtual void get_normalized_scores(Vector<double> &) = 0; |
20 | | virtual void get_distances(Vector<double> &) = 0; |
21 | 2.01k | virtual ~SuggestionsData() {} |
22 | | }; |
23 | | |
24 | | class Suggestions { |
25 | | public: |
26 | | SuggestionsData * sugs_; |
27 | | Convert * from_internal_; |
28 | | Vector<CharVector> words_buffer_; |
29 | | Vector<const char *> words_; |
30 | | Vector<double> normalized_scores_; |
31 | | Vector<double> distances_; |
32 | 0 | void reset() { |
33 | 0 | words_buffer_.clear(); |
34 | 0 | words_.clear(); |
35 | 0 | normalized_scores_.clear(); |
36 | 0 | distances_.clear(); |
37 | 0 | } |
38 | 0 | const char * * words(unsigned * len) { |
39 | 0 | if (words_.empty()) { |
40 | 0 | sugs_->get_words(from_internal_, words_buffer_); |
41 | 0 | words_.reserve(words_buffer_.size()); |
42 | 0 | for (Vector<CharVector>::iterator i = words_buffer_.begin(), e = words_buffer_.end(); i != e; ++i) |
43 | 0 | words_.push_back(i->data()); |
44 | 0 | } |
45 | 0 | if (len) *len = words_.size(); |
46 | 0 | return words_.data(); |
47 | 0 | } |
48 | 0 | double * normalized_scores(unsigned * len) { |
49 | 0 | if (normalized_scores_.empty()) { |
50 | 0 | sugs_->get_normalized_scores(normalized_scores_); |
51 | 0 | } |
52 | 0 | if (len) *len = normalized_scores_.size(); |
53 | 0 | return normalized_scores_.data(); |
54 | 0 | } |
55 | 0 | double * distances(unsigned * len) { |
56 | 0 | if (distances_.empty()) { |
57 | 0 | sugs_->get_distances(distances_); |
58 | 0 | } |
59 | 0 | if (len) *len = distances_.size(); |
60 | 0 | return distances_.data(); |
61 | 0 | } |
62 | | }; |
63 | | |
64 | | } |
65 | | |
66 | | #endif /* ASPELL_SUGGESTIONS__HPP */ |