summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Voicu <vladvoic@gmail.com>2011-11-29 01:15:18 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-09 15:03:59 (GMT)
commit404b087a11144c66416513929eb57c9786f41ffe (patch)
tree7b63584289498f01a2beb9337d5a2ffeb71081b3
parentb8f10af29258705b4610e99ba69f5ecab42ef6ae (diff)
downloadswift-contrib-404b087a11144c66416513929eb57c9786f41ffe.zip
swift-contrib-404b087a11144c66416513929eb57c9786f41ffe.tar.bz2
Modified the Spellchecker to use hunspell instead of aspell
-rw-r--r--SwifTools/SConscript2
-rw-r--r--SwifTools/SpellChecker.cpp42
-rw-r--r--SwifTools/SpellChecker.h7
3 files changed, 20 insertions, 31 deletions
diff --git a/SwifTools/SConscript b/SwifTools/SConscript
index 3e1a105..ac2dc6b 100644
--- a/SwifTools/SConscript
+++ b/SwifTools/SConscript
@@ -7,7 +7,7 @@ Import("env")
if env["SCONS_STAGE"] == "flags" :
env["SWIFTOOLS_FLAGS"] = {
"LIBPATH": [Dir(".")],
- "LIBS": ["SwifTools", "libaspell"]
+ "LIBS": ["SwifTools", "libhunspell"]
}
################################################################################
diff --git a/SwifTools/SpellChecker.cpp b/SwifTools/SpellChecker.cpp
index 8c9aeda..650b283 100644
--- a/SwifTools/SpellChecker.cpp
+++ b/SwifTools/SpellChecker.cpp
@@ -7,45 +7,35 @@
#include <SwifTools/SpellChecker.h>
#include <algorithm>
-#include <aspell.h>
+#include <hunspell/hunspell.hxx>
#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);
+ const char* dictionary_path = "/usr/share/hunspell/en_US.dic";
+ const char* affix_path = "/usr/share/hunspell/en_US.aff";
+ speller_ = new Hunspell(affix_path, dictionary_path);
+}
+
+SpellChecker::~SpellChecker() {
+ delete speller_;
}
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;
+ return speller_->spell(word.c_str());
}
void SpellChecker::getSuggestions(const std::string& word, std::vector<std::string>& list) {
- const AspellWordList *alist;
+ char **suggestList;
+ int words_returned;
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));
- }
+ words_returned = speller_->suggest(&suggestList, word.c_str());
+ }
+ for (int i = 0; i < words_returned; ++i) {
+ list.push_back(suggestList[i]);
+ free(suggestList[i]);
}
}
diff --git a/SwifTools/SpellChecker.h b/SwifTools/SpellChecker.h
index 3a9ff38..1c3148b 100644
--- a/SwifTools/SpellChecker.h
+++ b/SwifTools/SpellChecker.h
@@ -9,17 +9,16 @@
#pragma once
-class AspellSpeller;
-class AspellConfig;
+class Hunspell;
namespace Swift {
class SpellChecker {
public:
SpellChecker();
+ ~SpellChecker();
bool isCorrect(const std::string& word);
void getSuggestions(const std::string& word, std::vector<std::string>& list);
private:
- AspellSpeller* speller_;
- AspellConfig* config_;
+ Hunspell* speller_;
};
}