Skip to main content
An ABBYY FlexiCapture classifier processes submitted documents and determines their class. This lets you choose a document definition to use for field extraction. Each classifier corresponds to a specific classification training batch. To use several classifiers for a single batch, set up a classification script. This is useful when some documents need additional classification: the first classifier assigns each document a class, and then the script selects an additional classifier based on the result. For example, documents can be first classified into “invoices” and “contracts”, and then the invoices can be further classified by company name.
This script can only be set up for an existing classification training batch. You cannot set it up when creating a new batch.

Set up a classification script

1

Open the project properties

Click Project → Project Properties.
2

Open the Recognition tab

In the project properties window, go to the Recognition tab.
3

Open the classification script editor

In the Classification section, click Set to the right of Use script.
4

Add a classifier

In the dialog box, click Add and choose a classification batch from the list.
5

Set an alias name

Optionally, change the classifier’s Alias Name. The script refers to the name in the Alias Name column, so you do not have to rewrite the script if a classifier’s name changes during processing.
6

Open the script editor

Click Edit Script to open the Script editor window.

Parameters

NameTypeAccessDescription
BatchTypeClassifierIBatchTypeClassifierRead-onlyA classifier in the batch type.
IsConfidentboolRead-onlyClassification confidence. Unlike automatic classifiers, when you use the script this parameter must be specified manually in page properties. See the following example.
PageIPageRead/writeDocument page.
ProcessingIProcessingCallbackRead/writeThe object for logging information about processing.
The following example specifies IsConfident in page properties:
IClassificationResult result = Classifiers[0].ClassifyPage( Page );
Page.ResultClassName = result.ClassName;
Page.IsResultClassConfident = result.IsConfident;

Classify a page and set the class name

This script classifies pages and adds the name of a class to their properties:
IBatchTypeClassifierResult classifierResult = BatchTypeClassifier.ClassifyPage( Page, null );
Page.ResultClassName = classifierResult.ClassName;

Get classification confidence

This script gets classification confidence levels:
IClassificationResult result = Classifiers[0].ClassifyPage( Page );
FCTools.ShowMessage( "Class: " + result.ClassName );
Page.ResultClassName = result.ClassName;
FCTools.ShowMessage( "IsConfident: " + result.IsConfident );
Page.IsResultClassConfident = result.IsConfident;

Combine multiple classifiers for cascade classification

var res0 = Classifiers.Get ( "Batch" ).ClassifyPage( Page );
IClassConfidences classVars = res0.Classes;
foreach( IClassConfidence c in classVars )
{
    FCTools.ShowMessage( c.Name + " --> " + c.Confidence.ToString() );
}
FCTools.ShowMessage( "Class res0: " + res0.ClassName);
if (res0.ClassName == "Invoice")
{
    var res1 = Classifiers.Get ( "Batch2" ).ClassifyPage( Page );
    IClassConfidences classVars1 = res1.Classes;
    foreach( IClassConfidence d in classVars1 )
    {
        FCTools.ShowMessage( d.Name + " --> " + d.Confidence.ToString() );
    }
    FCTools.ShowMessage( "Class res1: " + res1.ClassName);
    Page.ResultClassName = res1.ClassName;
}
else
{
    Page.ResultClassName = res0.ClassName;
}
FCTools.ShowMessage( "Page.ResultClassName: " +Page.ResultClassName);

Assign the Unknown class to low-confidence documents

Use this script if your scenario does not require documents with a low confidence level to be assigned a class, even if a class has already been specified for them. An operator should classify such documents manually.
For the script to work, create a new class beforehand — for example, “Unknown” — and link it to the document definition in the Class Mapping dialog. For more information, see Mapping classes to Document Definition sections.
using System;

IClassificationResult result = Classifiers.Get ( "ClassifierBatch" ).ClassifyPage(Page);
Page.ResultClassName = result.ClassName;
IClassConfidences classVars = result.Classes;
Page.Comment = "";

foreach( IClassConfidence c in classVars )
{
    //FCTools.ShowMessage( c.Name + " -- " + c.Confidence.ToString() ); // records the classification confidence value in the event log
    Page.Comment = Page.Comment + c.Name + "-" + c.Confidence.ToString() + "; "; // records the classification confidence value in the page comments
}

if (classVars.Count>0)
{
    if (classVars[0].Confidence<80) Page.IsResultClassConfident=false; // confidence threshold below which a document will be classified as uncertainly classified
    else Page.IsResultClassConfident=true;

    if (classVars[0].Confidence<20) Page.ResultClassName="Unknown"; // confidence threshold below which a document will be assigned the "Unknown" class
    if (classVars.Count>1) {
        int classesToShow = Math.Min(classVars.Count, 3);
        for(int i=0; i<classesToShow; i++)
        {
            Page.Comment = Page.Comment + classVars[i].Name + "-" + classVars[i].Confidence.ToString() + "; ";
        }
    }
}

FCTools.ShowMessage( "Class: " + Page.ResultClassName );
The confidence threshold values in this script are for demonstration purposes only. Modify them depending on your workflow.