import re


def normalizeName(name):
  """Transforms a name to deal with common misspellings."""
  # Only use the first of several names.
  oneName = name.split(' ', 1)[0].lower()
  REPLACEMENTS = [
    ['y$', 'a'],  # Szczęsny = Szczęsna
    ['i$', 'a'],  # Nowicki = Nowicka
    ['ę', 'e'],
    ['ą', 'a'],
    ['ó', 'o'],
    ['ł', 'l'],
    ['ś', 's'],
    ['ż', 'z'],
    ['ź', 'z'],
    ['ć', 'c'],
    ['ń', 'n'],
    ['rz', 'z'],  # rz == ż
    ['en', 'e'],  # en == ę
    ['em', 'e'],  # em == ę
    ['on', 'a'],  # on == ą
    ['om', 'a'],  # om == ą
    ['u', 'o'],  # u == ó
    ['x', 'ks'],
    ['tt', 't'],
    ['nn', 'n'],
    ['ff', 'f'],
    ['of', 'ow'],
    ['nka$', 'na'],  # Irenka = Irena
  ]
  for repl in REPLACEMENTS:
    oneName = re.sub(repl[0], repl[1], oneName)

  return oneName