Monday, November 16, 2009

NHunspell - 0.9.2 released and two cool C# & VB.Net Code Projects too

CodeProject - Spell Check, Hyphenation and Thesaurus for .NET with C# and VB Samples Part 1: Single Threading

Introduction

Spell checking, hyphenation and synonym lookup via thesaurus are the Open Office spell checker Hunspell functions. The NHunspell project makes these functions available for .NET applications. As the Open Office spell checker Hunspell is used in a vast amount of open source applications it could also be the first choice for .NET applications. Beyond Open Office Hunspell is currently used in the Mozilla applications Firefox and Thunderbird, the browsers Google Chrome and Opera and last but not least in the new Apple MAC OS/X 10.6 "Snow Leopard" operating system.

Since the first steps (NHunspell - Hunspell for the .NET platform) NHunspell has improved a lot and goes straight to the first release candidate. The current release 0.9.2 is a milestone because the support of Hunspell is nearly complete.

Using NHunspell spell check, hyphenation and thesaurus in single threaded applications

NHunspell is designed to serve two different use cases: Single threaded applications, like word processors and any other tool with a UI/GUI and multi threaded applications like servers and web servers (ASP.NET).

This Article covers the Single threaded applications. They use the basic NHunspell classes Hunspell, Hyphen and MyThes. The members aren't thread safe. If these classes are used by multiple treads a synchronization mechanism like lock must be used. But NHunspell provides special multi threading classes which are announced in the second part of the article: Spell checking, hyphenation and thesaurus in multi threading applications

…”

CodeProject  - Spell Check, Hyphenation and Thesaurus for .NET with C# and VB Samples Part 2: Multi Threading 

“…

Background

Spell checking, hyphenation and thesaurus functions are based on dictionaries. These dictionaries and the marshalling buffers between .NET and the native DLLs are exclusive resources. The synchronization mechanism prevents the use of these resources by more than one thread. This has an huge performance impact on multi processor or even multi core computers. From performance point of view it is best when as many Hunspell, Hyphen or MyThes objects are used as processor cores are available. So each processor core has a object available to process requests. The SpellEngine class in conjunction with the SpellFactory class provides this feature out of the box. By default it instantiates as many objects as processor cores are available. The access to these object is internally controlled by a Semaphore.  

General Multi Threading Usage of NHunspell

The following code shows the methods of the SpellEngine and SpellFactory classes. It is obvious that in real server applications these objects aren't created and destroyed on every request. They are created at service start and disposed at service end and all requests are served by the same object (singleton pattern). So it is clear that you will never find this using{} block in a server application. But this is for demonstration purposes only. How it woks in a real ASP.NET application is explained later. 

…”

SourceForgeNHunspell

image

No need to spend tons on a spell checker or automate into Office, Word, etc; check out NHunspell instead. Your free, as in LGPL, .Net library spell checker…

Note the license from the project home page;

“…

Licence

NHunspell is licenced under: GPL/LGPL/MPL. Free use in commercial applications is permittet according to the LGPL and MPL licenses. Your commercial application can link against the NHunspell DLLs. \

…”

Related Past Post XRef:
Hunspell (Open Office’s Spell Checker) wrapped for .Net = NHunspell – Your LGPL spell checker, hyphenation library for .Net

3 comments:

Anonymous said...

Now that WPF has a built-in option for spell checking, there really isn't much of a need for this.

Greg said...

You assume everyone is on or moving to WPF.

That's not always the case... [long deep sigh]

Anonymous said...

Sorry the dictionaries of the WPF spell checkers are rare and NHunspell has support for hyphenation and thesaurus. Where is the similar WPF stuff?