blob: 8c9aedace60543081fd45bcafd981a4904ccf3a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/*
* Copyright (c) 2011 Voicu Vlad
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <SwifTools/SpellChecker.h>
#include <algorithm>
#include <aspell.h>
#include <boost/algorithm/string.hpp>
namespace Swift {
SpellChecker::SpellChecker() {
AspellCanHaveError* ret;
config_ = new_aspell_config();
ret = new_aspell_speller(config_);
if (aspell_error(ret) != 0) {
//TODO(vladv): Proper log the error
//printf("Error: %s\n",aspell_error_message(ret));
delete_aspell_can_have_error(ret);
}
speller_ = to_aspell_speller(ret);
}
bool SpellChecker::isCorrect(const std::string& word) {
if (!word.empty()) {
int aspell_error = aspell_speller_check(speller_, word.c_str(), -1);
if (aspell_error == 1) {
return true;
} else {
//TODO(vladv): Proper log the error
}
}
return false;
}
void SpellChecker::getSuggestions(const std::string& word, std::vector<std::string>& list) {
const AspellWordList *alist;
if (!word.empty()) {
alist = aspell_speller_suggest(speller_, word.c_str(), -1);
AspellStringEnumeration *els = aspell_word_list_elements(alist);
const char* aword;
while (((aword = aspell_string_enumeration_next(els)) != 0) && list.size() <= 5) {
list.push_back(std::string(aword));
}
}
}
}
|