// USE CASE: Configuring fields for better recognition results public static void Configuring_fields_for_better_recognition_results(IEngine engine) { trace("Create a Document Definition from a FlexiLayout..."); IDocumentDefinition newDefinition = engine.CreateDocumentDefinitionFromAFL(SamplesFolder + "\\SampleMisc\\Invoice_eng.afl", "English"); assert(newDefinition != null); trace("Configure data types..."); setFieldValueType(newDefinition, "InvoiceDate", FieldValueTypeEnum.FVT_DateTime); setFieldValueType(newDefinition, "Quantity", FieldValueTypeEnum.FVT_Number); setFieldValueType(newDefinition, "UnitPrice", FieldValueTypeEnum.FVT_Currency); setFieldValueType(newDefinition, "Total", FieldValueTypeEnum.FVT_Currency); setFieldValueType(newDefinition, "TotalAmount", FieldValueTypeEnum.FVT_Currency); trace("Configure recognition languages for text fields ..."); IFieldDefinition fieldDef = findFieldDef(newDefinition, "InvoiceNumber"); assert(fieldDef != null); ITextRecognitionParams textParams = fieldDef.RecognitionParams.AsTextParams(); ILanguage newLanguage = textParams.CreateEmbeddedLanguageByDataType(FieldValueTypeEnum.FVT_DateTime); textParams.Language = newLanguage; newLanguage = textParams.CreateEmbeddedLanguage(textParams.Language.Type, textParams.Language); assert(newLanguage != textParams.Language); assert(newLanguage.LanguageCategory == LanguageCategoryEnum.LC_DataType); assert(newLanguage.DatatypeCategory == DatatypeCategoryEnum.TC_DateTime); textParams.Language = newLanguage; newLanguage = textParams.CreateEmbeddedLanguage(LanguageTypeEnum.LT_Group, null); newLanguage.AsGroupLanguage().Add(engine.PredefinedLanguages.FindLanguage("English")); newLanguage.AsGroupLanguage().Add(engine.PredefinedLanguages.FindLanguage("Russian")); textParams.Language = newLanguage; assert(textParams.Language.Type == LanguageTypeEnum.LT_Group); assert(textParams.Language.AsGroupLanguage().Count == 2); assert(textParams.Language.AsGroupLanguage().Item(0).InternalName == "English"); assert(textParams.Language.AsGroupLanguage().Item(1).InternalName == "Russian"); newLanguage = textParams.CreateEmbeddedLanguage(LanguageTypeEnum.LT_Simple, null); newLanguage.AsSimpleLanguage().set_LetterSet(LanguageLetterSetEnum.LLS_Alphabet, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); newLanguage.AsSimpleLanguage().RegularExpression = "[A-Z]{1-}"; textParams.Language = newLanguage; assert(textParams.Language.AsSimpleLanguage().RegularExpression.Length > 0); newLanguage = textParams.CreateEmbeddedLanguage(LanguageTypeEnum.LT_Simple, engine.PredefinedLanguages.FindLanguage("English")); assert(newLanguage.AsSimpleLanguage().UsePredefinedDictionary == true); assert(newLanguage.AsSimpleLanguage().UseUserDefinedDictionary == false); assert(newLanguage.AsSimpleLanguage().UserDefinedDictionary == null); newLanguage.AsSimpleLanguage().UseUserDefinedDictionary = true; FCEngine.IDictionary dictionary = newLanguage.AsSimpleLanguage().UserDefinedDictionary; assert(dictionary != null); assert(dictionary.WordsCount == 0); dictionary.AddWord("ONE", 1); dictionary.AddWord("TWO", 1); dictionary.AddWord("THREE", 1); assert(dictionary.WordsCount == 3); IEnumDictionaryWords enumWords = dictionary.EnumWords(); for (int i = 0; i < 10; i++) { int confidence = 0; string word = enumWords.Next(out confidence); if (confidence == 0) { break; } trace(word); } textParams.Language = newLanguage; trace("Check the Document Definition..."); assert(newDefinition.Check() == true); traceBegin("Use the Document Definition in FlexiCaptureProcessor..."); IFlexiCaptureProcessor processor = engine.CreateFlexiCaptureProcessor(); processor.AddDocumentDefinition(newDefinition); // Add images for a single document processor.AddImageFile(SamplesFolder + "\\SampleImages\\Invoices_1.tif"); // Recognize the document IDocument document = processor.RecognizeNextDocument(); assert(document != null); assert(document.DocumentDefinition != null); assert(document.Pages.Count == 1); processor.ExportDocumentEx(document, SamplesFolder + "\\FCEExport", "Invoice", null); traceEnd("OK"); }