Scripting - How to mark a document for Online Learning
Issue
How to mark a document for Online Learning by script?
Solution
Specific Online Learning was introduced in KTM 3.5. The user has to manually press a button in Validation to mark a document for Specific Online Learning. The following script allows it to perform this step automatically.
To improve this process and get rid of the script automatic training was added in 6.3: if this is enabled and a field is changed in Validation then the document will be marked automatically for training. Please try this first as it will also check if new documents are required!
Please note that the script code does not check if it really makes sense to train the current document.
To mark a document for either Generic or Specific Online Learning, a text file needs to be created with the same name as the XDocument, but with the extension ".oll". The content of the OLL file controls the detailed action for this document in the Knowledge Base Learning Server. To mark a document for Specific Online Learning, the Specific option needs to be set to 1.
Add Microsoft Scripting Runtime
to the reference list first. The script event below runs in server, but it is also possible to move the script code to a different event, e.g., Document_Validated
.
Private Sub Document_AfterProcess(pXDoc As CASCADELib.CscXDocument) '* Reference - Microsoft Scripting Runtime (1.0) '* Create an online learning (OL) file To go With the XDoc If (check_if_training_is_required(pXDoc)) Then ' your function to check, if training is required Dim XDocFilename As String Dim OllFilename As String Dim FDS As New FileSystemObject Dim TS As TextStream XDocFilename = pXDoc.FileName OllFilename = Left(XDocFilename, Len(XDocFilename) - 3) + "oll" Set TS = FDS.CreateTextFile(OllFilename, True, False) TS.WriteLine("NTUser=script_"+Environ("USERNAME")) TS.WriteLine("NTStation=script_"+Environ("COMPUTERNAME")) TS.WriteLine("Classification=0") TS.WriteLine("Extraction=0") TS.WriteLine("Specific=1") TS.WriteLine("Comment=") TS.Close End If End Sub
An alternative script in pure WinWrap Basic without external references:
Sub MarkDocumentForOnlineLearning(pXDoc As CASCADELib.CscXDocument,comment As String, _ classification As Boolean, extraction As Boolean, specific As Boolean) Dim OllFilename As String OllFilename = Left(pXDoc.FileName, Len(pXDoc.FileName) - 3) + "oll" Dim FileNum As Integer FileNum=FreeFile Open OllFilename For Output As #FileNum Print #FileNum, "NTUser=script_" & Environ("USERNAME") Print #FileNum, "NTStation=script_" & Environ("COMPUTERNAME") Print #FileNum, "Classification=" & Bool2String(classification) Print #FileNum, "Extraction=" & Bool2String(extraction) Print #FileNum, "Specific=" & Bool2String(specific) Print #FileNum, "Comment=" & comment Close #FileNum End Sub Private Function Bool2String(a As Boolean) As String Bool2String = "0" If a Then Bool2String = "1" End Function
Level of Complexity
Moderate
Applies to
Product | Version | Build | Environment | Hardware |
---|---|---|---|---|
Kofax Transformation Module | all |
References
Add any references to other internal or external articles