2002-08-04 23:11:50 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2009-03-29 19:49:52 +00:00
|
|
|
* \file SpellChecker.h
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-08-04 23:11:50 +00:00
|
|
|
*
|
|
|
|
* \author unknown
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-08-04 23:11:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SPELL_BASE_H
|
|
|
|
#define SPELL_BASE_H
|
|
|
|
|
2007-10-31 22:40:34 +00:00
|
|
|
#include "support/strfwd.h"
|
2006-09-11 08:54:10 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
class BufferParams;
|
2010-02-10 08:10:31 +00:00
|
|
|
class Language;
|
2002-08-13 14:40:38 +00:00
|
|
|
class WordLangTuple;
|
2009-08-02 09:17:32 +00:00
|
|
|
class docstring_list;
|
2002-08-04 23:11:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-06 17:52:58 +00:00
|
|
|
* Pure virtual base class of all spellchecker implementations.
|
2002-08-04 23:11:50 +00:00
|
|
|
*/
|
2009-03-29 19:49:52 +00:00
|
|
|
class SpellChecker {
|
2002-08-04 23:11:50 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// the result from checking a single word
|
|
|
|
enum Result {
|
2005-01-20 16:17:37 +00:00
|
|
|
/// word is correct
|
2010-08-05 20:10:40 +00:00
|
|
|
WORD_OK = 1,
|
2005-01-20 16:17:37 +00:00
|
|
|
/// root of given word was found
|
2010-08-05 20:10:40 +00:00
|
|
|
ROOT_FOUND,
|
2005-01-20 16:17:37 +00:00
|
|
|
/// word found through compound formation
|
|
|
|
COMPOUND_WORD,
|
|
|
|
/// word not found
|
|
|
|
UNKNOWN_WORD,
|
|
|
|
/// number of other ignored "word"
|
2010-08-05 20:10:40 +00:00
|
|
|
IGNORED_WORD,
|
|
|
|
/// number of personal dictionary "word"
|
2012-01-04 22:02:07 +00:00
|
|
|
LEARNED_WORD,
|
|
|
|
/// missing dictionary for language
|
|
|
|
NO_DICTIONARY
|
2002-08-04 23:11:50 +00:00
|
|
|
};
|
|
|
|
|
2009-03-29 19:49:52 +00:00
|
|
|
virtual ~SpellChecker() {}
|
2002-08-04 23:11:50 +00:00
|
|
|
|
2010-08-05 20:10:40 +00:00
|
|
|
/// does the spell check failed
|
|
|
|
static bool misspelled(Result res) {
|
2010-12-01 08:25:17 +00:00
|
|
|
return res != WORD_OK
|
|
|
|
&& res != IGNORED_WORD
|
2012-01-04 22:02:07 +00:00
|
|
|
&& res != NO_DICTIONARY
|
2010-12-01 08:25:17 +00:00
|
|
|
&& res != LEARNED_WORD; }
|
2010-08-05 20:10:40 +00:00
|
|
|
|
2002-08-06 22:38:44 +00:00
|
|
|
/// check the given word of the given lang code and return the result
|
2009-03-29 19:49:52 +00:00
|
|
|
virtual enum Result check(WordLangTuple const &) = 0;
|
2010-09-04 07:48:15 +00:00
|
|
|
|
2009-08-02 09:17:32 +00:00
|
|
|
/// Gives suggestions.
|
|
|
|
virtual void suggest(WordLangTuple const &, docstring_list & suggestions) = 0;
|
2002-08-04 23:11:50 +00:00
|
|
|
|
2012-03-02 10:20:09 +00:00
|
|
|
/// Lemmatizing: return stem of word (used by Thesaurus).
|
|
|
|
virtual void stem(WordLangTuple const &, docstring_list & suggestions) = 0;
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
/// insert the given word into the personal dictionary
|
2009-03-29 19:49:52 +00:00
|
|
|
virtual void insert(WordLangTuple const &) = 0;
|
2002-08-04 23:11:50 +00:00
|
|
|
|
2010-08-05 20:10:40 +00:00
|
|
|
/// remove the given word from the personal dictionary
|
|
|
|
virtual void remove(WordLangTuple const &) = 0;
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
/// accept the given word temporarily
|
2009-03-29 19:49:52 +00:00
|
|
|
virtual void accept(WordLangTuple const &) = 0;
|
2002-08-04 23:11:50 +00:00
|
|
|
|
2010-02-10 08:10:31 +00:00
|
|
|
/// check if dictionary exists
|
|
|
|
virtual bool hasDictionary(Language const *) const = 0;
|
|
|
|
|
2012-01-04 22:02:07 +00:00
|
|
|
/// how many valid dictionaries were found
|
|
|
|
virtual int numDictionaries() const = 0;
|
|
|
|
|
2010-09-04 07:48:15 +00:00
|
|
|
/// if speller can spell check whole paragraph return true
|
|
|
|
virtual bool canCheckParagraph() const { return false; }
|
|
|
|
|
|
|
|
/// count of misspelled words
|
|
|
|
virtual int numMisspelledWords() const { return 0; }
|
|
|
|
|
|
|
|
/// start position and length of misspelled word at index
|
|
|
|
virtual void misspelledWord(
|
|
|
|
int /* index */,
|
|
|
|
int & start, int & length) const
|
|
|
|
{
|
|
|
|
/// index is used here to make the compiler happy
|
|
|
|
start = 0;
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
/// give an error message on messy exit
|
2009-03-29 19:49:52 +00:00
|
|
|
virtual docstring const error() = 0;
|
2010-12-01 08:25:17 +00:00
|
|
|
|
2010-09-14 05:24:04 +00:00
|
|
|
/// spell checker state versioning support
|
|
|
|
typedef unsigned long int ChangeNumber ;
|
|
|
|
ChangeNumber changeNumber() const { return change_number_; }
|
|
|
|
void changeNumber(ChangeNumber value) { change_number_ = value; }
|
|
|
|
void nextChangeNumber() { ++change_number_; }
|
|
|
|
virtual void advanceChangeNumber() = 0;
|
2010-12-01 08:25:17 +00:00
|
|
|
|
2010-09-14 05:24:04 +00:00
|
|
|
private:
|
|
|
|
ChangeNumber change_number_;
|
2002-08-04 23:11:50 +00:00
|
|
|
};
|
|
|
|
|
2009-03-30 07:44:01 +00:00
|
|
|
/// Access to the singleton SpellChecker.
|
|
|
|
/// Implemented in LyX.cpp
|
|
|
|
SpellChecker * theSpellChecker();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2009-08-08 17:05:31 +00:00
|
|
|
/// Set the singleton SpellChecker engine.
|
|
|
|
/// Implemented in LyX.cpp
|
|
|
|
void setSpellChecker();
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
#endif // SPELL_BASE_H
|