ImageGear .NET v24.12 - Updated
Work with a User Dictionary
User Guide > How to Work with... > OCR > How to... > Work with a User Dictionary

Compiling and changing a User dictionary requires that the application specify a User dictionary file with the ImGearRecUserDictionary.Load Method or create a new dictionary using the Create Method. At this point the content of the User dictionary can be listed, and items can be added or removed on request. Accessing the contents of the User dictionary or performing editing operations will open it for maintenance. If the User dictionary has been opened for maintenance, the user must call the Close Method before performing recognition.

The Modified Property can be used to learn whether there has been any change since the User dictionary was last opened for maintenance.

Changes can be made permanent by calling the Save Method.

This topic provides information about how to...

Create a New User Dictionary and Add UDitems to It

A new User dictionary can be created by calling the Create Method followed by the Save Method as follows:

C#
Copy Code
string userdict = "NEW_USER.DCT";
string sectA = "Section_A";
string item1 = "Peabody";
string item2 = "Budapest";
ImGearRecUserDictionary igRecUserDictionary = igRecognition.Recognition.UserDictionary;
igRecUserDictionary.Create();
igRecUserDictionary.AddItem(new ImGearRecUDItem(sectA, item1));
igRecUserDictionary.AddItem(new ImGearRecUDItem(sectA, item2));
igRecUserDictionary.Save(userdict);
igRecUserDictionary.Close();
VB.NET
Copy Code
Dim userdict As String = "NEW_USER.DCT"
Dim sectA As String = "Section_A"
Dim item1 As String = "Peabody"
Dim item2 As String = "Budapest"
Dim igRecUserDictionary As ImGearRecUserDictionary = igRecognition.Recognition.UserDictionary
igRecUserDictionary.Create()
igRecUserDictionary.AddItem(New ImGearRecUDItem(sectA, item1))
igRecUserDictionary.AddItem(New ImGearRecUDItem(sectA, item2))
igRecUserDictionary.Save(userdict)
igRecUserDictionary.Close()

A list of sections in the currently opened User dictionary can be retrieved with the GetSections Method.

A list of UDitems (the elements or entries) of the currently opened User dictionary can be retrieved with the GetItems Method. This method returns a list of the UDitems belonging to the specified section of the User dictionary with their attribute(s). The ImGearRecUDItem.IsRegExp Property denotes whether or not the item is a regular expression.

Elements can be added to the User dictionary with the AddItem Method. When adding a new UDitem with a non-existing section specified, the section will be automatically created. Existing UDitems can be deleted from the User dictionary with the DeleteItem Method. Sections are automatically removed as soon as their last UD item is deleted.

Maintain an Existing User Dictionary

C#
Copy Code
string userdict = "NEW_USER.DCT";
string sectA = "Section_A";
string sectB = "Section_B";
string item1 = "Peabody";
string item2 = "Peabody";
string item3 = "Budapest";
ImGearRecUserDictionary igRecUserDictionary = igRecognition.Recognition.UserDictionary;
igRecUserDictionary.Load(userdict, sectB);
igRecUserDictionary.AddItem(new ImGearRecUDItem(sectB, item1));
igRecUserDictionary.AddItem(new ImGearRecUDItem(sectB, item3));
igRecUserDictionary.DeleteItem(new ImGearRecUDItem(sectA, item2));
if (igRecUserDictionary.Modified)
      igRecUserDictionary.Save(userdict);
igRecUserDictionary.Close();
VB.NET
Copy Code
Dim userdict As String = "NEW_USER.DCT"
Dim sectA As String = "Section_A"
Dim sectB As String = "Section_B"
Dim item1 As String = "Peabody"
Dim item2 As String = "Peabody"
Dim item3 As String = "Budapest"
Dim igRecUserDictionary As ImGearRecUserDictionary = igRecognition.Recognition.UserDictionary
igRecUserDictionary.Load(userdict, sectB)
igRecUserDictionary.AddItem(New ImGearRecUDItem(sectB, item1))
igRecUserDictionary.AddItem(New ImGearRecUDItem(sectB, item3))
igRecUserDictionary.DeleteItem(New ImGearRecUDItem(sectA, item2))
If igRecUserDictionary.Modified Then
      igRecUserDictionary.Save(userdict)
End If
igRecUserDictionary.Close()
A User Dictionary that has been opened with Load Method or created with Create Method must be closed with Close Method before calling any method that performs recognition (e.g., Recognize Method).