Use spacy.compat.json_dumps for Python 2/3 compatibility (resolves #991)

This commit is contained in:
ines 2017-04-19 11:50:33 +02:00
parent 0605b95f2e
commit 48da244058

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json import json
from ...compat import json_dumps
from ... import util from ... import util
@ -29,7 +30,8 @@ def conllu2json(input_path, output_path, n_sents=10, use_morphology=False):
output_filename = input_path.parts[-1].replace(".conllu", ".json") output_filename = input_path.parts[-1].replace(".conllu", ".json")
output_file = output_path / output_filename output_file = output_path / output_filename
json.dump(docs, output_file.open('w', encoding='utf-8'), indent=2) with output_file.open('w', encoding='utf-8') as f:
f.write(json_dumps(docs))
util.print_msg("Created {} documents".format(len(docs)), util.print_msg("Created {} documents".format(len(docs)),
title="Generated output file {}".format(output_file)) title="Generated output file {}".format(output_file))