// ignore for session
void AppleSpellChecker::accept(WordLangTuple const & word)
{
	string const word_str = to_utf8(word.word());
	AppleSpeller_ignore(d->speller, word_str.c_str());
	LYXERR(Debug::GUI, "ignore word: \"" << word.word() << "\"") ;
	advanceChangeNumber();
}
// remove from personal dictionary
void AppleSpellChecker::remove(WordLangTuple const & word)
{
	string const word_str = to_utf8(word.word());
	AppleSpeller_unlearn(d->speller, word_str.c_str());
	LYXERR(Debug::GUI, "unlearn word: \"" << word.word() << "\"") ;
	advanceChangeNumber();
}
void AspellChecker::Private::insert(WordLangTuple const & word)
{
	Spellers::iterator it = spellers_.find(word.lang()->lang());
	if (it != spellers_.end()) {
		addToSession(it->second.e_speller, word.word());
		PersonalWordList * pd = personal_[word.lang()->lang()];
		if (!pd)
			return;
		pd->insert(word.word());
	}
}
SpellChecker::Result AppleSpellChecker::check(WordLangTuple const & word)
{
	if (!hasDictionary(word.lang()))
		return WORD_OK;

	string const word_str = to_utf8(word.word());
	string const lang = d->languageMap[word.lang()->lang()];
	SpellCheckResult result =
		AppleSpeller_check(d->speller,
			word_str.c_str(), lang.c_str());
	LYXERR(Debug::GUI, "spellCheck: \"" <<
		   word.word() << "\" = " << d->toString(result) <<
		   ", lang = " << lang) ;
	return d->toResult(result);
}
void AspellChecker::suggest(WordLangTuple const & wl,
	docstring_list & suggestions)
{
	suggestions.clear();
	AspellSpeller * m = d->speller(wl.lang());

	if (!m)
		return;

	string const word = d->toAspellWord(wl.word());
	AspellWordList const * sugs =
		aspell_speller_suggest(m, word.c_str(), -1);
	LASSERT(sugs != 0, return);
	AspellStringEnumeration * els = aspell_word_list_elements(sugs);
	if (!els || aspell_word_list_empty(sugs))
		return;

	for (;;) {
		char const * str = aspell_string_enumeration_next(els);
		if (!str)
			break;
		suggestions.push_back(from_utf8(str));
	}

	delete_aspell_string_enumeration(els);
}
bool AspellChecker::Private::learned(WordLangTuple const & word)
{
	PersonalWordList * pd = personal_[word.lang()->lang()];
	if (!pd)
		return false;
	return pd->exists(word.word());
}
Exemple #7
0
void EnchantChecker::accept(WordLangTuple const & word)
{
	enchant::Dict * m = d->speller(word.lang()->code());
	if (m) {
		m->add_to_session(to_utf8(word.word()));
		advanceChangeNumber();
	}
}
Exemple #8
0
void EnchantChecker::remove(WordLangTuple const & word)
{
	enchant::Dict * m = d->speller(word.lang()->code());
	if (m) {
		m->remove(to_utf8(word.word()));
		advanceChangeNumber();
	}
}
Exemple #9
0
SpellChecker::Result EnchantChecker::check(WordLangTuple const & word)
{
	enchant::Dict * m = d->speller(word.lang()->code());

	if (!m)
		return NO_DICTIONARY;

	if (word.word().empty())
		return WORD_OK;

	string utf8word = to_utf8(word.word());

	if (m->check(utf8word))
		return WORD_OK;

	return UNKNOWN_WORD;
}
void AspellChecker::accept(WordLangTuple const & word)
{
	Spellers::iterator it = d->spellers_.find(word.lang()->lang());
	if (it != d->spellers_.end()) {
		d->addToSession(it->second.e_speller, word.word());
		d->accept(it->second, word);
		advanceChangeNumber();
	}
}
/// personal word list interface
void AspellChecker::Private::remove(WordLangTuple const & word)
{
	PersonalWordList * pd = personal_[word.lang()->lang()];
	if (!pd)
		return;
	pd->remove(word.word());
	Spellers::iterator it = spellers_.find(word.lang()->lang());
	if (it != spellers_.end()) {
		initSessionDictionary(it->second, pd);
	}
}
void AppleSpellChecker::suggest(WordLangTuple const & wl,
	docstring_list & suggestions)
{
	suggestions.clear();
	string const word_str = to_utf8(wl.word());
	size_t num = AppleSpeller_makeSuggestion(d->speller, 
					word_str.c_str(), wl.lang()->code().c_str());
	for (size_t i = 0; i < num; i++) {
		char const * next = AppleSpeller_getSuggestion(d->speller, i);
		if (!next) break;
		suggestions.push_back(from_utf8(next));
	}
}
SpellChecker::Result AspellChecker::Private::check(
	AspellSpeller * m, WordLangTuple const & word) 
	const
{
	SpellChecker::Result result = WORD_OK;
	docstring w1;
	docstring rest = split(word.word(), w1, '-');
	for (; result == WORD_OK;) {
		string const word_str = toAspellWord(w1);
		int const word_ok = aspell_speller_check(m, word_str.c_str(), -1);
		LASSERT(word_ok != -1, return UNKNOWN_WORD);
		result = (word_ok) ? WORD_OK : UNKNOWN_WORD;
		if (rest.empty())
			break;
		rest = split(rest,w1,'-');
	}
	if (result == WORD_OK)
		return result;
	string const word_str = toAspellWord(word.word());
	int const word_ok = aspell_speller_check(m, word_str.c_str(), -1);
	LASSERT(word_ok != -1, return UNKNOWN_WORD);
	return (word_ok) ? WORD_OK : UNKNOWN_WORD;
}
SpellChecker::Result AspellChecker::check(WordLangTuple const & word)
{
  
	AspellSpeller * m = d->speller(word.lang());

	if (!m)
		return NO_DICTIONARY;

	if (word.word().empty())
		// MSVC compiled Aspell doesn't like it.
		return WORD_OK;

	SpellChecker::Result rc = d->check(m, word);
	return (rc == WORD_OK && d->learned(word)) ? LEARNED_WORD : rc;
}
Exemple #15
0
void EnchantChecker::suggest(WordLangTuple const & wl,
	docstring_list & suggestions)
{
	suggestions.clear();
	enchant::Dict * m = d->speller(wl.lang()->code());

	if (!m)
		return;

	string utf8word = to_utf8(wl.word());

	vector<string> suggs = m->suggest(utf8word);
	vector<string>::const_iterator it = suggs.begin();

	for (; it != suggs.end(); ++it)
		suggestions.push_back(from_utf8(*it));
}
void AspellChecker::Private::accept(Speller & speller, WordLangTuple const & word)
{
	speller.ignored_words_.push_back(word.word());
}