From a4fca261371f508721e45700e39b950e85b6718a Mon Sep 17 00:00:00 2001 From: erikamenezes Date: Mon, 20 May 2019 22:01:09 +0000 Subject: [PATCH 1/9] added feature to export jsaon text labels --- app/server/api.py | 12 ++++++++-- .../static/js/download_sequence_labeling.vue | 18 +++++++++++++++ .../download_sequence_labeling.json1l | 3 +++ app/server/utils.py | 22 +++++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 app/server/static/js/examples/download_sequence_labeling.json1l diff --git a/app/server/api.py b/app/server/api.py index bc853c4d..5376f7de 100644 --- a/app/server/api.py +++ b/app/server/api.py @@ -209,13 +209,21 @@ class TextDownloadAPI(APIView): project = get_object_or_404(Project, pk=self.kwargs['project_id']) documents = project.documents.all() painter = self.select_painter(format) - data = painter.paint(documents) + + # json1 format prints text labels while json format prints annotations with label ids + # json1 format - "labels": [[0, 15, "PERSON"], ..] + # json format "annotations": [{"label": 5, "start_offset": 0, "end_offset": 2, "user": 1},..] + if format == "json1": + labels = project.labels.all() + data = painter.paint_labels(documents, labels) + else: + data = painter.paint(documents) return Response(data) def select_painter(self, format): if format == 'csv': return CSVPainter() - elif format == 'json': + elif format == 'json' or format == "json1": return JSONPainter() else: raise ValidationError('format {} is invalid.'.format(format)) diff --git a/app/server/static/js/download_sequence_labeling.vue b/app/server/static/js/download_sequence_labeling.vue index 10529fac..dfea48a7 100644 --- a/app/server/static/js/download_sequence_labeling.vue +++ b/app/server/static/js/download_sequence_labeling.vue @@ -12,11 +12,29 @@ block select-format-area ) | JSONL + label.radio + input( + type="radio" + name="format" + value="json1" + v-bind:checked="format == 'json1'" + v-model="format" + ) + | JSON(Text-Labels) + + block example-format-area pre.code-block(v-show="format == 'json'") code.json include ./examples/download_sequence_labeling.jsonl | ... + pre.code-block(v-show="format == 'json1'") + code.json + include ./examples/download_sequence_labeling.json1l + | ... + + +