English (English)

Sample 4. Step 5.4: Invoice Number field, InvoiceNumber element

On some of the documents, the Invoice Number field is located to the right of the field name whereas on other documents it is located below the name (in documents 1 and 2 the field data are placed directly beneath the name).

To create an InvoiceNumber element:

  1. In the InvoiceHeader element, create an element of type Character String and name it InvoiceNumber.
    Note.The name of the element need not be the same as the name of the block corresponding to the InvoiceNumber field. However, having identical names is convenient when working with a FlexiLayout.
  2. Click the Character String tab.
  3. Specify the alphabet:
    -./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  4. Set Percentage of non-alphabet characters to 30%.
  5. In the Character count field, specify the fuzzy interval {-1, 3, 20, INF} for the length of the character string, assuming that possible values fall into the region of 3 to 20 characters. Any hypothesis outside this interval will be penalized.
  6. On some of the images, the search area for the Invoice Number field contains the already detected kwInvoiceDate element. Exclude this element from the search area, so that the program does not include this text in its hypotheses for the Invoice Number field:
    • On the Search Constraints tab, click the Add... button next to the Exclude regions of elements field.
    • Select kwInvoiceDate from the list of elements.
    • Click OK. The string SearchElements.InvoiceHeader.kwInvoiceDate will appear in theExclude regions of elements field.

      Show me...

  1. Click the Advanced tab.
  2. In Advanced pre-search relations, specify additional conditions: if the name kwInvoiceNumber is not found, do not search for the InvoiceNumber field, otherwise specify the search area as an array of rectangles: one rectangle to the right of the name and another rectangle below the name with a small offset. In the FlexiLayout language, this condition can be written as follows:
    if kwInvoiceNumber.IsNull then Dontfind();
    else
    { WholeWordMOde: true;
    MaxGapInLine: 30dt;
    RectArray DataRegion;
    Let r1= Rect (kwInvoiceNumber.Rect.Right, kwInvoiceNumber.Rect.Top -20dt, kwInvoiceNumber.Rect.Right + 650dt, kwInvoiceNumber.Rect.Bottom + 50dt);
    // Limits the search area by a rectangle to the right of the name of the InvoiceNumber field.
    Let r2 = Rect (kwInvoiceNumber.Rect.Left - 100dt, kwInvoiceNumber.Rect.Bottom, kwInvoiceNumber.Rect.Right + 100dt, kwInvoiceNumber.Rect.Bottom + 100dt);
    // Limits the search area by a rectangle beneath the name of the InvoiceNumber field.
    DataRegion = RectArray (r1);
    DataRegion.Add (r2);
    RestrictSearchArea (DataRegion);
    }
  3. The search area for the field is limited to two rectangles, one to the right of the field name and one beneath it. If the field data are located to the right of the field name, there is often some other text beneath the field (on the test images, this is most commonly the name and data of the Date field). Since this extraneous text will be included into the search area for the Invoice Number field, the program will generate a hypothesis for this text. To influence the quality of this hypothesis, specify additional checks in the Advanced post-search relations field: the lower the text beneath the field name, the bigger the penalty. In the FlexiLayout language, this condition can be written as follows:
    if not IsNull then
    { FuzzyQuality: Top - kwInvoiceNumber.Rect.Top, {-30000,0,0,10000}*dt;
    }
    // The greater the distance between the name and upper boundary of the field, the bigger the penalty for the corresponding hypothesis. In this particular case, the hypothesis for the element whose upper boundary coincides with the upper boundary of the name will have the highest quality.
  4. Temporarily exclude the InvoiceFooter element and match the FlexiLayout.
  5. Specify the location of the InvoiceNumber block as a rectangular region of the InvoiceNumber element enlarged by 5 dots vertically and horizontally. To do this, select Expression and type the following expression:
    Rect outputRect;
    outputRect = InvoiceHeader.InvoiceNumber.Rect;
    IsNull = InvoiceHeader.InvoiceNumber.IsNull;
    // Treats the block region as detected if the InvoiceNumber element has been detected.
    OutputRegion = outputRect;
    OutputRegion.Inflate (5dt, 5dt);

12.04.2024 18:16:02

Please leave your feedback about this article

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.