/* * Copyright (c) 2011 Voicu Vlad * Licensed under the Simplified BSD license. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include namespace Swift { SpellChecker::SpellChecker() { 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) { return speller_->spell(word.c_str()); } void SpellChecker::getSuggestions(const std::string& word, std::vector& 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]); } } }