-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_flags_rime.py
More file actions
49 lines (39 loc) · 1.22 KB
/
add_flags_rime.py
File metadata and controls
49 lines (39 loc) · 1.22 KB
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
39
40
41
42
43
44
45
46
47
48
49
import os
for f in os.listdir("../../CARRA-evaluation/flags_rime"):
st = f.replace(".csv", "")
fr = f"../../CARRA-evaluation/flags_rime/{st}.csv"
ff = f"flags/{st}.csv"
if not os.path.exists(ff):
continue
# read rime flags (drop header)
with open(fr, "r", encoding="utf-8") as src:
rime_lines = src.read().splitlines()[1:]
# read base file
with open(ff, "r", encoding="utf-8") as base:
existing = base.read().splitlines()
# remove old rime lines
existing = [
ln for ln in existing
if "automatically detected as rime-affected (bav)" not in ln
]
# compute new lines to add
new = [ln for ln in rime_lines if ln not in existing]
# prepare final list
final = existing.copy()
if new:
final.append("")
final.extend(new)
# collapse multiple blank lines
cleaned = []
last_empty = False
for ln in final:
if ln.strip() == "":
if not last_empty:
cleaned.append("")
last_empty = True
else:
cleaned.append(ln)
last_empty = False
# write result
with open(ff, "w", encoding="utf-8") as out:
out.write("\n".join(cleaned) + "\n")