turkic-ocr-code / scripts /r5 /r5_kohtd_check.py
treoa's picture
Release 1
24aaa76
Raw History Blame Contribute Delete
1.49 kB
"""R5 DATA: what does cleaning change in KOHTD labels, and what is the form_id of scan-named crops."""
import collections
import unicodedata
from pathlib import Path
K1 = Path("/path/to/TURKIC_OCR_DATA/data/processed/kohtd_split_v1")
for fn in ("train.tsv", "validation.tsv", "test.tsv"):
kinds = collections.Counter()
changes = collections.Counter()
ex = []
scan_forms = collections.Counter()
with open(K1 / fn, encoding="utf-8", newline="") as f:
f.readline()
for line in f:
p = line.rstrip("\n").split("\t")
kinds[p[-1]] += 1
if p[-1] != "numbered":
scan_forms[p[1][:20]] += 1
lab = "\t".join(p[2:-1])
nf = unicodedata.normalize("NFC", lab)
st = nf.strip()
if nf != lab:
changes["nfc_changed"] += 1
if len(ex) < 4:
ex.append((p[0], [hex(ord(c)) for c in lab if unicodedata.normalize("NFC", c) != c][:4], lab))
if st != nf:
changes["strip_changed"] += 1
if len(ex) < 8:
ex.append((p[0], "strip", repr(lab)))
if lab != lab.replace("\r", " ").replace("\n", " "):
changes["has_newline"] += 1
if "\t" in lab:
changes["has_tab"] += 1
print(fn, dict(kinds), dict(changes), "scan-form-ids", len(scan_forms), list(scan_forms.items())[:3])
for e in ex:
print(" ", e)