From 424859669666fbee51e88dc735c4c06f5c1db021 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 6 Apr 2021 11:29:01 +0900 Subject: [PATCH] Add dict method to Record --- app/api/views/upload/dataset.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/api/views/upload/dataset.py b/app/api/views/upload/dataset.py index bed273db..26d6735f 100644 --- a/app/api/views/upload/dataset.py +++ b/app/api/views/upload/dataset.py @@ -21,6 +21,18 @@ class Record: def __str__(self): return f'{self.data}\t{self.label}' + def dict(self): + label_names = [ + { + 'text': label.name + } for label in self.label if label.has_name() + ] + return { + 'data': self.data.dict(), + 'annotation': [label.dict() for label in self.label], + 'label': label_names + } + class Dataset: