[Library] Spell v2.0 (Preview)

Post your working scripts, libraries and tools
User avatar
jballi
Posts: 587
Joined: 29 Sep 2013, 17:34

[Library] Spell v2.0 (Preview)

25 Oct 2014, 14:29

Post History
This library was first released on the original AutoHotkey forum by majkinetor. You can find the original post here. New versions of the library, if any, will be posted on this forum.

Introduction
Hunspell is a spell check subsystem that was created in 2003. Because it's free and open source, it is incorporated in many applications including OpenOffice, LibreOffice, Mozilla Thunderbird & Firefox, and Google Chrome, just to name a few.

The Spell library is a wrapper for the Hunspell API.

Spell Library
Key features:
  • Compatibility. [v2.0+] The Spell library can be used with all versions of AutoHotkey including x64. The previous versions were limited to AutoHotkey Basic and the ANSI version of AutoHotkey v1.1+.
  • Custom Dictionaries. [v1.1+] Words from one or more "custom" dictionaries can be quickly added to the active dictionary.
  • Portable and Independent. The Hunspell DLLs and dictionary files can be stored anywhere. Other than the optional custom dictionary files, the library does not use any other programs, files, or services.
The Code
The pertinent files are as follows:
  • Project: Spell Unicode.zip. This archive includes the Spell library, the Hunspell DLL files, example scripts, and all the files needed to run the example scripts.
  • Documentation: Spell Library
Version 2.0

API
Version 2.0 of the Spell library is now based on v0.9.2.0 of the NHunspell Spell Checker API. The modules are compiled for Unicode and there is a x86 and a x64 version of the DLL files. These components allow the Spell library to run on all versions of AutoHotkey.

The new Hunspell DLL files are named Hunspellx86.dll and Hunspellx64.dll. These files are used instead of hunspelldll.dll which was used by the 1.x versions of the library.

Please note that this version of the NHunspell API is not the latest version. Not even close. v0.9.2.0 was released in 2009 but is one of last versions of the API that runs independently. Newer versions of the API depend quite a bit on the .NET environment and requires additional software to be installed.

What's Different
From a functional perspective, v2.0 is virtually the same as v1.1 with new features added. From a developer perspective, there are several important changes of note:
  • The Spell_AddCustomWord function has been renamed to Spell_AddCustom. Also, the return value has changed. See the function documentation for the details.
  • Spell_Init. Two important changes. First, the p_CustomDic parameter has been removed. Call the Spell_InitCustom function directly to load words from a custom dictionary. Next, there are important usability improvements to the DLLPath parameter. See the function documentation for the details.
  • The Spell_PutWord function has been renamed to Spell_Add. The name is patterned after the API function name.
  • The Spell_GetEncoding function is no longer available. The new API does not support this feature. Although not programmer friendly, the dictionary's encoding can be found in the affix file (Ex: "en_US.aff"). Look for the "SET" command (Ex: "SET UTF-8").
What's New
A few important changes:
  • Spell_Init. This function has beefed-up to ensure that dictionary and DLL files exists before proceeding. These changes help to keep AutoHotkey from crashing when key files cannot be found. Hint: Do not call any other library functions if the return value from this function is not valid.
  • Spell_Add (formerly Spell_PutWord). The p_Word parameter has been updated so that more than one word can be added a time. This change allows for an entire custom dictionary to be loaded in a single call. Also, a new optional p_AddCase parameter has been added. See the function documentation for the details.
  • Spell_AddCustom (formerly Spell_AddCustomWord). The p_Word parameter has been updated so that more than one word can be added a time. See the function documentation for more information.
  • Spell_InitCustom. A new optional p_AddCase parameter has been added. See the Spell_Add documentation for the details.
Issues/Considerations
Stuff to know:
  • Preview release. Because of the large number of changes to the library, this is a preview release. Everything is subject to change.
  • Compatibility. The library was designed to run on all versions of AutoHotkey and most versions of Windows (XP+). I have tested this software on AutoHotkey Basic and a recent version of AutoHotkey v1.1+ (ANSI and Unicode, 32-bit and 64-bit) but I only have one PC to test this software on (currently Windows 7 SP1 64-bit). If you experience any problems with your version of AutoHotkey or Microsoft Windows, please let me know. I will try to correct the problem.
  • Dictionaries. Thanks to Apache OpenOffice, dictionaries for a dozen or so languages can be found on their web site. See the References section for the link. However, Hunspell dictionaries for other languages may be hard to find. There are many languages for which there are no Hunspell dictionaries.
  • Dictionary testing. Although I've done my best, my ability to do any serious tests on dictionaries other than US English, is severely limited. If you experience any problems with your dictionary, please let me know. I will try to correct the problem.
  • Suggestions. Probably won't affect most developers/users but just in case... Finding suggestions for a misspelled word is a resource intensive task. For most dictionaries, the request is handled in a timely manner for most words. The request takes 200 ms or less, usually much much less. However, for a few dictionaries (I found this while testing a French dictionary), this request can take a very noticeable amount of time for some words. I've observed a response time of 500 ms or more. Since getting suggestions for a misspelled word is primarily an API task, there is not much that can be done to improve the performance of this request.
  • Examples. If any of the examples don't work as expected, please let me know. I will try to correct the problem.
  • Licensing. I haven't done all of the necessary due diligence on the licensing needed in order publish a script using the Spell library. Here's what I have so far... The API was built under Hunspell's open source license. The dictionaries available via OpenOffice are also released under an open source license. However, dictionaries found in the wild (no example yet) may be licensed separately. Be sure to check carefully before publishing a script using a dictionary found in the wild.
References
The following are a few links that may be helpful.
Observations and Final Thoughts
I have several applications that use the old Spell v1.1 library. I created this version of the Spell library in order to be able to eventually convert these applications to AutoHotkey v1.1+ and then to the 64-bit version of AutoHotkey. I have been using this library for a couple of weeks now and so far, everything is working as expected.

Initial tests show that the library runs the most efficiently on the 32-bit version of AutoHotkey v1.1+ (Unicode). This is logical since words do not have to converted from/to ANSI as they do when using an ANSI version of AutoHotkey. Don't worry, the ANSI versions of AutoHotkey are only a tiny bit slower than the 32-bit Unicode version of AutoHotkey when using the Spell library. I was surprised that the 64-bit version of AutoHotkey runs about the same speed as AutoHotkey Basic and the ANSI version of AutoHotkey v1.1+. I've got an old PC with only 4GB of memory so that may have something to do with my test results.

I need your feedback. If there are any bugs, compatibility problems, or if there is a better way accomplish a particular task, please let me know!

---------------------------------------------------------------------------
Release Notes

v2.0 (Preview)
First release of v2.0 library which uses new Hunspell DLLs.
Last edited by jballi on 24 Mar 2017, 15:57, edited 1 time in total.
User avatar
joedf
Posts: 7357
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: [Library] Spell v2.0 (Preview)

26 Oct 2014, 10:26

Datz eh kool Zkript! :D
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]

Return to “Scripts and Functions”

Who is online

Users browsing this forum: AHK_user, arion, Bing [Bot] and 53 guests