Custom Language - Code Sample (Linux)

FineReader Engine
11, 12
Code Samples Collection
image: fre12_icon_userlanguages.gif

The sample code shows how to work with recognition languages. It creates a new recognition language and changes its dictionary to a manually-created sample dictionary. After the recognition, it calculates the number of words in the text and how many of them were found in the user dictionary.


The procedure of creating a new recognition language and calculating recognition statistics uses the language-related and text-related objects and methods of ABBYY FineReader Engine. Do the following:

  1. Create the Engine object using the InitializeEngine function or GetEngineObject function (version 11).
  2. [optional] Load a predefined profile for your scenario using the LoadPredefinedProfile method of the Engine object.
  3. Call the CreateFRDocument method of the Engine object to create the FRDocument object.
  4. Add pages from an image file to the document. Use the AddImageFile method of the FRDocument object.
  5. Create a new dictionary:
    1. Create the LanguageDatabase object using the CreateLanguageDatabase method of the Engine object.
    2. Create a new empty user dictionary file and the Dictionary object using the CreateNewDictionary method of the LanguageDatabase object.
    3. Specify the dictionary name, use the Name property of the Dictionary object.
    4. To add words to the dictionary, use the AddWord method of the Dictionary object.
  6. Create a new recognition language:
    1. Create a new TextLanguage object with the help of the CreateTextLanguage method of the LanguageDatabase object.
    2. Copy all attributes from the predefined language (“English”). Use the CopyFrom method of the TextLanguage object.
    3. Specify the language name (the InternalName property of the TextLanguage object).
  7. Bind the new dictionary to the BaseLanguage object within the new recognition language:
    1. Select the first BaseLanguage object within the TextLanguage object corresponding to the new language. Use the BaseLanguages property of the TextLanguage object and the Item method of the BaseLanguages object.
    2. Change internal name of the base language to user-defined (the InternalName property of the BaseLanguage object).
    3. Get a collection of dictionary descriptions for the BaseLanguage object corresponding to the new base language and remove all items from this collection. Use the DeleteAll method of the DictionaryDescriptions object.
    4. Add an empty user dictionary description (the AddNew method of the DictionaryDescriptions object) to the collection of dictionary descriptions.
    5. Get the new dictionary description (the GetAsUserDictionaryDescription method of the DictionaryDescription object) as a new UserDictionaryDescription object and specify the path to the dictionary file (the FileName property of the UserDictionaryDescription object).
  8. Create the DocumentProcessingParams object (the CreateDocumentProcessingParams method of the Engine object) and set the recognition language to the new one. Use the RecognizerParams property of the PageProcessingParams subobject and the TextLanguage property of the RecognizerParams object.
  9. Call the Process method of the FRDocument object with the created DocumentProcessingParams object as the first parameter.
  10. Calculate word recognition statistics:
    1. For each word in the text check whether the word was found in the dictionary. Use the IsWordFromDictionary property of the Word object.
    2. To calculate the total number of the words in the text sum up the number of the words in each paragraph. Use the Count property of the Words object corresponding to the collection of the words in the paragraph.
  11. [optional] Display the recognition statistics.
  12. Close the FRDocument object using the Close method.
  13. Unload FineReader Engine — use the DeinitializeEngine function.

Back To:

This website uses cookies which enable you to see pages or use other functions of our websites. You can turn off such cookies in your browser’s settings. If you continue to use these pages, you consent to the use of cookies.
  • No tags, yet