Spelling Checker for ColdFusion with Jazzy

Spelling checking is another function I wish ColdFusion supported out of the box. This Christmas I took over the adventure of writing a spelling checker with pure ColdFusion, so it could even works in shared hosting environments, but gave up the journey in the middle of writing a bloom filter realizing I was taking a wrong way. Unlike other adventurers, I got discouraged by my first mistake and turn into Java. But to be fair to myself, everyone in the house asking me to make Kottu for Christmas dinner.

Jazzy is a free and open source Java spelling checker API. It is incredibly fast, works smooth and easy to bring into ColdFusion. Download the jazzy-core.jar, copy into your ColdFusion server's lib folder or brining it in with javaloader or any other way you like. 

Jazzy woks with Open Office dictionaries and Open Office support plenty of languages or you can download British and US dictionaries here too. Load Jazzy library and point into your main dictionary file.  

   1: <cfset Jazzy                        = CreateObject("Java","com.swabunga.spell.engine.SpellDictionaryHashMap").Init(CreateObject("java","java.io.File").Init("#ExpandPath('dictionaries/en_USx.dic')#"))>

If you want to add more than one dictionary file, you can do that too.
   1: <cfset Jazzy                        = CreateObject("Java","com.swabunga.spell.engine.SpellDictionaryHashMap").Init(CreateObject("java","java.io.File").Init("#ExpandPath('dictionaries/en_USx.dic')#"))>
   2:  <cfset Application.Jazzy.addDictionary(CreateObject("java","java.io.File").Init( ExpandPath('dictionaries/en_UK.dic') ))>
   3:  <cfset Application.Jazzy.addDictionary(CreateObject("java","java.io.File").Init( ExpandPath('dictionaries/en_UK2.dic') ))>
Show/Hide Line Numbers . Full Screen . Plain

The object creation took around 300 tick counts and it is not necessary nor smart to bring in the library on each and every word we want to spell check. Better load into an Application or Server variable.

   1: <cfif not StructKeyExists(Application,'Jazzy')>
   2:         <cfset Application.Jazzy                        = CreateObject("Java","com.swabunga.spell.engine.SpellDictionaryHashMap").Init(CreateObject("java","java.io.File").Init("#ExpandPath('dictionaries/en_USx.dic')#"))>
   3: </cfif>
Show/Hide Line Numbers . Full Screen . Plain

Here is how to check if the spelling is correct or not - let's test the word "Collywobblas"

   1: Application.Jazzy.isCorrect('Collywobblas')

This would return Yes or No, and off cause this returns No in this case. Let's ask for suggestions:

   1: Application.Jazzy.getSuggestions('Collywobblas',1)

This returns an array of suggestions. Convert that to into a string

   1: Application.Jazzy.getSuggestions('Collywobblas',1). toString()
gives me the correct word [collywobbles]

Adding words to your dictionary is also simple.

   1: Application.Jazzy.addWord('Batrachomyomachy')
permanently add the word "Batrachomyomachy" into your main dictionary file. All those functions run in less than a single tick count. Sweet.

Jazzy haven't updated since 2005, it is quite an old project. But I don't think much altered in English language since Shakespeare either. Here I put together simple raw working example and also you can download the example files. (You need to load jar file into CFM for get it to work). 

Download (Jazzy.zip)
8 Comments :
Madushan M.
Wednesday 27 March 2013 12:25 PM
Thank you for the post but is it just me or is the DEMO not working?
BTW nothing beats Kottu, Kottu rocks.
Monday 01 April 2013 12:35 PM
Thanks Madushan. I move my server to Railo and I forgot to load classes. Yes. Hitting SL this month - Hoping for some sound Kottu and Kottu sound.
Saturday 23 March 2013 10:01 AM
Is Unicode enabled in the CF end?
Friday 22 March 2013 04:14 AM
Everything works perfect.
But we have problem with italian language, with words like società or perchè .. and in general all words with
òàèéìù . how to forze Jazzy to read with correct caracheters encoding?
regards
Friday 25 January 2013 02:35 PM
Did you or anyone try this on a 64-bit install?
Friday 25 January 2013 11:27 PM
Demo is on 64bit
J V SUBRAMANYAM
Friday 04 January 2013 01:13 AM
weather Spell check as you type (SCAYT) functionality is available in this application. if it is there please inform me and weather it should work with WYSWYG editots like (TinyMCE, FCK editor..)
Friday 04 January 2013 09:37 AM
No. you have to build those interfaces yourself. This is just an example how to get the spelling checked.