|
|
@ -1,9 +1,7 @@
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
# encoding: utf-8
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
|
|
|
|
# Copyright 2018 Nagoya University (Tomoki Hayashi)
|
|
|
|
# Copyright 2018 Nagoya University (Tomoki Hayashi)
|
|
|
|
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
|
@ -12,7 +10,6 @@ import codecs
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
from distutils.util import strtobool
|
|
|
|
from distutils.util import strtobool
|
|
|
|
|
|
|
|
|
|
|
|
from espnet.utils.cli_utils import get_commandline_args
|
|
|
|
from espnet.utils.cli_utils import get_commandline_args
|
|
|
@ -23,17 +20,16 @@ is_python2 = sys.version_info[0] == 2
|
|
|
|
def get_parser():
|
|
|
|
def get_parser():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="add multiple json values to an input or output value",
|
|
|
|
description="add multiple json values to an input or output value",
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter, )
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument("jsons", type=str, nargs="+", help="json files")
|
|
|
|
parser.add_argument("jsons", type=str, nargs="+", help="json files")
|
|
|
|
parser.add_argument(
|
|
|
|
parser.add_argument(
|
|
|
|
"-i",
|
|
|
|
"-i",
|
|
|
|
"--is-input",
|
|
|
|
"--is-input",
|
|
|
|
default=True,
|
|
|
|
default=True,
|
|
|
|
type=strtobool,
|
|
|
|
type=strtobool,
|
|
|
|
help="If true, add to input. If false, add to output",
|
|
|
|
help="If true, add to input. If false, add to output", )
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
parser.add_argument("--verbose", "-V", default=0, type=int, help="Verbose option")
|
|
|
|
"--verbose", "-V", default=0, type=int, help="Verbose option")
|
|
|
|
return parser
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -121,7 +117,8 @@ if __name__ == "__main__":
|
|
|
|
out_add_dic = {}
|
|
|
|
out_add_dic = {}
|
|
|
|
# add shape
|
|
|
|
# add shape
|
|
|
|
if "odim" in adddic and "olen" in adddic:
|
|
|
|
if "odim" in adddic and "olen" in adddic:
|
|
|
|
out_add_dic["shape"] = [int(adddic["olen"]), int(adddic["odim"])]
|
|
|
|
out_add_dic[
|
|
|
|
|
|
|
|
"shape"] = [int(adddic["olen"]), int(adddic["odim"])]
|
|
|
|
elif "odim" in adddic:
|
|
|
|
elif "odim" in adddic:
|
|
|
|
out_add_dic["shape"] = [int(adddic["odim"])]
|
|
|
|
out_add_dic["shape"] = [int(adddic["odim"])]
|
|
|
|
# add all other key value
|
|
|
|
# add all other key value
|
|
|
@ -143,13 +140,13 @@ if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
# ensure "ensure_ascii=False", which is a bug
|
|
|
|
# ensure "ensure_ascii=False", which is a bug
|
|
|
|
jsonstring = json.dumps(
|
|
|
|
jsonstring = json.dumps(
|
|
|
|
{"utts": new_dic},
|
|
|
|
{
|
|
|
|
|
|
|
|
"utts": new_dic
|
|
|
|
|
|
|
|
},
|
|
|
|
indent=4,
|
|
|
|
indent=4,
|
|
|
|
ensure_ascii=False,
|
|
|
|
ensure_ascii=False,
|
|
|
|
sort_keys=True,
|
|
|
|
sort_keys=True,
|
|
|
|
separators=(",", ": "),
|
|
|
|
separators=(",", ": "), )
|
|
|
|
)
|
|
|
|
sys.stdout = codecs.getwriter("utf-8")(sys.stdout
|
|
|
|
sys.stdout = codecs.getwriter("utf-8")(
|
|
|
|
if is_python2 else sys.stdout.buffer)
|
|
|
|
sys.stdout if is_python2 else sys.stdout.buffer
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
print(jsonstring)
|
|
|
|
print(jsonstring)
|
|
|
|