Click here to Skip to main content
11,478,562 members (70,085 online)
Click here to Skip to main content
Add your own
alternative version

A Spell Checking Engine

, 5 Feb 2001 202.2K 5.5K 107
A free spell checking engine for use in your C++ applications. Includes the current US English dictionary

  Copyright:		2000
  Author:			Matthew T Gullett
  Name:				CFPSSpellCheckEngine
  Part of:			Spell Checking Engine  1 of 1
  Requires:			USMain.dic, [USUser.dic], [USCommon.dic]

  This class is designed to implement a phonetic spell
  checking engine with support for US English (and probably
  UK english)  It implements a simple interface for accessing
  spell checking functions.  It is designed to be very fast
  with support for a user dictionary and a common misspelling
  dictionary to improve performance and user perception.  

  This class is provided -as is-.  No warranty as to the
  function or performance of this class is provided either 
  written or implied.  
  You may freely use this code and modify it as necessary,
  as long as this header is unmodified and credit is given
  to the author in the application(s) in which it is


#if !defined(AFX_FPSSPELLCHECKENGINE_H__9CDCF81C_0F4A_11D3_9EAF_444553540000__INCLUDED_)

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

	BOOL bPresent;
	long lFirstRecord;
	long lLastRecord;

	long lStartPos;
	long lLen;

#define FPSSPELL_MIN_CACHE_SIZE			360000

class CFPSSpellCheckEngine  
	virtual ~CFPSSpellCheckEngine();

	// ***************************************************
	// program specific functions
	virtual BOOL FindWord (LPCSTR lpszWord, CStringList& PossibleMatches);
	virtual BOOL InitEngine();
	virtual void SetDictionaries (LPCSTR lpszMain, LPCSTR lpszUser, LPCSTR lpszCommonUse);
	virtual long GetRecordCount();

	// ***************************************************
	// user interact functions
	virtual void AddWord (LPCSTR lpszWord);
	virtual void IgnoreWord (LPCSTR lpszWord);

	// ***************************************************
	// DD maintance functions
	virtual BOOL SaveWordFile (LPCSTR lpszFileName);
	virtual void BuildMainDIC (LPCSTR lpszWordFile, LPCSTR lpszDICFile);

	// ***************************************************
	// parsing algorithms
	virtual void PhoneticWord (char* szInput, char* szOutput);
	virtual char GetFirstVowel(char* szWord, int& iVowelPos);
	virtual int GetSylableCount (char* szWord);
	virtual void MetaphoneEx(char *szInput, char *szOutput, int iMaxLen = 6);
	virtual int GetVowelCount(char* szWord);

	virtual void RemoveVowelsAndDups(char *szInput, char *szOutput);
	virtual BOOL CheckEndings(LPCSTR lpszW1, int iLen1, LPCSTR lpszW2, int iLen2);
	virtual BOOL IsWordMatch(char *szWord1, int iWord1Len, char *szWord2, int iWord2Len);
	virtual BOOL IsMetaphoneMatch(char* szMeta1, char* szMeta2);
	virtual void FindMatchingWords (LPCSTR lpszWord, CStringList& Matches);
	virtual BOOL GetRecord(long lRecord, char *szWord);
	virtual BOOL FindWordMain (LPCSTR lpszWordToFind);
	virtual void CacheCommonUseWords();
	virtual void CacheUserDic();
	virtual void CacheWords();

	virtual BOOL IsSylableCountsOK (int iWord, int iRecord);
	virtual BOOL IsWordLenOK (int iWordLen, int iRecordWordLen);
	virtual long GetRecordPos (long lRecord);
	virtual BOOL IsVowel (char szChar);
	virtual void TrimRight (char* szText);

	virtual BOOL GetRecord (long lRecord, char* szWord, char* szMetaphon, int & iSylableCount, char* szPhonetic);

	virtual void CacheWordLocations();

	CString m_strMainDic;
	CString m_strUserDic;
	CString m_strCmnUseDic;

	CMapStringToString m_UserDic;
	CMapStringToString m_CmnUseDic;
	CMapStringToString m_RecentFinds;

	int m_iMainHandle;
	char* m_pMainBuffer;
	long m_lMainLen;

	long m_lCacheStartPos;
	long m_lCacheLen;

	CString m_strTempWord;

	FPSSPELL_MAINDIC_ALPOS m_LocationCache[255];

	char* m_pWordCache;

	long	m_lWordsSearched;
	long	m_lComparisonsMade;

	void RemoveVowels (char* szInput, char* szOutput);

#endif // !defined(AFX_FPSSPELLCHECKENGINE_H__9CDCF81C_0F4A_11D3_9EAF_444553540000__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Matt Gullett
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 6 Feb 2001
Article Copyright 2001 by Matt Gullett
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid