code: def deal_isolate_span(thead_part):
      """
      Deal with isolate span cases in this function.
      It causes by wrong prediction in structure recognition model.
      eg. predict <td rowspan="2"></td> to <td></td> rowspan="2"></b></td>.
      :param thead_part:
      :return:
      """
      # 1. find out isolate span tokens.
      isolate_pattern = (
          '<td></td> rowspan="(\d)+" colspan="(\d)+"></b></td>|'
          '<td></td> colspan="(\d)+" rowspan="(\d)+"></b></td>|'
          '<td></td> rowspan="(\d)+"></b></td>|'
          '<td></td> colspan="(\d)+"></b></td>'
      )
      isolate_iter = re.finditer(isolate_pattern, thead_part)
      isolate_list = [i.group() for i in isolate_iter]
  
      # 2. find out span number, by step 1 results.
      span_pattern = (
          ' rowspan="(\d)+" colspan="(\d)+"|'
          ' colspan="(\d)+" rowspan="(\d)+"|'
          ' rowspan="(\d)+"|'
          ' colspan="(\d)+"'
      )
      corrected_list = []
      for isolate_item in isolate_list:
          span_part = re.search(span_pattern, isolate_item)
          spanStr_in_isolateItem = span_part.group()
          # 3. merge the span number into the span token format string.
          if spanStr_in_isolateItem is not None:
              corrected_item = "<td{}></td>".format(
                  spanStr_in_isolateItem
              )
              corrected_list.append(corrected_item)
          else:
              corrected_list.append(None)
  
      # 4. replace original isolated token.
      for corrected_item, isolate_item in zip(
          corrected_list, isolate_list
      ):
          if corrected_item is not None:
              thead_part = thead_part.replace(
                  isolate_item, corrected_item
              )
          else:
              pass
      return thead_part
  
imports: import os
  import re
  import cv2
  import glob
  import copy
  import math
  import pickle
  import numpy
  from shapely.geometry import Polygon, MultiPoint
label_desc: Use image node_id 26 for calling a global function with example usage: deal_isolate_span(thead_part) and returns: thead_part