def _get_diff(
    sentence1: str,
    sentence2: str,
    marker: str,
) -> Tuple[str, Tuple[str, str]]:
  """Replaces smalles substring difference between two sentences."""
  sentence1 = _normalize_spaces(sentence1)
  sentence2 = _normalize_spaces(sentence2)
  if sentence1[-1] != sentence2[-1]:
    if sentence1[-1] != '.':
      logging.info('Adding punctuation to "%s"', sentence1)
      sentence1 = sentence1 + '.'
    if sentence2[-1] != '.':
      logging.info('Adding punctuation to "%s"', sentence2)
      sentence2 = sentence2 + '.'

  start_idx, end_idx = 0, 1
  for start in re.finditer(r'\b\w', sentence1):
    idx = start.span()[0]
    if sentence1[:idx] == sentence2[:idx]:
      start_idx = idx
  for end in reversed(list(re.finditer(r'\w\b', sentence1))):
    idx = end.span()[1] - len(sentence1)
    if sentence1[idx:] == sentence2[idx:]:
      end_idx = idx
  if end_idx >= 0:
    raise ValueError('Indexing with -0 will not work in this formulation so '
                     f'{sentence1} cannot end in a word character.')
  template1, option1 = _build_template(sentence1, start_idx, end_idx, marker)
  template2, option2 = _build_template(sentence2, start_idx, end_idx, marker)
  assert template1 == template2
  return template1, (option1, option2)
Replaces smalles substring difference between two sentences.
language/wino_dict/utils.py