Tuesday, October 11, 2005

Multi-Lingual Spell Checking in Crossword Forge

Crossword Forge has had an English spell checker for the last six months. Still I've found that I've wanted it to do more. Since Crossword Forge is a natural fit for foreign language teachers, I've always thought it would be great if it could bring multi-lingual spell checking to its users as well.

The question on how to proceed with that was a tough one. Do I add additional dictionaries to the current spell checker, or do I try to leverage the spell checker built-in into Mac OS X (which is already multi-lingual). There were pros and cons to both approaches. By adding my own dictionaries, I could ensure that the feature would be available to all my customers at the same time and in the same way (i.e. Windows users would get the feature as well). But it would mean that I was responsible for the reliability of the free dictionaries I found, and I would have to produce a phonetic variant of those dictionaries for each of the languages I wanted to support. It would also mean that Crossword Forge was going to get bigger (the built-in dictionaries take up space), or more complicated (I could have the user download the additional dictionaries separately).

In the end I decided that I would probably eventually want to do both, but should start with the approach that would have the biggest impact in the shortest amount of time. Since most of my current customers were on the Mac, and I could leverage 13 dictionaries in about the same amount of time that it would take to add 1 more dictionary for all the platforms, I decided to go with the OS X integration approach.

A big factor in that decision was Charles Yeomans excellent online book I Declare. The book takes a programmer through the process of integrating Mac OS X spell checker into RB program's step by step. It also gave me a firm enough grasp of the subject, that I felt comfortable going beyond what was presented in the book. Which brings me to a slightly less technical topic "spell checker interface design".

For reasons not entirely clear to me, Apple decided to implement the Mac OS X spell checker window as a non-modal window. This means that, unlike most spell checkers you may have used, Mac OS X's spell checker allows you to modify your document in ways independent of your spell checker, while you are in the process of checking its spelling! For example you could add a paragraph to your document while it is complaining about a misspelled word. The misspelled word in question may not be there any more, or it may no longer be misspelled. Because most other spell checkers are modal (you can't change the document in other ways while you are spell checking) they avoid this situation entirely. The question is, how should the UI respond in those situations.

I was hoping since Apple designed the spell checker this way, they might have a good way of handling it for their apps that use it. Unfortunately Apple seems to have ignored the problem, or at least handled it in what to me seems an unintuitive experience for the end user. For example, If you press the correct button, even when everything about the document has changed, the spell checker will replace the contents of the current selection with the button. This isn't helpful, and could be quite harmful (what if you had performed a select all, operation right before you pressed the correct button. (all of your documents text would be replaced by the corrected word.))

I deviated from Apple's approach in Crossword Forge. The first thing I do differently, is ignore the selection. I instead, store the misspelled word's position in a way that the user can't directly manipulate it (like they can with the selection). If the text itself changes, I look to see if it has effected the position of the misspelled word in question. If so I re-analyze that piece of text (possibly backtracking if necessary) to see if there are new misspelled words in that vicinity. If not, I can safely proceed to replace the corrected word.

Another mistake made by Apple's spell checker is that it doesn't re-consider the current misspelled word when the dictionary is changed. The word may not be misspelled in the new dictionary, and certainly the suggestions should be different. Crossword Forge's implementation corrects this issue.

Despite the rough road, adding multi-lingual spell checking to Crossword Forge was a great experience, and lots of fun. I hope users will enjoy having a multi-lingual spell checker built into their crossword puzzle and word search puzzle generator, as well. If you are interested in trying it out, you can go here: crossword forge download page. If you are on Windows and want multi-lingual spell checking, send me a note. I still plan on tackling the problem myself, but a friendly reminder may help me prioritize it.