Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/json export #778

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
rename format to export_format and add default case
  • Loading branch information
cgill95 committed May 19, 2020
commit b8cd462ab30878a61a06b8863f54d09df381ef20
12 changes: 6 additions & 6 deletions app/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,29 +412,29 @@ def render(self, data, accepted_media_type=None, renderer_context=None):

class JSONPainter(object):

def paint(self, documents, format):
def paint(self, documents, export_format='jsonl'):
serializer = DocumentSerializer(documents, many=True)
data = []
if format == 'json':
if export_format == 'json':
data.append([])
for d in serializer.data:
d['meta'] = json.loads(d['meta'])
for a in d['annotations']:
a.pop('id')
a.pop('prob')
a.pop('document')
if format == 'json':
if export_format == 'json':
data[0].append(d)
else:
data.append(d)
return data

@staticmethod
def paint_labels(documents, labels, format):
def paint_labels(documents, labels, export_format='jsonl'):
serializer_labels = LabelSerializer(labels, many=True)
serializer = DocumentSerializer(documents, many=True)
data = []
if format == 'json':
if export_format == 'json':
data.append([])
for d in serializer.data:
labels = []
Expand All @@ -447,7 +447,7 @@ def paint_labels(documents, labels, format):
d.pop('annotations')
d['labels'] = labels
d['meta'] = json.loads(d['meta'])
if format == 'json':
if export_format == 'json':
data[0].append(d)
else:
data.append(d)
Expand Down