Skip to main content
Kofax

Is it possible to preserve certain Form Types set by Capture while using Trainable Document Separation (TDS) in KTM Server?

15051

QAID # 15051 Published 

Question / Problem:

Is it possible to preserve certain Form Types set by Capture while using Trainable Document Separation (TDS) in KTM Server?

Answer / Solution:

Using TDS will ignore existing Document structure and create new Documents, which also clears XValues such as AC_FORMTYPE. This means that there would be no way to retain the previously set Form Type for classification.

The way to get this information to persist through TDS is to provide 100% confident page-level results in the Document_BeforeTDS event telling it to use the class determined by the Form Type.

The code example below will do this for any Document which has a Form Type, although it may be desirable to add addtional logic or only use specific Form Types:

' Project Script
Private Sub Document_BeforeTDS(ByVal pXDoc As CASCADELib.CscXDocument, ByRef bSkip As Boolean)
    Dim oClsResult As CscResult
    Dim crtType As CscResultType
    Dim lPage As Long
    Dim aFormType As Variant
    Dim sFormType As String
    Dim sClass As String
    sFormType = pXDoc.XValues.ItemByName("AC_FORMTYPE").Value
    'If there is a form type assigned, then...
    If sFormType <> "" Then
        'Split the form type XValue FT_Class into FT and Class and assign class to string variable
        aFormType = Split(sFormType, "_")
        sClass = aFormType(1)
        'Loop through pages
        For lPage = 0 To pXDoc.CDoc.Pages.Count - 1
            If lPage = 0 Then
                crtType = CscResultTypeFirstPage
        End If
        If lPage <> 0 And lPage <> pXDoc.CDoc.Pages.Count - 1 Then
            crtType = CscResultTypeMiddlePage
        End If
        If lPage <> 0 And lPage = pXDoc.CDoc.Pages.Count - 1 Then
            crtType = CscResultTypeLastPage
        End If
        'Get result object for this page.
        Set oClsResult = GetClassificationResult(pXDoc, lPage)
        'Set the page classification result, with 100% confidence
        oClsResult.SetPageLevelConfidence Project.ClassByName(sClass).ClassID, crtType, 1.00
    Next 'page
    End If
End Sub
'Return the relevant results collection for this page.
Private Function GetClassificationResult(pXDoc As CscXDocument, lPage As Long) As CscResult
    If pXDoc.Representations.Count = 0 Then
        'There is no OCR for this document; we can only use the layout result collection.
        Set GetClassificationResult = pXDoc.CDoc.Pages(lPage).ClassificationResult
    Else
        'OCR exists for this document, prefer content classification over layout classification.
        If pXDoc.Pages(lPage).ClassificationResult Is Nothing Then
            Set GetClassificationResult = pXDoc.CDoc.Pages(lPage).ClassificationResult
        Else
            Set GetClassificationResult = pXDoc.Pages(lPage).ClassificationResult
        End If
    End If
End Function

Applies to: 

Product Version Category
AXPRO 4.5 Server
AXPRO 5.0 Server