Spell

Spellchecking using Hunspell

Summary
SpellSpellchecking using Hunspell
AddCustomWordAdd a word to a custom dictionary file.
GetEncodingGet dictonary encoding
InitInitialise the spellcheck engine,
InitCustomAdd words from a custom dictionary file to the dictionary.
PutWordAdd word to dictionary.
SpellSpellcheck word
SuggestSuggest words for word.
UnintFrees the spell object and the memory allocated to the DLL (unless the DLL was loaded outside of this function library).
Example
About

AddCustomWord

Spell_AddCustomWord(p_CustomDic,  
p_Word,  
p_EOL = "`r`n")

Add a word to a custom dictionary file.

Parameters

p_CustomDicPath to a custom dictionary file.
p_WordWord to add.
p_EOLEnd-Of-Line (EOL) characters.  [Optional] The default is CR+LF.

Returns

TRUE if successful, otherwise FALSE.

Remarks

  • This function DOES NOT update the active dictionary.  Call Spell_PutWord to add the word to the active dictionary.
  • The custom dictionary file must already exist, even if it’s empty.
  • The custom dictionary file must be in a Unix (EOL=LF) or DOS (EOL=CR+LF) format.  This function will add a word followed by the characters in p_EOL parameter (default=CR+LR) to the end of the file.  If editing the file manually, make sure there is a LF or CR+LF after the last word.

GetEncoding

Spell_GetEncoding(ByRef hSpell)

Get dictonary encoding

Init

Spell_Init(ByRef hSpell,  
 aff,  
 dic,  
 CustomDic = "",
 DLLPath = "hunspelldll.dll")

Initialise the spellcheck engine,

Parameters

hSpellVariable that contains the current dictionary information.
affPath to affinity file.
dicPath to dictionary file.
CustomDicPath to a custom dictionary file [Optional].
DLLPathPath and file name for the hunspelldll.dll file.  [Optional] If not defined, the DLL file must be located in the local folder or in the path.

hSpell map

Offset  Description
------  -----------
  0     Handle to the spell object
  4     Handle to the Hunspell DLL library module
  8     Address to the hunspell_initialize function
 12     Address to the hunspell_uninitialize function
 16     Address to the hunspell_spell function
 20     Address to the hunspell_suggest function
 24     Address to the hunspell_suggest_auto function
 28     Address to the hunspell_suggest_free function
 32     Address to the hunspell_get_dic_encoding function
 36     Address to the hunspell_put_word function
 --
 40     Total bytes

InitCustom

Spell_InitCustom(ByRef hSpell,
 p_CustomDic)

Add words from a custom dictionary file to the dictionary.  Words are valid until spell object is destroyed.

Returns

The number of words loaded to the spell object.

Remarks

  • This function must be called AFTER the Spell_Init function.
  • The custom dictionary file must be in Unix (EOL=LF) or DOS (EOL=CR+LF) format.
  • Call this function directly if you wish to load more than one custom dictionary or if you want to know how many words were loaded from the custom dictionary file.  Otherwise, specify the custom dictionary when calling the Spell_Init function.

PutWord

Spell_PutWord(ByRef hSpell,
 word)

Add word to dictionary.  Word is valid until the spell object is destroyed.

Spell

Spell_Spell(ByRef hSpell,
 word)

Spellcheck word

Returns

True or False.

Suggest

Spell_Suggest(ByRef hSpell,
 word,
ByRef sList)

Suggest words for word.

Parameters

wordWord for which to look up for suggestions.
sListReference to variable to receive suggestion word list.

Returns

Number of words in sList

Unint

Frees the spell object and the memory allocated to the DLL (unless the DLL was loaded outside of this function library).

Example

   word = autohotkey

   Spell_Init(hSpell,"dic\en_US.aff", "dic\en_US.dic")
   if Spell_Spell(hSpell, word)
      msgbox OK
   else {
      cnt := Spell_Suggest(hSPell, word, lst)
      msgbox %cnt%`n`n%lst%
   }

   Spell_Uninit( hSpell )
return
Spell_AddCustomWord(p_CustomDic,  
p_Word,  
p_EOL = "`r`n")
Add a word to a custom dictionary file.
Spell_GetEncoding(ByRef hSpell)
Get dictonary encoding
Spell_Init(ByRef hSpell,  
 aff,  
 dic,  
 CustomDic = "",
 DLLPath = "hunspelldll.dll")
Initialise the spellcheck engine,
Spell_InitCustom(ByRef hSpell,
 p_CustomDic)
Add words from a custom dictionary file to the dictionary.
Spell_PutWord(ByRef hSpell,
 word)
Add word to dictionary.
Spell_Spell(ByRef hSpell,
 word)
Spellcheck word
Spell_Suggest(ByRef hSpell,
 word,
ByRef sList)
Suggest words for word.
Close