code: def find_near_matches_generic(subsequence, sequence, search_params):
      
      if not subsequence:
          raise ValueError('Given subsequence is empty!')
  
      # if the limitations are so strict that only exact matches are allowed,
      # use search_exact()
      if search_params.max_l_dist == 0:
          return [
              Match(start_index, start_index + len(subsequence), 0)
              for start_index in search_exact(subsequence, sequence)
          ]
  
      # if the n-gram length would be at least 3, use the n-gram search method
      elif len(subsequence) // (search_params.max_l_dist + 1) >= 3:
          return find_near_matches_generic_ngrams(subsequence, sequence, search_params)
  
      # use the linear programming search method
      else:
          matches = find_near_matches_generic_linear_programming(subsequence, sequence, search_params)
  
          match_groups = group_matches(matches)
          best_matches = [get_best_match_in_group(group) for group in match_groups]
          return sorted(best_matches)
docs: search for near-matches of subsequence in sequence
  
      This searches for near-matches, where the nearly-matching parts of the
      sequence must meet the following limitations (relative to the subsequence):
  
      * the maximum allowed number of character substitutions
      * the maximum allowed number of new characters inserted
      * and the maximum allowed number of character deletions
      * the total number of substitutions, insertions and deletions