File size: 1,290 Bytes
28e6c6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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)