Leadtools.Forms.Ocr Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
IOcrUserDictionary Interface
See Also  Members   Example
Leadtools.Forms.Ocr Namespace : IOcrUserDictionary Interface



The user dictionary settings currently used in the engine.

Syntax

Visual Basic (Declaration) 
Public Interface IOcrUserDictionary 
Visual Basic (Usage)Copy Code
Dim instance As IOcrUserDictionary
C# 
public interface IOcrUserDictionary 
C++/CLI 
public interface class IOcrUserDictionary 

Example

This example will create a user dictionary and add a few sections and items to it

Visual BasicCopy Code
Public Sub OcrUserDictionaryExample()
   ' Unlock the support needed for LEADTOOLS Plus OCR engine
   RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here")
   RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here")
   RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here")
   ' Create an instance of the engine
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
      ' Start the engine using default parameters
      ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)

      ' Get the user dictionary object used in the engine
      Dim userDictionary As IOcrUserDictionary = ocrEngine.SpellCheckManager.UserDictionary

      ' Create a new user dictionary
      Dim defaultSectionName As String = "Cities"
      userDictionary.Create(defaultSectionName)

      ' Add a few items to this user dictionary
      Dim cities() As String = {"Lagos, Amman"}
      For Each city As String In cities
         Dim item As IOcrUserDictionaryItem = userDictionary.CreateItem(city, OcrUserDictionaryItemStyles.None)
         userDictionary.AddItem(defaultSectionName, item)
      Next

      ' Save this user dictionary to disk
      Dim userDictionaryFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Cities.ud"
      userDictionary.Save(userDictionaryFileName)
      userDictionary.Close()

      ' Now re-open this user dictionary to show how we can iterate the items
      userDictionary.Open(userDictionaryFileName, defaultSectionName)

      ' Enumerate the sections
      Dim sectionName As String = userDictionary.GetFirstSectionName()
      Do While (Not sectionName Is Nothing)
         Console.WriteLine("Section: {0}", sectionName)

         ' Find the items of this section
         ' Note, the items returned maight be a group of the items you added
         Dim item As IOcrUserDictionaryItem = userDictionary.GetFirstItem(sectionName)
         Do While (Not item Is Nothing)
            Console.WriteLine(" Item: {0}", item.Value)
            item = userDictionary.GetNextItem()
         Loop

         sectionName = userDictionary.GetNextSectionName()
      Loop

      userDictionary.Close()

      ' Now set this user dictionary as the one to use in spell checking
      userDictionary.Use(userDictionaryFileName, defaultSectionName)

      ' Show the current user dictionary and section names
      Console.WriteLine("User dictionary in use:\nFileName: {0}\nDefaultSectionName: {1}", userDictionary.FileName, userDictionary.DefaultSectionName)

      ' Shutdown the engine
      ' Note: calling Dispose will also automatically shutdown the engine if it has been started
      ocrEngine.Shutdown()
   End Using
End Sub
C#Copy Code
public void OcrUserDictionaryExample() 

   // Unlock the support needed for LEADTOOLS Plus OCR engine 
   RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here"); 
   RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here"); 
   RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here"); 
   // Create an instance of the engine 
   using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) 
   { 
      // Start the engine using default parameters 
      ocrEngine.Startup(null, null, null, null); 
 
      // Get the user dictionary object used in the engine 
      IOcrUserDictionary userDictionary = ocrEngine.SpellCheckManager.UserDictionary; 
 
      // Create a new user dictionary 
      string defaultSectionName = "Cities"; 
      userDictionary.Create(defaultSectionName); 
 
      // Add a few items to this user dictionary 
      string[] cities = { "Lagos, Amman" }; 
      foreach(string city in cities) 
      { 
         IOcrUserDictionaryItem item = userDictionary.CreateItem(city, OcrUserDictionaryItemStyles.None); 
         userDictionary.AddItem(defaultSectionName, item); 
      } 
 
      // Save this user dictionary to disk 
      string userDictionaryFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Cities.ud"; 
      userDictionary.Save(userDictionaryFileName); 
      userDictionary.Close(); 
 
      // Now re-open this user dictionary to show how we can iterate the items 
      userDictionary.Open(userDictionaryFileName, defaultSectionName); 
 
      // Enumerate the sections 
      string sectionName = userDictionary.GetFirstSectionName(); 
      while(sectionName != null) 
      { 
         Console.WriteLine("Section: {0}", sectionName); 
 
         // Find the items of this section 
         // Note, the items returned maight be a group of the items you added 
         IOcrUserDictionaryItem item = userDictionary.GetFirstItem(sectionName); 
         while(item != null) 
         { 
            Console.WriteLine("  Item: {0}", item.Value); 
            item = userDictionary.GetNextItem(); 
         } 
 
         sectionName = userDictionary.GetNextSectionName(); 
      } 
 
      userDictionary.Close(); 
 
      // Now set this user dictionary as the one to use in spell checking 
      userDictionary.Use(userDictionaryFileName, defaultSectionName); 
 
      // Show the current user dictionary and section names 
      Console.WriteLine("User dictionary in use:\nFileName: {0}\nDefaultSectionName: {1}", userDictionary.FileName, userDictionary.DefaultSectionName); 
 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown(); 
   } 
}

Remarks

Important Note: User dictionaries are only supported in the Advantage OCR engine in this version of LEADTOOLS. Using the functionality of the IOcrUserDictionary interface in any other engine will have no effect on the recognition results.

You can get the instance of the IOcrUserDictionary interface currently used in the engine with the IOcrSpellCheckManager.UserDictionary property.

The functionality of the checking subsystem consists of three separate parts:

  1. Spell checking through the language dictionaries. You can enable and disable the spell languages used through in the system with the IOcrSpellCheckManager.SpellLanguage property.
  2. User dictionary checking. You can control the use of a user dictionary through the IOcrUserDictionary interface methods accessed by the IOcrSpellCheckManager.UserDictionary property.
  3. User-defined checking through the use of the global OcrSpellCheckCallback callback which can be set by the IOcrSpellCheckManager.SetSpellCheckCallback method.

A user dictionary typically consists of different sections, the sections may contain one or more specified items (IOcrUserDictionaryItem). You can enumerate the sections in the User dictionary with the GetFirstSectionName and GetNextSectionName methods.

Each zone can be linked to a section in the User dictionary using the OcrZone.UserDictionarySectionName property.

User dictionary items are strings and they must be no longer than MaximumItemLength characters. They may contain spaces and punctuation characters.

If there is no default section specified, in the methods that expects a DefaultSectionName parameter, the first section of the User dictionary will be the default.

You can set the current user dictionary to use in the checking subsystem with the Use method. If no user dictionary has been set, no checking through the user dictionary will be performed.

You can use the Create method to create a new user dictionary and the Open method to open for edit an existing dictionary. You can then iterate through the sections and items as well as adding new sections and items to the dictionary. When you are done, you must call Save to save any changes you made to the dictionary and finally Close to close it.

Note: The IOcrSpellCheckManager.SpellLanguage property is read only for the LEADTOOLS OCR Advantage Engine, setting this property will have no effect since the spell language will always be the same as the currently enabled language.

Note: User-defined checking through the OcrSpellCheckCallback callback is not supported when using the LEADTOOLS OCR Advantage Engine.

Note: User dictionary sections are not supported in the LEADTOOLS OCR Advantage Engine.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

IOcrUserDictionary requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features