yagmurtuncer's picture
Add Turkish Text Normalization (TN/ITN) dataset: 17k rule-based pairs + reproducible pipeline, validation, dataset card
5c0e24f verified
Raw
History Blame Contribute Delete
1.87 kB
# -*- 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)