code: def fix_ending(word):
      if word[-2:] in _doubles:
          word = word[:-1]
  
      for endingrule in _endingrules[word[-1]]:
          target, newend = endingrule[:2]
          if word.endswith(target):
              if len(endingrule) > 2:
                  exceptafter = endingrule[2]
                  c = word[0 - (len(target) + 1)]
                  if c in exceptafter:
                      return word
  
              return word[: 0 - len(target)] + newend
  
      return word
  
imports: from collections import defaultdict
label_desc: Use image node_id 31 for calling a global function with example usage: fix_ending(word) and returns: word, unknown, word