Datasets:
File size: 1,868 Bytes
5c0e24f | 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 | # -*- coding: utf-8 -*-
"""Data quality checks for the Turkish Text Normalization dataset."""
import csv, glob, re, sys
from collections import Counter
ALLOWED_CAT = {"cardinal","ordinal","decimal","percentage","currency","date","time"}
# spoken side should only contain lowercase Turkish letters + spaces
SPOKEN_RE = re.compile(r"^[a-zçğıöşü ]+$")
def load(path):
with open(path, encoding="utf-8") as f:
return list(csv.DictReader(f))
errors = 0
def check(cond, msg):
global errors
if not cond:
errors += 1; print("FAIL:", msg)
rows = []
for p in sorted(glob.glob("data/*.csv")):
r = load(p); rows += r
print(f"{p}: {len(r)} rows")
# 1) no empty fields
check(all(r["written"].strip() and r["spoken"].strip() and r["category"].strip() for r in rows),
"empty field found")
# 2) categories valid
bad = set(r["category"] for r in rows) - ALLOWED_CAT
check(not bad, f"unexpected categories: {bad}")
# 3) spoken charset (lowercase Turkish only)
badspk = [r["spoken"] for r in rows if not SPOKEN_RE.match(r["spoken"])][:5]
check(not badspk, f"spoken has invalid chars, e.g. {badspk}")
# 4) global uniqueness of (written, spoken)
pairs = [(r["written"], r["spoken"]) for r in rows]
dups = [k for k,v in Counter(pairs).items() if v > 1][:5]
check(not dups, f"duplicate (written,spoken) pairs: {dups}")
# 5) every category present
present = set(r["category"] for r in rows)
check(present == ALLOWED_CAT, f"missing categories: {ALLOWED_CAT - present}")
# 6) written side non-trivial (has a digit)
check(all(any(ch.isdigit() for ch in r["written"]) for r in rows), "written without digits")
print("\nby category:", dict(sorted(Counter(r["category"] for r in rows).items())))
print("total:", len(rows))
print("RESULT:", "ALL CHECKS PASSED ✅" if errors == 0 else f"{errors} CHECK(S) FAILED ❌")
sys.exit(1 if errors else 0)
|