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

40 lines
808 B

2 years ago
3 years ago
  1. from .catalog import (
  2. CSV,
  3. JSON,
  4. JSONL,
  5. AudioFile,
  6. CoNLL,
  7. Excel,
  8. FastText,
  9. Format,
  10. ImageFile,
  11. TextFile,
  12. TextLine,
  13. )
  14. from .parsers import (
  15. CoNLLParser,
  16. CSVParser,
  17. ExcelParser,
  18. FastTextParser,
  19. JSONLParser,
  20. JSONParser,
  21. LineParser,
  22. PlainParser,
  23. TextFileParser,
  24. )
  25. def create_parser(file_format: Format, **kwargs):
  26. mapping = {
  27. TextFile.name: TextFileParser,
  28. TextLine.name: LineParser,
  29. CSV.name: CSVParser,
  30. JSONL.name: JSONLParser,
  31. JSON.name: JSONParser,
  32. FastText.name: FastTextParser,
  33. Excel.name: ExcelParser,
  34. CoNLL.name: CoNLLParser,
  35. ImageFile.name: PlainParser,
  36. AudioFile.name: PlainParser,
  37. }
  38. return mapping[file_format.name](**kwargs)