Skip to content

Tell Form Revisions Apart

A county permit office receives one application form in two revisions. The 2024 revision moved several fields, so each revision needs its own subclass with its own zones. The two revisions look alike, and only the revision line in the footer, "Form PRM-210 (Rev. 03/2024)", tells them apart. A Regex Anchor on that line picks the right subclass with no script, and an OCR action writes the revision to an Index field.

At a glance

  • Extension point Regex Anchor refiner and OCR action (no code). A Custom Condition variation for many revisions.
  • You need Class "Permit Application"; subclasses "PRM-210 Rev 2019" and "PRM-210 Rev 2024", each with a model document; Index field Form Revision; permission Use This App in the Intuitive AI app
  • Teaches One exact string as a subclass vote, a capture group that places the zone, and a rule that writes the matched text

Set it up

  1. In the Intuitive AI app, open subclass "PRM-210 Rev 2024". Use Show OCR Data on the model page and copy the exact text of the revision line.
  2. In First Page Refiners, select Add Refiner: › Regex Anchor.
  3. Draw the zone tight around the revision date ("03/2024") on the model page.
  4. In RegEx:, enter the 2024 pattern below. In the flag menu, keep only i.
  5. Select Add a Rule. Add the same Regex Anchor with Add Condition: (same zone, same pattern).
  6. In that rule, select Add Action: › OCR ("Extract from OCR Snippet"). Use the same zone. Set Property: to Form Revision and RegEx: to [0-9]{2}\s*/\s*[0-9]{4}.
  7. Save the subclass. Repeat steps 1 to 7 in subclass "PRM-210 Rev 2019" with the 2019 pattern.

The patterns

PRM-210 Rev 2024: RegEx
Form\s+PRM[-\s]?210\s*\(?\s*Rev[.,]?\s*([0-9]{2}\s*/\s*2024)
PRM-210 Rev 2019: RegEx
Form\s+PRM[-\s]?210\s*\(?\s*Rev[.,]?\s*([0-9]{2}\s*/\s*2019)

How it works

  • The anchor searches the OCR text of the whole page. On a 2019 form, the 2024 pattern finds no match and returns 0.
  • Page refiners on one page combine with And, so a 0 from the anchor makes that subclass's page score 0. The 2019 subclass scores between 0.5 and 1 (0.5 plus half the OCR confidence of the match) and wins.
  • The capture group ( ... ) holds the date. The engine aligns the zone with the first captured group, so the zone lands on "03/2024" even when the scan is shifted.
  • [-\s]?, \(? and Rev[.,]? absorb common OCR variations: a lost hyphen, a lost parenthesis, a comma read for a period.
  • In the rule, the anchor condition passes only on a page that carries the revision line. The OCR action then moves its zone to follow the anchor and keeps only the date, so Form Revision gets "03/2024".

Test it

  1. Open the class and select Test. Upload five forms of each revision, including a skewed scan and a faint copy.
  2. Select Start Test.
  3. For each document, check Matched Subclass. In Detailed Test Results, read the Condition Confidence of each anchor, and the Form Revision value in Extraction Results.

You should see

every 2024 form matched to "PRM-210 Rev 2024" with an anchor confidence above 0.5, the 2024 anchor at 0 on every 2019 form, and Form Revision set to the printed date.

What can go wrong

Watch out

  • Both subclasses score 0. The footer was cut off by the scanner, or OCR misread the line. Check Show OCR Data on a failed document and widen the pattern, for example 20[0-9O]{2} if OCR reads a zero as the letter O.
  • The wrong page anchors. A pattern without the form number can match a "Rev." line in an attached document. Keep Form\s+PRM[-\s]?210 in the pattern.
  • Form Revision holds extra text. The OCR zone is wider than the date. Draw it tighter, or keep the RegEx: on the OCR action.
  • Form Revision is empty but the subclass matched. The rule has no anchor condition with a confidence above 0.5 on that page, or the OCR RegEx: found no date. The zone text then goes to the Assist bucket instead of the field.
  • A timeout error. Avoid open-ended patterns such as .*Rev.*. The pattern has 5 seconds per page.

Variation: many revisions, one script

With five or more revisions, one Custom Condition can serve every subclass. Name each subclass so that it ends with the revision year ("PRM-210 Rev 2024"), and paste the same script into First Page Refiners › Add Refiner: › Custom Condition of each subclass.

Condition_FormRevision.js
(function () {
    // Where: each "PRM-210 Rev YYYY" subclass > First Page Refiners > Custom Condition.
    // Returns 0.95 when the printed revision year matches the subclass name, else 0.
    if (!state.KnownSubclass) {
        return; // Class-level refiner: no opinion.
    }

    var wanted = /Rev\s+([0-9]{4})\s*$/i.exec(String(state.KnownSubclass.Name));
    if (!wanted) {
        result.SetResult(0); // The subclass name does not end with "Rev YYYY".
        return;
    }

    var ocr = services.OcrService.GetPageOcr(state);
    var text = (ocr && ocr.Text) ? String(ocr.Text).replace(/\s+/g, " ") : "";
    if (text.length === 0) {
        return; // No readable text: no opinion.
    }

    var printed = /\bForm\s+PRM[-\s]?210\s*\(?\s*Rev[.,]?\s*[0-9]{2}\s*\/\s*([0-9]{4})\b/i.exec(text);
    if (!printed) {
        result.SetResult(0); // Not this form, or the revision line is unreadable.
        return;
    }

    result.SetResult(printed[1] === wanted[1] ? 0.95 : 0);
})();

A new revision then needs a new subclass with its zones, and no script change.