Spell check Functions

Spell Check Functions

SPELLCHECKADDDICTIONARY

Registers and returns the key to a dictionary that will be later used for spell checking.

Syntax

SpellCheckAddDictionary ( dictionaryType, pathDictionary, pathGrammarDictionary, pathOther, culture, options )

Arguments

dictionaryType

Type: string

One of the supported dictionary types. If null or empty, the value defaults to Hunspell. The supported dictionaries are:

  • Custom - This dictionary type lists words in a plain text file where each line contains only one word. To use this dictionary, manually prepare a text file (or export any existing dictionary to a plain text file).
  • OpenOffice - a dictionary provided by Apache OpenOffice.
  • ISpell - dictionaries provided by International Ispell.

dictionaryPath

Type: string

The path to the dictionary path.

dictionaryGrammarPath

Type: string

The path to the affix file in OpenOffice.org format or the to the ISpell affix (.AFF) file.

otherPath

Type: string

The path to the alphabet file, used with custom and Ispell dictionaries.

culture

Type: string

Specifies culture settings (the symbols encoding, language and phonetic specifics). E.g.: en-CA, fr-CA, en-US, etc.

options

Type: int

A bitwise combination of the enumeration values that provide options for spelling. Use SpellCheckOptionsMask to calculate the options. If null, the default value is such that upper case words and words with numbers are ignored.

We bear no responsibility for the content and availability of dictionaries and affix files, since they are part of open-source projects.

Returns

Type: string

An opaque string, representing a speller configuration.

Remarks

Alphabet File

An alphabet file is a plain text file, containing the letter set used for the current dictionary. It is a string of letter characters found in the dictionary's words. They are intended solely to facilitate the construction of suggestions performed by letter additions and replacements. An upper case letter set is sufficient.

To illustrate this idea, here is an example of the French alphabet:

AÀÁÂÄBCÇDEÈÉÊFGHIÌÍÎÏJKLMNOÓÔÕPQRSTUÙÚÛÜVWXYZ

Custom Dictionary

A custom dictionary is a simple text file where each line contains a word to validate.

OpenOffice Dictionary

The Open Office dictionary is similar to ISpell, since it also generates the entire word list based on the Affix file - *.aff, and the Base Words file - *.dic. But note that this standard provides different rules for the Affix file than ISpell, so you can't use the same Affix files for both dictionaries.

In general, Open Office dictionaries are word rich and contain less mistakes than ISpell since they are developed by more people. The dictionaries and affix files used are a part of the OpenOffice.org project and can be downloaded from here: Dictionaries page.

ISpell Dictionary

An ideal dictionary would contain all the words of a given language. However, it's much smaller and more effective to split the dictionary into several parts (depending on the language). For example, in several Indo-European languages, including English, words are derived from the base by adding affixes - prefixes or postfixes. So the size of the dictionary can be greatly reduced if the base words, affixes and the rules for adding affixes to base words are placed into separate files. The complete list of words could be built in-place when necessary. This technique especially proves its effectiveness for synthetic languages (rich in verbal and inflective forms) - Lithuanian or Russian for example.

The ISpell dictionary is based upon this approach. It includes base words and affixes. Physically it is represented by the Alphabet file - *.txt, the Affix file - *.aff and the Base Words file - *.xlg or *.hash. (Note: SpellChecker doesn't provide support for compressed *.hash files, but you may use *.xlg files).

ISpell dictionaries are primarily developed by enthusiasts all over the world, and you may freely find them for different languages on the Web. For example, the English dictionary can be found at ftp://ftp.tue.nl/pub/tex/GB95/ispell-english.zip. Additionally, while developed by different individuals, each ISpell dictionary may be redistributed under its specific license agreement. Most of them are free.

Example

The following example uses the built-in, Hunspell dictionary for the English/Canada culture.

DECLARE @dictkey NVARCHAR
SET @dictkey = SpellCheckAddDictionary(NULL, NULL, NULL, NULL, 'en-CA', 0)

Example

The following example adds a custom dictionary. A custom dictionary is a simple text file where each line contains a single word to be matched.

DECLARE @dictkey NVARCHAR
SET @dictkey = SpellCheckAddDictionary('custom', 'X:\...\CustomEnglish.dic', '', '', 'en-CA', 0)

SPELLCHECKISVALID

Indicates if the input text is a valid word.

Syntax

SpellCheckIsValid ( spellerKey, input )

Arguments

spellerKey

Type: string

The key to the dictionary configuration returned by SpellCheckAddDictionary.

input

Type: string

The word to spell check.

Returns

Type: int

1 if the word is spelled correctly; 0 otherwise.

Example

The following example tests the spelling of "colour" for Canadian English, and the American English spelling "color".

DECLARE @dictkey NVARCHAR
SET @dictkey = SpellCheckAddDictionary(NULL, NULL, NULL, NULL, 'en-CA', 0)
SELECT SpellCheckIsValid(@dictkey, "colour")
SELECT SpellCheckIsValid(@dictkey, "color")

Returns

1

0

SPELLCHECKOPTIONSMASK

Calculates an option mask for use by other spell checking functions. The returned value is an integer.

Syntax

SpellCheckOptionsMask ( ignoreEmails, ignoreMixedCaseWords, ignoreRepeatedWords, ignoreUpperCaseWords, ignoreUrls, ignoreWordsWithNumber )

Arguments

ignoreEmails

Type: int (0 or 1)

1 to indicate that email addresses should be excluded from the check.

ignoreMixedCaseWords

Type: int (0 or 1)

1 to indicate that the spell checker must ignore words containing different case letters in positions other than the first.

ignoreRepeatedWords

Type: int (0 or 1)

1 to indicate that repeating words are ignored.

ignoreUpperCaseWords

Type: int (0 or 1)

1 to indicate that the spell checker must ignore words in which all letters are uppercase.

ignoreUrls

Type: int (0 or 1)

1 to indicate that URLs are ignored.

ignoreWordsWithNumber

Type: int (0 or 1)

1 to indicate that words that contain numbers are ignored.

Return Value

Type: int

The spell check options mask.

Example

This example sets an option mask where mixed and upper case words are ignored.

SELECT SpellCheckOptionsMask(0, 1, 0, 1, 0, 0)

Returns

10

SPELLCHECK

Spell checks the input text and attempts to return suggestions if the word is not valid. A null value indicates that the input is a valid word.

Syntax

SpellCheck ( spellerKey, input )

Arguments

spellerKey

Type: string

The key to the dictionary configuration returned by SpellCheckAddDictionary.

input

Type: string

The word to spell check.

Returns

Type: string

null if the word is valid; otherwise, the word and if possible, suggestions.

Example

DECLARE @dictkey NVARCHAR
SET @dictkey = SpellCheckAddDictionary(NULL, NULL, NULL, NULL, 'en-CA', 0)
SELECT SpellCheck(@dictkey, "color")
SELECT SpellCheck(@dictkey, "colour")

Returns

color - colour colon col or

(null)

REGEXSPLITSPELLCHECKISVALID

Splits the specified input string into words, and spell checks the words that do not match the ignore pattern.

Syntax

RegexSplitSpellChekIsValid ( input, splitPattern, ignorePattern, options, spellCheckerKey )

Arguments

input

Type: string

The string to split and spell check.

splitPattern

Type: string

The pattern to use to split the input string.

ignorePattern

Type: string

The pattern to use to match the parts that are to be skipped spell checking.

options

Type: int

A bitwise combination of the enumeration values that provide options for matching. Use RegexMask to calculate the options.

spellCheckerKey

Type: int

An internally managed value of the dictionary to use for spell checking. Use SpellCheckAddDictionary to configure dictionaries.

Return Value

Type: string

A multiline string; each line contains the mispelled words, with suggestions.

Example

DECLARE @dictkey NVARCHAR
SET @dictkey = SpellCheckAddDictionary(NULL, NULL, NULL, NULL, 'en-CA', 0)
SELECT RegexSplitSpellCheckValid("The foxs jumpz over da fence.", " ", null, 0, @dictkey)

Returns

foxs - fox foxes fox's fobs foes
jumpz - jump jumps jumpy jump z
da - DA ad a d Ada