Download parse_text.py from speech-seq2seq/ami: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/speech-seq2seq/ami/resolve/main/parse_text.py
- Command line
-
hf download hf://datasets/speech-seq2seq/ami/parse_text.py
-
curl -L -o parse_text.py https://huggingface.co/datasets/speech-seq2seq/ami/resolve/main/parse_text.py
1.29 kB
| #!/usr/bin/env python3 | |
| import sys | |
| import re | |
| transcript = sys.argv[1] | |
| new_transcript = sys.argv[2] | |
| ref_look_up_dict_end = {} | |
| with open(transcript, "r") as f: | |
| ref_lines = f.readlines() | |
| for line in ref_lines: | |
| items = line.split(" ") | |
| key = "_".join(items[:3] + items[4:5]) | |
| if key in ref_look_up_dict_end: | |
| print("WARNING: Already there", "_".join(items)) | |
| ref_look_up_dict_end[key] = " ".join(items[5:]) | |
| for line in ref_lines: | |
| items = line.split(" ") | |
| key = "_".join(items[:3] + items[4:5]) | |
| start_time = items[3] | |
| if " ," in line: | |
| index = int(line.split(" ,")[1][0]) | |
| if index > 0: | |
| new_key = "_".join(key.split("_")[:3] + [start_time]) | |
| if new_key in ref_look_up_dict_end and ref_look_up_dict_end[new_key].strip()[-1] not in [".", ",", "?"]: | |
| ref_look_up_dict_end[new_key] = ref_look_up_dict_end[new_key].strip() + ",\n" # noqa: E501 | |
| with open(new_transcript, "w") as f: | |
| for line in ref_lines: | |
| items = line.split(" ") | |
| key = "_".join(items[:3] + items[4:5]) | |
| if key in ref_look_up_dict_end: | |
| line = ref_look_up_dict_end.pop(key) | |
| line = re.sub(r" \,[0-9]+", ",", line) | |
| f.write(" ".join(items[:5]) + " " + line) | |