From c53b243b1b6fddbb1c1e92d24e246380f789bbc1 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 7 Apr 2021 11:04:24 +0900 Subject: [PATCH] Add factories --- app/api/views/upload/factory.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/api/views/upload/factory.py diff --git a/app/api/views/upload/factory.py b/app/api/views/upload/factory.py new file mode 100644 index 00000000..14c3132c --- /dev/null +++ b/app/api/views/upload/factory.py @@ -0,0 +1,28 @@ +from . import dataset +from . import label + + +def get_dataset_class(format: str): + if format == 'csv': + return dataset.CsvDataset + elif format == 'jsonl': + return dataset.JSONLDataset + elif format == 'json': + return dataset.JSONDataset + elif format == 'fasttext': + return dataset.FastTextDataset + elif format == 'excel': + return dataset.ExcelDataset + else: + ValueError(f'Invalid format: {format}') + + +def get_label_class(project_type: str): + if project_type == 'DocumentClassification': + return label.CategoryLabel + elif project_type == 'SequenceLabeling': + return label.OffsetLabel + elif project_type == 'Seq2seq': + return label.TextLabel + else: + ValueError(f'Invalid project type: {project_type}')