Browse Source

Enable to display non-ascii metadata, resolves #513

pull/670/head
Hironsan 4 years ago
parent
commit
63044f942b
1 changed files with 6 additions and 2 deletions
  1. 8
      app/api/utils.py

8
app/api/utils.py

@ -222,6 +222,10 @@ class FileParser(object):
def parse(self, file):
raise NotImplementedError()
@staticmethod
def encode_metadata(data):
return json.dumps(data, ensure_ascii=False)
class CoNLLParser(FileParser):
"""Uploads CoNLL format file.
@ -358,7 +362,7 @@ class ExcelParser(FileParser):
elif len(row) == len(columns) and len(row) >= 2:
datum = dict(zip(columns, row))
text, label = datum.pop('text'), datum.pop('label')
meta = json.dumps(datum)
meta = FileParser.encode_metadata(datum)
j = {'text': text, 'labels': [label], 'meta': meta}
data.append(j)
else:
@ -379,7 +383,7 @@ class JSONParser(FileParser):
data = []
try:
j = json.loads(line)
j['meta'] = json.dumps(j.get('meta', {}))
j['meta'] = FileParser.encode_metadata(j.get('meta', {}))
data.append(j)
except json.decoder.JSONDecodeError:
raise FileParseException(line_num=i, line=line)

Loading…
Cancel
Save