Custom Dictionaries

Published 02 October 09 09:33 PM | text 

Most current editors provide built in spell checking which validates user input. Spell checkers can be found in anything from word processors, to email clients, and even web browsers. Depending on the scenario, these spell checking utilities vary in complexity. Simple spell checkers compare the input against a default dictionary and then highlight mismatches. More complex spell checkers allow dynamic modification of the dictionary.

 

WPF includes a spell checker, but currently it only uses the OS provided dictionary for input validation. It lacks the functionality to allow the default dictionaries to be augmented with custom dictionaries provided by an application. This has been a major issue for apps which target specific industries with specialized lingo. Those apps are plagued by misspelling notifications.

 

A chat client is a classic example of an application that displays specialized words. In such an application, web slang such as lol, brb, or ttyl is frequently used. While these acronyms are not official words in English, in the context of a chat client these are not misspelled words.

 

This problem has been fixed in WPF 4.0. The ability to augment spelling support, via an application provided custom dictionary, has been added to the framework.

 

 

 

Custom Dictionaries API

The property CustomDictionaries has been added to the SpellCheck class.

·        CustomDictionaries - This is a read-only dependency property which is an IList of URIs. Each URI points to a custom dictionary to be used for spell checking.  If spell checking is disabled, SpellCheck.IsEnabled == false, no spell checking will occur, even if a custom dictionary is provided.

 

Custom Dictionary Format

Custom dictionaries are simple text files with single words on each line. Each line represents a legitimate word which should not be marked as misspelled.

 

The first line of this file can specify a language that the custom dictionary should correspond to (e.g. “#LID 1033” means that this custom dictionary applies to US English). If no language is set, the custom dictionary will apply to all default dictionaries.

·        #LID 1033 – English

·        #LID 3082 - Spanish

·        #LID 1031 - German

·        #LID 1036 - French

 

Comments are not supported inside the custom dictionary file.

 

 

<Window x:Class="CustomSpellerDictionaries.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:sys1="clr-namespace:System;assembly=system"

        Title="Custom Dictionaries Example">

    <Grid>

        <TextBox Text="Finallly, my name, Chipalo, is not marked as misspelled."

                 TextOptions.TextFormattingMode="Display">

            <SpellCheck.IsEnabled>true</SpellCheck.IsEnabled>

            <SpellCheck.CustomDictionaries>

                <sys1:Uri>D:\TEMP\dictionary.lex</sys1:Uri>

            </SpellCheck.CustomDictionaries>

        </TextBox>

    </Grid>

</Window>

 

Contents of D:\TEMP\dictionary.lex

Chipalo

 

CustomDictionaries

TextBlock created with the above XAML. Notice that spell checking is enabled but “Chipalo” is not marked as misspelled.

 

 

 

Custom Dictionaries Suggested Usage

 

Custom dictionaries should be used when an application wants a set of words, which are not found in the default dictionary for a language, to not be marked as misspelled. Specifying a langue for a custom dictionary will limit the use of the dictionary to only the denoted language. A custom dictionary which is not marked as language specific will be used for spell checking in all languages which spell checking is supported.

 

Spelling support in WPF is limited to four languages: English, Spanish, French, and German. Custom dictionaries are designed to augment the default dictionaries for these languages and not to extend spelling support to other languages. Creating a custom dictionary which contains common Russian words, marking the dictionary as a Russian dictionary, and adding it to the SpellCheck object of a TextBox or RichTextbox will not add Russian spelling support. If the first line of a custom dictionary denotes that the dictionary is used for a language which is not supported, that dictionary will be ignored. 

 - Chipalo

Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Ruben said on October 26, 2009 2:30 PM:

Still no additional dictionaries? AND the CustomDictionaries API is off limits to other languages? That's not a feature. That's the LACK of a feature as far as I'm concerned.

# Junior Osei said on November 5, 2009 1:39 AM:

I kinda agree with Ruben. I would like to add a custom dictionary of my words, in effect, my own language. It would have been great if I could create my own language with custom dictionaries.

# text said on November 6, 2009 8:27 AM:

Ruben - I would agree that additional dictionaries and customization of existing dictionaries are distinct features.  Both features are targeted at specific scenarios and have different design considerations. For example, additional dictionaries (which support another language) are much larger than dictionary addons (which support industry specific lingo). The two need to be created, processed, and stored differently. We have done the work to support modification of existing dictionaries in WPF 4.0, and we would like to extend this work in future releases to support additional dictionaries.

Chipalo

# EugeneMcCarthy said on November 9, 2009 6:47 AM:

I would like very much if you have a window that can spell like I had in XP

# text said on November 9, 2009 1:31 PM:

Eugene - Sorry I am not sure which feature you are referring to.

# Luke said on November 11, 2009 6:27 AM:

Good to hear that custom dictionaries are in .NET 4.0.  However, where can I locate detailed information on what dictionaries are available?

I understand only 4 languages are supported, English, German, French and Spanish are available.  But is only en-US supported, how about en-GB?

Documentation on this topic in MSDN docs. seems sparse at best.  Where can I locate exact details on the languages supported?

# Nicola said on November 17, 2009 3:25 AM:

I agree with Ruben, this is a missing feature for all people speaking other than english, french, german or spanish.

"...WPF includes a spell checker, but currently it only uses the OS provided dictionary for input validation..." this is exactly what is expected from a feature like this, italian dictionary for an italian OS...

I can't see any valid reason to limit this to only 4 languages, having MS full dictionaries for all localized Office version...

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Page view tracker