Commit 1d8b79f61492cbb28ce0f087f3a9dcea8546e06b
1 parent
16251ebfaa
Exists in
master
Changed to make simple the utt2sub and sub2utt commands. Was too long, no it cost less time.
Showing 1 changed file with 15 additions and 19 deletions Side-by-side Diff
volia/masseffect.py
... | ... | @@ -92,32 +92,30 @@ |
92 | 92 | of.write(f"{kaldi_id} {masseffect_id}\n") |
93 | 93 | |
94 | 94 | |
95 | -def utt2sub(file: str, subfile: str, outfile: str): | |
95 | +def utt2sub(file: str, outfile: str): | |
96 | 96 | data = core.data.read_id_values(file) |
97 | 97 | keys = [key for key in data] |
98 | 98 | |
99 | - data_sub = core.data.read_id_values(subfile) | |
100 | - keys_sub = [key for key in data_sub] | |
101 | - | |
102 | 99 | with open(outfile, "w") as of: |
103 | - for key in keys: | |
104 | - subkeys = [subkey for subkey in keys_sub if subkey.startswith(key)] | |
105 | - subkeys_str = " ".join(subkeys) | |
100 | + key_2_subkeys = {} | |
101 | + for subkey in keys: | |
102 | + key = subkey.replace(" ", "").replace("\n", "").split("_")[:-1] | |
103 | + key_2_subkeys[key] = [] | |
104 | + key_2_subkeys[key].append(subkey) | |
105 | + | |
106 | + for key in key_2_subkeys: | |
107 | + subkeys_str = " ".join(key_2_subkeys[key]) | |
106 | 108 | of.write(f"{key} {subkeys_str}\n") |
107 | 109 | |
108 | 110 | |
109 | -def sub2utt(file: str, subfile: str, outfile: str): | |
111 | +def sub2utt(file: str, outfile: str): | |
110 | 112 | data = core.data.read_id_values(file) |
111 | 113 | keys = [key for key in data] |
112 | 114 | |
113 | - data_sub = core.data.read_id_values(subfile) | |
114 | - keys_sub = [key for key in data_sub] | |
115 | - | |
116 | 115 | with open(outfile, "w") as of: |
117 | - for key in keys: | |
118 | - subkeys = [subkey for subkey in keys_sub if subkey.startswith(key)] | |
119 | - for subkey in subkeys: | |
120 | - of.write(f"{subkey} {key}\n") | |
116 | + for subkey in keys: | |
117 | + key = subkey.replace(" ", "").replace("\n", "").split("_")[:-1] | |
118 | + of.write(f"{subkey} {key}\n") | |
121 | 119 | |
122 | 120 | |
123 | 121 | if __name__ == '__main__': |
124 | 122 | |
... | ... | @@ -162,15 +160,13 @@ |
162 | 160 | |
163 | 161 | # Create utt2sub |
164 | 162 | parser_utt2sub = subparsers.add_parser("utt2sub", help="generate utt2sub file") |
165 | - parser_utt2sub.add_argument("--file", required=True, type=str, help="features, list or labels file with normal ids") | |
166 | - parser_utt2sub.add_argument("--subfile", required=True, type=str, help="features, list or labels file with sub ids") | |
163 | + parser_utt2sub.add_argument("--file", required=True, type=str, help="features, list or labels file with sub ids") | |
167 | 164 | parser_utt2sub.add_argument("--outfile", required=True, type=str, help="output file") |
168 | 165 | parser_utt2sub.set_defaults(which="utt2sub") |
169 | 166 | |
170 | 167 | # Create sub2utt |
171 | 168 | parser_sub2utt = subparsers.add_parser("sub2utt", help="generate sub2utt file") |
172 | - parser_sub2utt.add_argument("--file", required=True, type=str, help="features, list or labels file with normal ids") | |
173 | - parser_sub2utt.add_argument("--subfile", required=True, type=str, help="features, list or labels file sub ids") | |
169 | + parser_sub2utt.add_argument("--file", required=True, type=str, help="features, list or labels file with sub ids") | |
174 | 170 | parser_sub2utt.add_argument("--outfile", required=True, type=str, help="output file") |
175 | 171 | parser_sub2utt.set_defaults(which="sub2utt") |
176 | 172 |