util.py 614 B

12345678910111213141516171819202122232425
  1. # Natural Language Toolkit: Stemmer Utilities
  2. #
  3. # Copyright (C) 2001-2019 NLTK Project
  4. # Author: Helder <he7d3r@gmail.com>
  5. # URL: <http://nltk.org/>
  6. # For license information, see LICENSE.TXT
  7. def suffix_replace(original, old, new):
  8. """
  9. Replaces the old suffix of the original string by a new suffix
  10. """
  11. return original[: -len(old)] + new
  12. def prefix_replace(original, old, new):
  13. """
  14. Replaces the old prefix of the original string by a new suffix
  15. :param original: string
  16. :param old: string
  17. :param new: string
  18. :return: string
  19. """
  20. return new + original[len(old) :]