// Dictionary.h: interface for the Dictionary class.
#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_
#include "..\stdafx.h"
#include <string>
#include <vector>
using namespace std;

#include "ChipMonkTypes.h"

struct IndxEntry{
	int m_nFirst, m_nLast;
};

int CountWords(const WCHAR *pDict, int nSize);
int GetWordLength(const WCHAR *pWord);
int WordLength(const WCHAR *pCurrWord);
WCHAR *GetNextWord(WCHAR *pWords);
void GetFirst3Letters(const WCHAR *pCurrWord, WCHAR *p3Letters);
BOOL IsANumber(const wstring & sWord);


class Dictionary
{

public:

	static Dictionary* Instance();
	static Dictionary* SetLanguage(int nLangIndx);
	
	virtual ~Dictionary();
	
	virtual BOOL Init(const char * installDir) = 0;

	virtual BOOL FilterOutIllegalChars(const WCHAR *pSrc, WCHAR *pDest)const;
	virtual WCHAR *OptimalMerge(WCHAR **ppTexts,  int nTexts, int nThreshold, BOOL *pNotOverlap);
	virtual const WCHAR *MergeText(WCHAR *pText0, WCHAR *pText1);
	virtual WCHAR *MergeLines(const WCHAR *pLine0, const WCHAR *pLine1, WCHAR *pRes = NULL);
	virtual int InDictionary(const WCHAR *pLine, int pos);
	virtual BOOL CheckNotMatchedWord(const WCHAR *pWord);
	virtual int FilterLine(const WCHAR *pLine, WCHAR *pNewLine);
	virtual WCHAR *FilterText(const WCHAR *pText, int nValidToNotRatio /* *256 */, int &nQuality);
	virtual void FilterText(WCHAR *pText, int nValidToNotRatio = 256);
	virtual const WCHAR *CountValidWords(const WCHAR *pLine, int &nWord, int &nNoWord);
	virtual BOOL LookUp(const WCHAR *pWord);
	virtual const WCHAR *CountFoundWords(const WCHAR *pLine, int &nWord, int &nNoWord, int nMinWordLength);
	virtual bool CheckText(const WCHAR *pText);
	virtual BOOL SpellCheck(wstring & sWord, BOOL speaking);
	virtual BOOL ValidCharacter(WCHAR c)const = 0;
	virtual BOOL InWordValidCharacter(WCHAR c)const = 0;
	virtual int CompareWords(const WCHAR *w0, const WCHAR *w1)const;
	void Sort(const char *pSaveFileName = NULL);
	virtual int WordLength(const WCHAR *pCurrWord)const;
	virtual void GetFirst3Letters(const WCHAR *pCurrWord, WCHAR *p3Letters) const;
	virtual void ToLower(wstring & s) const;


protected:

	Dictionary();

	virtual int GettLetterIndx(WCHAR c)const = 0;
	virtual WCHAR ToLower(WCHAR c)const = 0;
	virtual int ToLower(const WCHAR *pSrc, WCHAR *pDest) const;
	virtual void ConvertToLower(WCHAR &c)const = 0;
	int GetWordLength(const WCHAR *pWord)const;

	static Dictionary* mInstance;

	static int m_nLangIndx;

	int m_nNUM_OF_LETTERS;

	WCHAR *m_pDict, **m_pWords;
	IndxEntry *m_pIndx;
	WCHAR m_pCurrWord[MAX_PATH];
	void AddToShortWords(const WCHAR *pCurrWord, int nLength);
	BOOL *m_pOneLetWords, *m_pTwoLetWords;
	vector<pair<wstring, vector<wstring> > > m_vRepalcement;
};

wstring & TrimString(wstring & s);

/* ------------------------------------------------------------------------ */
/*	Language                                                                 */
/* ------------------------------------------------------------------------ */
#define RTK_ENGLISH		0x1
#define RTK_FRENCH		0x2
#define RTK_GERMAN		0x4
#define RTK_ITALIAN		0x8
#define RTK_SPANISH		0x10
#define RTK_PORTUGUESE	0x20
#define RTK_DANISH		0x40
#define RTK_DUTCH 		0x80
#define RTK_NORWEGIAN	0x100
#define RTK_SWEDISH		0x200
#define RTK_RUSSIAN		0x400
#define RTK_FINNISH		0x800


#endif // _DICTIONARY_H_
