MCPcopy Create free account
hub / github.com/espnet/espnet / convert

Function convert

utils/json2trn_mt.py:44–114  ·  view source on GitHub ↗
(jsonf, dic, refs, hyps, srcs, dic_src)

Source from the content-addressed store, hash-verified

42
43
44def convert(jsonf, dic, refs, hyps, srcs, dic_src):
45 # logging info
46 logfmt = "%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s"
47 logging.basicConfig(level=logging.INFO, format=logfmt)
48 logging.info(get_commandline_args())
49
50 logging.info("reading %s", jsonf)
51 with codecs.open(jsonf, "r", encoding="utf-8") as f:
52 j = json.load(f)
53
54 # target dictionary
55 logging.info("reading %s", dic)
56 with codecs.open(dic, "r", encoding="utf-8") as f:
57 dictionary = f.readlines()
58 char_list_tgt = [entry.split(" ")[0] for entry in dictionary]
59 char_list_tgt.insert(0, "<blank>")
60 char_list_tgt.append("<eos>")
61
62 # source dictionary
63 logging.info("reading %s", dic_src)
64 if dic_src:
65 with codecs.open(dic_src, "r", encoding="utf-8") as f:
66 dictionary = f.readlines()
67 char_list_src = [entry.split(" ")[0] for entry in dictionary]
68 char_list_src.insert(0, "<blank>")
69 char_list_src.append("<eos>")
70
71 if hyps:
72 hyp_file = codecs.open(hyps[0], "w", encoding="utf-8")
73 ref_file = codecs.open(refs[0], "w", encoding="utf-8")
74 if srcs:
75 src_file = codecs.open(srcs[0], "w", encoding="utf-8")
76
77 for x in j["utts"]:
78 # hyps
79 if hyps:
80 hyp_file.write(j["utts"][x]["output"][0]["rec_text"].replace("<eos>", "")),
81
82 hyp_file.write(
83 " (" + j["utts"][x]["utt2spk"].replace("-", "_") + "-" + x + ")\n"
84 )
85
86 # ref
87 ref_file.write(j["utts"][x]["output"][0]["text"]),
88
89 ref_file.write(
90 " (" + j["utts"][x]["utt2spk"].replace("-", "_") + "-" + x + ")\n"
91 )
92
93 # src
94 if "tokenid_src" in j["utts"][x]["output"][0].keys():
95 if dic_src:
96 seq = [
97 char_list_src[int(i)]
98 for i in j["utts"][x]["output"][0]["tokenid_src"].split()
99 ]
100 else:
101 seq = [

Callers 1

mainFunction · 0.70

Calls 7

get_commandline_argsFunction · 0.90
openMethod · 0.80
insertMethod · 0.80
appendMethod · 0.80
splitMethod · 0.45
keysMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…