Community

How "manually match" a document definition via script

From the Verification Station it is possible to select an "Unknown" document and manually match it to a document definition. Is it possible to do this via a document script (within an advanced workflow)? I've looked through the FlexiCapture 10 help (specifically the IDocument methods) and don't see anything that would accomplish this.
0

Comments

3 comments

  • Avatar
    Sushi
    Why not just create a generic FlexiLayout that will match to any document? Set it the last on the list and check match first FlexiLayout option. That way if it doesn't match any DocDef, in the list, it will match the last generic layout.
    0
  • Avatar
    Russell Kent
    The project cannot use the "accept first matching FlexiLayout" option because there are layouts which are very similar and the evaluation engine needs to select the layout which *best* matches, *not* the first layout which matches at all.
    0
  • Avatar
    Slowdima
    The task can be solved by "before matching" event handler, where it is possible to specify a list of document definition names ( or names of certain section ) available for matching on the document. In case of one member in the list you can also specify if it should be matched forcedly. Also, there is a scripting method IFlexiCaptureTools::ClassifyPage, which allows to understand which sections can be matched with a page without actual matching. All members of IFlexiCaptureTools are static, so methods of this interface can be called from any scripts. The point is that method ClassifyPage needs for full access to IPage object, which is not the case for “before matching” script, but is true for processing scripts for example. So, classification method can be used from “batch processing script” or “document processing script”. Execution results can be passed to the event handler with help of document registration parameter.

    For example, here is a real support case. Client had 5 document definitions. First 4 of them had 1 instance of single-page fixed section (for processing of fixed form ) and 1 instance of single-page flexi section. Last document definition had only an instance of flexi section. The point is that all 5 flexi sections had the same flexi layout inside. So, if a batch of documents would be recognized in a usual way, the man would have a lot of assembling errors since flexi section for unstructured pages would be chosen in unpredictable way. The only way to understand which flexi section should be chosen is to know which fixed section was matched on previous page.

    In the project we created a batch processing script stage and placed it just before recognition, when all documents are disassembled (so, each page is considered a document). Code of the script was the following ( C# ):

    //================
    IPageClassificationResult[] Results = new IPageClassificationResult[ Documents.Count ];
    string[] DocDefNames = new string[ Documents.Count ];
    bool[] IsFixedFormPage = new bool[ Documents.Count ];

    for ( int i = 0; i < documents.count;="" i++="" )="">
    Results[ i ] = FCTools.ClassifyPage( Documents[ i ].Pages[ 0 ], System.Type.Missing, false );

    string sSuitableSections = Results[ i ].MatchedSections;
    DocDefNames[ i ] = sSuitableSections.Substring( 0, sSuitableSections.IndexOf( @"\" ) );
    IsFixedFormPage[ i ] = (int)Results[ i ].PageType == 2;

    }


    for ( int i = 0; i < documents.count;="" i++="" )="">
    string sCorrectSection;



    if ( IsFixedFormPage[ i ] ) {
    sCorrectSection = Results[ i ].MatchedSections;

    }
    else {
    if ( ( i == 0 ) || ( IsFixedFormPage[ i - 1] == false ) ) {
    sCorrectSection = @"Definizione documento5\Sezione documento 1";
    }
    else {
    sCorrectSection = DocDefNames[ i - 1 ] + @"\Sezione documento 1" ;
    }

    }

    Documents[ i ].Properties.Set( "CorrectSection", sCorrectSection );
    }
    //================

    And code of the handler was just

    //==============
    if ( Document.Properties.Has( "CorrectSection" ) ) {
    Matching.DefinitionsList = Document.Properties.Get( "CorrectSection" );
    }
    //==============

    This script just demonstrates the idea, this is not a kind of “best practice” etc.
    0

Please sign in to leave a comment.