How to use the user dictionary

Question

Sometimes the recognition of complicated and rare words might not be sufficient, for example, additional spaces might be inserted into the resulting word.

Answer

The recognition of complicated and rare words might be improved by adding these words to the user dictionary.

Please refer to the following code snippet for setting up a user dictionary:

        //Create document processing parameters
CSafePtr<IDocumentProcessingParams> DocumentProcessingParams;
CheckResult(FREngine->CreateDocumentProcessingParams(&DocumentProcessingParams));

CSafePtr<IPageProcessingParams> PageProcessingParams;
CheckResult(DocumentProcessingParams->get_PageProcessingParams(&PageProcessingParams));

CSafePtr<IRecognizerParams> RecognizerParams;
CheckResult(PageProcessingParams->get_RecognizerParams(&RecognizerParams));

CSafePtr<ILanguageDatabase> LanguageDatabase;
CheckResult(FREngine->CreateLanguageDatabase(&LanguageDatabase));

CSafePtr<ITextLanguage> TextLanguage;
CheckResult(LanguageDatabase->CreateTextLanguage(&TextLanguage));
CheckResult(LanguageDatabase->CreateCompoundTextLanguage(L"English,ChineseTaiwan", &TextLanguage));

CSafePtr<IBaseLanguages> BaseLanguages;
CheckResult(TextLanguage->get_BaseLanguages(&BaseLanguages));

CSafePtr<IBaseLanguage> BaseLanguage;
//English base language
CheckResult(BaseLanguages->get_Element(1, &BaseLanguage));

//Create user dictionary file
CSafePtr<IDictionary> Dictionary;
CheckResult(LanguageDatabase->CreateNewDictionary(L"Dictionary.amd", LI_EnglishUnitedStates, &Dictionary));

CheckResult(Dictionary->put_Name(L"TestDictionary"));
CheckResult(Dictionary->AddWord(L"Hematocrit", 100));

CSafePtr<IDictionaryDescriptions> DictionaryDescriptions;
CheckResult(BaseLanguage->get_DictionaryDescriptions(&DictionaryDescriptions));

CSafePtr<IDictionaryDescription> DictionaryDescription;
CheckResult(DictionaryDescriptions->AddNew(DT_UserDictionary, &DictionaryDescription));

CSafePtr<IUserDictionaryDescription> UserDictionaryDescription;
CheckResult(DictionaryDescription->GetAsUserDictionaryDescription(&UserDictionaryDescription));

//Load user dictionary file
CheckResult(UserDictionaryDescription->put_FileName(L"Dictionary.amd"));

CheckResult(RecognizerParams->put_TextLanguage(TextLanguage));

///////////// 

WriteLineToLog(L"Processing...");
CheckResult(frDocument->Process(DocumentProcessingParams));

C++ code snippet

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.