code: def singularize(word, pos=NOUN, custom=None):
      
      if custom and word in custom:
          return custom[word]
      # Recurse compound words (e.g. mothers-in-law).
      if "-" in word:
          w = word.split("-")
          if len(w) > 1 and w[1] in plural_prepositions:
              return singularize(w[0], pos, custom) + "-" + "-".join(w[1:])
      # dogs' => dog's
      if word.endswith("'"):
          return singularize(word[:-1]) + "'s"
      w = word.lower()
      for x in singular_uninflected:
          if x.endswith(w):
              return word
      for x in singular_uncountable:
          if x.endswith(w):
              return word
      for x in singular_ie:
          if w.endswith(x + "s"):
              return w[:-1]
      for x in singular_irregular:
          if w.endswith(x):
              return re.sub('(?i)' + x + '$', singular_irregular[x], word)
      for suffix, inflection in singular_rules:
          m = suffix.search(word)
          g = m and m.groups() or []
          if m:
              for k in range(len(g)):
                  if g[k] is None:
                      inflection = inflection.replace('\\' + str(k + 1), '')
              return suffix.sub(inflection, word)
      return word
docs: Returns the singular of a given word.