def _find_exact_matches(source, target):
  """Returns longest non-overlapping sub-strings shared by source and target."""
  source_len = len(source)
  target_len = len(target)

  matches = set()
  matched_source_ranges = set()
  matched_target_ranges = set()
  for sequence_len in range(max(target_len, source_len), 0, -1):
    for source_start_idx in range(0, source_len - sequence_len + 1):
      source_end_idx = source_start_idx + sequence_len
      if _in_matched_range(source_start_idx, source_end_idx,
                           matched_source_ranges):
        continue
      for target_start_idx in range(0, target_len - sequence_len + 1):
        target_end_idx = target_start_idx + sequence_len
        if _in_matched_range(target_start_idx, target_end_idx,
                             matched_target_ranges):
          continue

        source_span = source[source_start_idx:source_end_idx]
        target_span = target[target_start_idx:target_end_idx]

        if source_span == target_span:
          matches.add(tuple(source_span))
          matched_source_ranges.add((source_start_idx, source_end_idx))
          matched_target_ranges.add((target_start_idx, target_end_idx))

  return matches
Returns longest non-overlapping sub-strings shared by source and target.
language/compgen/nqg/model/induction/exact_match_utils.py