ImageGear for C and C++ on Windows v19.1 - 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 specifies a User dictionary file with the IG_REC_UD_set() function, followed by a call to the IG_REC_UD_edit_open() function. At this point the content of the User dictionary can be listed, and items can be added or removed on request until IG_REC_UD_edit_close() is called.

The IG_REC_UD_state_get() function 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 IG_REC_UD_save() function.

A new User dictionary can be created by calling the IG_REC_UD_set() function with a NULL parameter, followed by a IG_REC_UD_save() call as follows.

This section provides information about how to...

Create a New User Dictionary and Add UDitems

C
Copy Code
AT_ERRCOUNT nErrCount;
LPSTR userdict = "NEW_USER.DICT";
LPSTR sectA = "Section_A";
LPCWSTR item1 = L"Peabody";
LPCWSTR item2 = L"Budapest";
nErrCount = IG_REC_UD_set(NULL, NULL);
nErrCount = IG_REC_UD_edit_open();
nErrCount = IG_REC_UD_item_add(sectA, item1, 0);
nErrCount = IG_REC_UD_item_add(sectA, item2, 0);
nErrCount = IG_REC_UD_save(userdict);
nErrCount = IG_REC_UD_edit_close();

Sections in the currently opened User dictionary can be enumerated with the IG_REC_UD_section_first_get(), IG_REC_UD_section_next_get() function-pair.

UDitems (the elements or entries) of the currently opened User dictionary can be enumerated with the IG_REC_UD_item_first_get(), IG_REC_UD_item_next_get() function-pair. These functions list the UDitems belonging to the specified section of the User dictionary with their attribute(s). The attribute equal to 1 denotes that the item is a regular expression.

Elements can be added to the User dictionary with the IG_REC_UD_item_add() function. 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 IG_REC_UD_item_delete() function. Sections are automatically removed as soon as their last UD item is deleted.

Maintain an Existing User Dictionary

C
Copy Code
AT_ERRCOUNT nErrCount;
AT_BOOL bChanged;
LPSTR userdict = "NEW_USER.DICT";
LPSTR sectA = "Section_A";
LPSTR sectB = "Section_B";
LPCWSTR item1 = L"Peabody";
LPCWSTR item2 = L"Peabody";
LPCWSTR item3 = L"Budapest";
nErrCount = IG_REC_UD_set(userdict, sectB);
nErrCount = IG_REC_UD_edit_open();
nErrCount = IG_REC_UD_item_add(sectB, item1, 0);
nErrCount = IG_REC_UD_item_add(sectB, item3, 0);
nErrCount = IG_REC_UD_item_delete(sectA, item2, 0);
nErrCount = IG_REC_UD_state_get(&bChanged);
if (bChanged == TRUE)
    nErrCount = IG_REC_UD_save("USER2.DICT");
nErrCount = IG_REC_UD_edit_close();
A User Dictionary that has been opened with IG_REC_UD_edit_open() must be closed with IG_REC_UD_edit_close() before calling any function that performs recognition (e.g., IG_REC_image_recognize() ).