You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

path.py 1.3 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """Utility of file path"""
  2. import pathlib
  3. FILE_TYPE_ALIASES = {
  4. ".tbz": (".tar", ".bz2"),
  5. ".tbz2": (".tar", ".bz2"),
  6. ".tgz": (".tar", ".gz"),
  7. }
  8. ARCHIVE_TYPE_SUFFIX = [
  9. ".tar",
  10. ".zip",
  11. ]
  12. COMPRESS_TYPE_SUFFIX = [
  13. ".bz2",
  14. ".gz",
  15. ]
  16. def detect_file_type(filename: str): # pylint: disable=inconsistent-return-statements
  17. """Detect file type by suffixes and return tuple(suffix, archive_type, compression)."""
  18. suffixes = pathlib.Path(filename).suffixes
  19. if not suffixes:
  20. raise RuntimeError(f"File `{filename}` has no suffixes that could be used to detect.")
  21. suffix = suffixes[-1]
  22. # Check if the suffix is a known alias.
  23. if suffix in FILE_TYPE_ALIASES:
  24. return suffix, FILE_TYPE_ALIASES[suffix][0], FILE_TYPE_ALIASES[suffix][1]
  25. # Check if the suffix is an archive type.
  26. if suffix in ARCHIVE_TYPE_SUFFIX:
  27. return suffix, suffix, None
  28. # Check if the suffix is a compression.
  29. if suffix in COMPRESS_TYPE_SUFFIX:
  30. # Check for suffix hierarchy.
  31. if len(suffixes) > 1:
  32. suffix2 = suffixes[-2]
  33. # Check if the suffix2 is an archive type.
  34. if suffix2 in ARCHIVE_TYPE_SUFFIX:
  35. return suffix2 + suffix, suffix2, suffix
  36. return suffix, None, suffix

基于MindSpore的多模态股票价格预测系统研究 Informer,LSTM,RNN