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.

30 lines
1.1 KiB

  1. from typing import Type
  2. from ...models import (DOCUMENT_CLASSIFICATION, IMAGE_CLASSIFICATION, SEQ2SEQ,
  3. SEQUENCE_LABELING)
  4. from . import catalog, repositories, writer
  5. def create_repository(project) -> repositories.BaseRepository:
  6. mapping = {
  7. DOCUMENT_CLASSIFICATION: repositories.TextClassificationRepository,
  8. SEQUENCE_LABELING: repositories.SequenceLabelingRepository,
  9. SEQ2SEQ: repositories.Seq2seqRepository,
  10. IMAGE_CLASSIFICATION: repositories.FileRepository,
  11. }
  12. if project.project_type not in mapping:
  13. ValueError(f'Invalid project type: {project.project_type}')
  14. repository = mapping.get(project.project_type)(project)
  15. return repository
  16. def create_writer(format: str) -> Type[writer.BaseWriter]:
  17. mapping = {
  18. catalog.CSV.name: writer.CsvWriter,
  19. catalog.JSON.name: writer.JSONWriter,
  20. catalog.JSONL.name: writer.JSONLWriter,
  21. catalog.FastText.name: writer.FastTextWriter,
  22. }
  23. if format not in mapping:
  24. ValueError(f'Invalid format: {format}')
  25. return mapping[format]