L_Doc2GetWordSuggestions

#include "ltdoc2.h"

L_LTDOC2_API L_INT EXT_FUNCTION L_Doc2GetWordSuggestions(hDoc, nPageIndex, nWordIndex, pppWordSuggestions, plSuggestionsCount)

L_HDOC2 hDoc;

/* handle to the OCR document */

L_INT nPageIndex;

/* page index */

L_INT nWordIndex;

/* word index */

L_WCHAR*** pppWordSuggestions;

/* address of a pointer to pointer of type L_WCHAR */

L_INT32 * plSuggestionsCount;

/* pointer to the number of word's suggestions */

Gets an array of all available alternatives/suggestions for the recognized words.

Parameter

Description

hDoc

Handle to the OCR document.

nPageIndex

A zero-based index of the recognized page for which to get the recognized words suggestions.

nWordIndex

A zero-based index of the word to get its recognized alternatives/suggestions.

pppWordSuggestions

Address of pointer to pointer that represents an array of strings to be allocated and updated with the available word's suggestions.

plSuggestionsCount

Pointer to a variable to be updated with the number of elements in the pppWordSuggestions array.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function obtains an array of recognized alternative words at the specified word index (if any are available).

This function obtains the number of alternative word's suggestions in plSuggestionsCount.

You must free the memory associated with pppWordSuggestions parameter when it is no longer needed, by calling the L_Doc2FreeWordSuggestions function.

This function should not be called before calling the L_Doc2GetRecognizedWords function.

Required DLLs and Libraries

LTDOC2

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

L_Doc2GetCharacterChoices, L_Doc2FreeCharacterChoices, L_Doc2FreeWordSuggestions, L_Doc2GetRecognizedCharacters, L_Doc2GetRecognizedWords

Topics:

OCR Functions: Recognition

 

Recognizing Document Pages

Example

L_LTDOC2TEX_API L_INT DocGetWordSuggestionsExample(L_HDOC2 hDoc)
{
   L_INT nRet;
   RECOGNIZEOPTS2 RecogOpts;
   RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS2);
   RecogOpts.nPageIndexStart = 0;
   RecogOpts.nPagesCount = 1;
   RecogOpts.SpellLangId = DOC2_LANG_ID_ENGLISH;
   nRet = L_Doc2Recognize (hDoc, &RecogOpts, NULL, NULL);
   if (nRet == SUCCESS)
   {
      pRECOGWORDS2 pRecogWords = NULL;
      L_INT nWordsCount = 0;
      nRet = L_Doc2GetRecognizedWords(hDoc, 0, &pRecogWords, sizeof(RECOGWORDS2), &nWordsCount);
	  if (nRet == SUCCESS)
      {
         for (L_INT32 i=0; i<nWordsCount; i++)
         {
            L_WCHAR ** ppWordSuggestions = NULL;
            L_INT nSuggestionsCount = 0;
            nRet = L_Doc2GetWordSuggestions(hDoc, 0, i, &ppWordSuggestions, &nSuggestionsCount);
			if(nRet == SUCCESS && nSuggestionsCount > 0)
            {
               L_TCHAR szBuffer[1024];
               ZeroMemory(szBuffer, sizeof(szBuffer));
               wsprintf(szBuffer, TEXT("Word Index: %d\nWord: %s\nSuggestions Count: %d"), i, pRecogWords[i].szWord, nSuggestionsCount);
               MessageBox(NULL, szBuffer, TEXT("Word Suggestions Count"), MB_OK);
               L_Doc2FreeWordSuggestions(hDoc, &ppWordSuggestions, nSuggestionsCount);
            }
         }
		 nRet = L_Doc2FreeRecognizedWords(hDoc, &pRecogWords);
		 if(nRet != SUCCESS)
            return nRet;
      }
   }
   return SUCCESS;
}