Browse Source
Merge pull request #670 from doccano/bugfix/enable-to-display-non-ascii-metadata
Enable to display non-ascii metadata
pull/671/head
v1.0.4
Hiroki Nakayama
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
6 additions and
2 deletions
-
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) |
|
|
|