blob: 2a36930b2ab1b80407cc4d1f1e1f2f20d72458fb (
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
|
/*
* Copyright (c) 2011 Voicu Vlad
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <SwifTools/HunspellChecker.h>
#include <algorithm>
#include <hunspell/hunspell.hxx>
#include <boost/algorithm/string.hpp>
namespace Swift {
HunspellChecker::HunspellChecker(const char* affix_path, const char* dictionary_path) {
speller_ = new Hunspell(affix_path, dictionary_path);
}
HunspellChecker::~HunspellChecker() {
delete speller_;
}
bool HunspellChecker::isCorrect(const std::string& word) {
return speller_->spell(word.c_str());
}
void HunspellChecker::getSuggestions(const std::string& word, std::vector<std::string>& list) {
char **suggestList;
int words_returned;
if (!word.empty()) {
words_returned = speller_->suggest(&suggestList, word.c_str());
}
for (int i = 0; i < words_returned; ++i) {
list.push_back(suggestList[i]);
free(suggestList[i]);
}
}
}
|