The StructuredStrings.fsp sample project
The sample projectStructuredStrings.fsp shows how to search for a single-line Invoice number field that has a similar format on all pages (folder %public%\ABBYY\FlexiCapture\12.0\Samples\FLS\Tips and Tricks\Structured strings).
The project has four pages:
- Pages 1 and 2 – The Invoice number field is printed at good quality.
- Page 3 – The Invoice number field is printed, but the image is noisy.
- Page 4 – The image quality is good, but the Invoice number field is filled in by hand.
Describe the invoice number with a regular expression
The search for the Invoice number field relies on the field name. First, you need an element that describes the search constraints of the field name. In the project, this is a Static Text element named InvoiceNumberHeader with the valueInvoiceN:.
The Invoice number field is a single-line field. To detect it, the project uses a Character String element named NumAsRegularExpression. As the project pages show, the format of the Invoice number field can be described with the following regular expression:
10&0-20-A/04.
On page 4, the invoice number is filled in by hand. The pre-recognition result (Z.OOO-41-C/03) does not match the described format either.
Add a fallback Character String element with an alphabet
The recommended solution is as follows. Create one more Character String element and name it NumAsAlphabet. Specify for it the same search constraints as for the NumAsRegularExpression element. Then group the two elements into one Group element, InvoiceNumber. However, describe the NumAsAlphabet element not as a regular expression but as a list of all valid characters.
When specifying search constraints for the NumAsAlphabet element, you can use drag-and-drop to copy the settings from the Relations section of the NumAsRegularExpression element into the same section of the current element. Alternatively, the following code can be written in the Advanced pre-search relations field:
SearchElements.InvoiceNumber is specified as its Source element. At this stage, the FlexiLayout for detecting Invoice number fields is complete.
If, for some reason, the method described earlier is not sufficient for detecting the data field (whether its format is known or unknown), one more element (of type Object Collection) can be created in the group. In this project, it is an Object Collection element named NumAsObjectCollection.It is not actually needed given the good quality of the images in this project and is only shown as an example (the Disable command is specified for it).An additional Object Collection element might be needed when it is difficult to predict pre-recognition results on different pages, but the search area can be accurately described, preventing unwanted information from getting into the hypotheses.
Why the regular expression improves reliability
The following question may arise: why is a regular expression needed if the field can sometimes be detected without it? The answer is that the use of a regular expression makes the search more reliable. If this element is found, then you can be sure that you have found the very line that you need. This information can then be safely used to detect further elements and their relations. When the search constraints are lax, you cannot be absolutely sure that you have found exactly what you need. This may happen if the image is very noisy. In such cases, using a Character String element with a specified alphabet can lead to an excessive percentage of errors (the Percentage of non-alphabet characters parameter). As a result, the element will either not be detected at all or be detected only partially. The following figure shows an example of such a situation.




