code: def get_all_candidates_coverage(phrases, phrases2positions):
      """Get maximum hit coverage for each phrase - within a moving window of length of the phrase.
      Args:
          phrases: List of all phrases in custom vocabulary. Position corresponds to phrase_id.
          phrases2positions: a matrix of size (len(phrases), len(ASR-hypothesis)).
              It is filled with 1.0 (hits) on intersection of letter n-grams and phrases that are indexed by these n-grams, 0.0 - elsewhere.
      Returns:
          candidate2coverage: list of size len(phrases) containing coverage (0.0 to 1.0) in best window.
          candidate2position: list of size len(phrases) containing starting position of best window.
      """
      candidate2coverage = [0.0] * len(phrases)
      candidate2position = [-1] * len(phrases)
  
      for i in range(len(phrases)):
          phrase_length = phrases[i].count(" ") + 1
          all_coverage = np.sum(phrases2positions[i]) / phrase_length
          # if total coverage on whole ASR-hypothesis is too small, there is no sense in using moving window
          if all_coverage < 0.4:
              continue
          moving_sum = np.sum(phrases2positions[i, 0:phrase_length])
          max_sum = moving_sum
          best_pos = 0
          for pos in range(
              1, phrases2positions.shape[1] - phrase_length + 1
          ):
              moving_sum -= phrases2positions[i, pos - 1]
              moving_sum += phrases2positions[
                  i, pos + phrase_length - 1
              ]
              if moving_sum > max_sum:
                  max_sum = moving_sum
                  best_pos = pos
  
          coverage = max_sum / (phrase_length + 2)  # smoothing
          candidate2coverage[i] = coverage
          candidate2position[i] = best_pos
      return candidate2coverage, candidate2position
  
imports: import json
  import math
  import random
  import re
  from collections import defaultdict, namedtuple
  from typing import Dict, List, Set, Tuple, Union
  import numpy
  from numba import jit
label_desc: Use image node_id 8 for calling a global function with example usage: get_all_candidates_coverage(phrases, phrases2positions) and returns: candidate2coverage,  candidate2position