def _morph_by_rules(
    word: str, morph_rules: Dict[str, Dict[str,
                                           str]]) -> Optional[Dict[str, str]]:
  """Creates the morphology dictionary for a word based on the rules.

  Note that this dictionary is from a part of speech to that word's conjugation
  for that part of speech. It tries to find the longest matching suffix in the
  dictionary, failing if a suffix isn't found for some part of speech.

  Args:
    word: The word to find the morphology for.
    morph_rules: The part of speech to suffix substitution dictionary.

  Returns:
    A part of speech to conjugated word dictionary.
  """
  morphs = {}
  for pos, suffix_to_change in morph_rules.items():
    i = max(5, len(word))
    morph = None
    while i >= 2:
      suggested_suffix = word[-i:]
      if suggested_suffix in suffix_to_change:
        morph = f"{word[:-i]}{suffix_to_change[suggested_suffix]}"
        break
      i -= 1
    if morph is None:
      return None
    morphs[pos] = morph
  return morphs
Creates the morphology dictionary for a word based on the rules.

  Note that this dictionary is from a part of speech to that word's conjugation
  for that part of speech. It tries to find the longest matching suffix in the
  dictionary, failing if a suffix isn't found for some part of speech.

  Args:
    word: The word to find the morphology for.
    morph_rules: The part of speech to suffix substitution dictionary.

  Returns:
    A part of speech to conjugated word dictionary.
  
language/wino_dict/create_new_words.py