Working with the Format Analysis Engine (SCBCdrFormatEngine)
This class provides methods and properties for the Format Analysis engine.
Sample code
The following sample code searches for a 1 to 10 digits long number in the workdoc by using the Simple Expression algorithm. If the word is found, the variable pValid is set to true.
Private Sub PoNo_Validate(pField as SCBCdrPROJLib.ISCBCdrField, pWorkdoc as SCBCdrPROJLib.ISCBCdrWorkdoc, pValid as Boolean)
Dim FormatEngine as SCBCdrFormatEngine
Dim oPOTemplate as SCBCdrFormatSettings
If FormatEngine Is Nothing Then Set FormatEngine = New SCBCdrFormatEngine
If oPOTemplate Is Nothing Then Set oPOTemplate = New SCBCdrFormatSettings
oPOTemplate.DeleteAll
oPOTemplate.AddFormat("#[1-10]")
oPOTemplate.MaxDistance = 0.1
oPOTemplate.MaxWordCount = 5
oPOTemplate.MaxWordGap = 4
oPOTemplate.MaxWordLen = 100
oPOTemplate.KeepSpaces = False
oPOTemplate.CaseSensitive = False
oPOTemplate.IgnoreCharacters(0) = ",.-/()[]"
oPOTemplate.CompareType(0) = CdrTypeSimpleExpression
Dim strFoundString as String
If FormatEngine.FindStringFirst(pWorkdoc, oPOTemplate, , strFoundString) Then
strFoundString = "Found"
pField.Text = strFoundString
pValid = True
Else
pValid = False
End If
End Sub
Sample Code
The following sample code writes the confidence of the test string "1234567890" against the Format String #[3-5], which is the index 3 of the field MyField, into the log file.
Private Sub MyField_PreExtract(pField as SCBCdrPROJLib.ISCBCdrField, pWorkdoc as SCBCdrPROJLib.ISCBCdrWorkdoc)
Dim DocClass as SCBCdrDocClass
Dim theAnalysisSettings as SCBCdrPROJLib.ISCBCdrAnalysisSettings
Dim theSettings as Object
Dim theFormatSettings as SCBCdrFormLib.SCBCdrFormatSettings
Dim AE as Object
Dim theFormatEngine as SCBCdrFormLib.SCBCdrFormatEngine
Dim TestStr as String
Dim fDist as Single
'Get current DocClass
Set DocClass=Project.AllClasses.ItemByName(pWorkdoc.DocClassName)
'Get the settings for the field 'MyField'
DocClass.GetFieldAnalysisSettings("MyField","German", theAnalysisSettings)
'Convert them to the SCBCdrFormatSettings
Set theSettings = theAnalysisSettings
Set theFormatSettings = theSettings
'Get SCBCdrFormatEngine from the project
Set AE=Project.GetAnalysisEngineByName("Format Analysis Engine")
Set theFormatEngine = AE
'Test a string against Format String index 2 of field MyField, using the current options for that specific search string
TestStr = "1234567890"
'The Format String index 2 is #[3-5] (Simple Expression)
fDist = theFormatEngine.TestString(TestStr, 2, theFormatSettings)
Project.LogScriptMessageEx(CDRTypeInfo, CDRSeverityLogFileOnly, "Distance from the String 1234567890 using #[3-5] is: " & CStr(fDist)) 'Expected value is 0.5
End Sub
Sample Code
The following sample code shows how to set "Compare case sensitive" and "Keep spaces between connected words" options for a specific format string of the field MyField, and how to check if an option is active.
Private Sub MyField_PreExtract(pField as SCBCdrPROJLib.ISCBCdrField, pWorkdoc as SCBCdrPROJLib.ISCBCdrWorkdoc)
Dim DocClass as SCBCdrDocClass
Dim theAnalysisSettings as SCBCdrPROJLib.ISCBCdrAnalysisSettings
Dim theSettings as Object
Dim theFormatSettings as SCBCdrFormLib.SCBCdrFormatSettings
Dim nFlag3 as Long
'Get current DocClass
Set DocClass=Project.AllClasses.ItemByName(pWorkdoc.DocClassName)
'Get the settings for the field 'MyField'
DocClass.GetFieldAnalysisSettings ("MyField","German", theAnalysisSettings)
'Convert them to the SCBCdrFormatSettings
Set theSettings = theAnalysisSettings
Set theFormatSettings = theSettings
'Set the "Case Sensitive" option (bit 1) for Format string 3
'Get the current settings for the Format String
nFlag3 = theFormatSettings.SrchFlag(3)
'Set bit 1. To clear the option, use "nFlag3 And (Not 1)"
theFormatSettings.SrchFlag(3) = nFlag3 Or 1
'Set the "Keep spaces..." option (bit 2) for Format string 3
'Get the current settings for the Format String
nFlag3 = theFormatSettings.SrchFlag(3)
'Set bit 2. To clear the option, use "nFlag3 And (Not 2)"
theFormatSettings.SrchFlag(3) = nFlag3 Or 2
'If "Keep spaces..." (bit 2) is enabled for Format String 3
'write a message in the Log
If (theFormatSettings.SrchFlag(3) And 2) Then
Project.LogScriptMessageEx (CDRTypeInfo, CDRSeverityLogFileOnly, "Keep Spaces option is active for Format String 3")
End If
End Sub