我正在尝试创建一个自定义字典以用于 C# 的 Abby FineReader SDK,但我没有成功。
是否有人知道如何在 FineReader 中创建和使用自定义词典?
我正在尝试创建一个自定义字典以用于 C# 的 Abby FineReader SDK,但我没有成功。
是否有人知道如何在 FineReader 中创建和使用自定义词典?
DocumentProcessingParams dpParams = engine.CreateDocumentProcessingParams();
dpParams.PageProcessingParams.RecognizerParams.TextLanguage = makeTextLanguage("DICTIONARY PATH");
private TextLanguage makeTextLanguage(string dictionaryPath)
{
// Create new TextLanguage object
LanguageDatabase languageDatabase = engine.CreateLanguageDatabase();
TextLanguage textLanguage = languageDatabase.CreateTextLanguage();
var textlanguageName = Path.GetFileName(new FileInfo(textBox_dictionary.Text).Name);
// Copy all attributes from predefined English language
TextLanguage tempL = engine.PredefinedLanguages.Find("PortugueseBrazilian")
.TextLanguage;
textLanguage.CopyFrom(tempL);
textLanguage.InternalName = textlanguageName;
// Bind new dictionary to first (and single) BaseLanguage object within TextLanguage
BaseLanguage baseLanguage = textLanguage.BaseLanguages[0];
// Change internal dictionary name to user-defined
baseLanguage.InternalName = textlanguageName;
//set custom doctionary for base language
setDictionary(baseLanguage, dictionaryPath);
return textLanguage;
}
//set custom dictinary for base language
private void setDictionary(BaseLanguage baseLanguage, string dictionaryPath)
{
//create dictionary file
// Get collection of dictionary descriptions and remove all items
DictionaryDescriptions dictionaryDescriptions = baseLanguage.DictionaryDescriptions;
//dictionaryDescriptions.DeleteAll();
// Create user dictionary description and add it to the collection
IDictionaryDescription dictionaryDescription = dictionaryDescriptions.AddNew(DictionaryTypeEnum.DT_UserDictionary);
UserDictionaryDescription userDictionaryDescription = dictionaryDescription.GetAsUserDictionaryDescription();
userDictionaryDescription.FileName = dictionaryPath;
}