Skip to main content

Is it possible to populate a document field with classification confidence in KTA?

Using XValues, classification confidence can be saved during the Classification activity, and then retrieved and set to a field during the Extraction activity.

Question / Problem: 

Is it possible to populate a document field with classification confidence in KTA?

Answer / Solution: 

You can set the confidence value to a field in your transformation project.  There are some non-obvious but solvable obstacles:

1.       pXDoc.ClassificationResult is only populated during the classification phase, so the value must be retrieved in the Classification Group, not the Extraction Group.

2.       Fields don’t exist in the Classification Group, so the value must be saved as an XValue.  Then the Extraction Group can copy the XValue to the field.


First add script to the project level of the Classification Group to save confidence to an XValue:

Private Sub Document_AfterClassifyXDoc(ByVal pXDoc As CASCADELib.CscXDocument)
End Sub

Public Sub SaveClassificationConfidenceToXValue(pXDoc As CscXDocument)
   If Not pXDoc.ClassificationResult Is Nothing Then
      ' ClassificationResult object will only exist during classification phase...
      Dim Conf As Single
      If pXDoc.ClassificationResult.NumberOfConfidences>0 Then
      End If

      ' ...And fields do not exist in the Classification Group project,
      ' so save confidence to an XValue that can be read during extraction
   End If
End Sub


Then in the Extraction Group, add a “ClassificationConfidence” field at the project level.  Finally in the Extraction Group, add project level script to populate the field from XValue:

Private Sub Document_AfterExtract(ByVal pXDoc As CASCADELib.CscXDocument)
End Sub

Public Sub SetClassificationConfidenceFieldFromXValue(pXDoc As CscXDocument)
   ' Get classificaiton confidence from XValue set in Classifiation Group
   If pXDoc.XValues.ItemExists("ClassificationConfidence") Then
   End If
End Sub

For more details on using XValues in this way, see:

Is it possible to save values from Classification or Extraction, other than document fields, for later use in a process?

Applies to:  

Product Version
KTA 7.0+


Author:  Stephen Klancher