VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "DetectorMorpho"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ====== Morphology expression detector =======
' Shared module version: 20220613
' Tested in:
' Depends on:
' Required reference: API_Python, ex_Python
Option Explicit

Private tags_ As String

Public Function Init(sTags$)
  tags_ = sTags
End Function

Public Function Test(sText$) As Boolean
  If tags_ = vbNullString Then _
    Exit Function
  Test = AccessPython.CallFunction(PY_MODULE_TEXT, "parse", Array(sText, tags_)) <> ""
End Function

Public Function ExtractFragments(sText$) As PC_ParsedData
  Dim iData As New PC_ParsedData
  
  On Error GoTo SKIP_PYTHON
  Dim iResult As Variant
  iResult = AccessPython.CallFunction(PY_MODULE_TEXT, "match_all_morpho", Array(sText, tags_))
  On Error GoTo 0
  
  Dim nItem&
  For nItem = LBound(iResult) To UBound(iResult) Step 1
    Dim nStart&: nStart = iResult(nItem, 0)
    Dim nEnd&: nEnd = iResult(nItem, 1)
    Call iData.AddItem(nStart, nEnd)
  Next nItem

SKIP_PYTHON:
  Set ExtractFragments = iData
End Function

