class_docstr: Character metrics for text recognition task.
  
  Args:
      valid_symbol (str): Valid characters.
          Defaults to '[^A-Z^a-z^0-9^一-龥]'
      collect_device (str): Device name used for collecting results from
          different ranks during distributed training. Must be 'cpu' or
          'gpu'. Defaults to 'cpu'.
      prefix (str, optional): The prefix that will be added in the metric
          names to disambiguate homonymous metrics of different evaluators.
          If prefix is not provided in the argument, self.default_prefix
          will be used instead. Defaults to None.
docstr: Calculate correct character number in prediction.
  
  Args:
      pred (str): Prediction text.
      gt (str): Ground truth text.
  
  Returns:
      true_positive_char_num (int): The true positive number.
docstr_tok: ["Calculate","correct","character","number","in","prediction",".","Args",":","pred","(","str",")",":","Prediction","text",".","gt","(","str",")",":","Ground","truth","text",".","Returns",":","true_positive_char_num","(","int",")",":","The","true","positive","number","."]
code: def _cal_true_positive_char(self, pred: str, gt: str) -> int:
      """Calculate correct character number in prediction.
  
      Args:
          pred (str): Prediction text.
          gt (str): Ground truth text.
  
      Returns:
          true_positive_char_num (int): The true positive number.
      """
  
      all_opt = SequenceMatcher(None, pred, gt)
      true_positive_char_num = 0
      for opt, _, _, s2, e2 in all_opt.get_opcodes():
          if opt == "equal":
              true_positive_char_num += e2 - s2
          else:
              pass
      return true_positive_char_num
  
imports: import re
  from difflib import SequenceMatcher
  from typing import Dict, Optional, Sequence, Union
  import mmengine
  from mmengine.evaluator import BaseMetric
  from rapidfuzz.distance import Levenshtein
  from mmocr.registry import METRICS
label_desc: Use image node_id 4 for calling the CharMetric obj's underlying member method code with example usage: obj._cal_true_positive_char(pred, gt) and returns: true_positive_char_num