utils.py 679 B

123456789101112131415161718192021222324252627282930313233343536
  1. import csv
  2. import os
  3. import logging
  4. def get_abs_path(rel_path):
  5. """
  6. Get absolute path
  7. Args:
  8. rel_path: relative path to this file
  9. Returns absolute path
  10. """
  11. abs_path = os.path.dirname(os.path.abspath(__file__)) + os.sep + rel_path
  12. if not os.path.exists(abs_path):
  13. logging.warning(f'{abs_path} does not exist')
  14. return abs_path
  15. def load_labels(abs_path):
  16. """
  17. loads relative path file as dictionary
  18. Args:
  19. abs_path: absolute path
  20. Returns dictionary of mappings
  21. """
  22. label_tsv = open(abs_path, encoding='utf-8')
  23. labels = list(csv.reader(label_tsv, delimiter="\t"))
  24. return labels