utils.py 617 B

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. from typing import Union
  3. import inflect
  4. _inflect = inflect.engine()
  5. def num_to_word(x: Union[str, int]):
  6. """
  7. converts integer to spoken representation
  8. Args
  9. x: integer
  10. Returns: spoken representation
  11. """
  12. if isinstance(x, int):
  13. x = str(x)
  14. x = _inflect.number_to_words(str(x)).replace("-", " ").replace(",", "")
  15. return x
  16. def get_abs_path(rel_path):
  17. """
  18. Get absolute path
  19. Args:
  20. rel_path: relative path to this file
  21. Returns absolute path
  22. """
  23. return os.path.dirname(os.path.abspath(__file__)) + '/' + rel_path