#!/usr/bin/env python3 """Sanity checks for dataset/cases.jsonl. Run after any rebuild. python3 lint_dataset.py # exit 1 if any problem is found Checks: - every case has the fields the rig needs, 6-tool fixtures only - a case's text never contains another shop's/owner's codename, and no codename from the first release is left (either would decode a word of a real shop name); a case naming its own shop or house brand is fine - no synthetic codename glued inside another word: the anonymizer once replaced substrings, turning «پیگیری» into «پیدیبا» and «سنگین» into «سآذین»; a codename may only appear as a whole word - no characters from scripts the dataset never uses (CJK, Devanagari, ...) - no shop-side message that is empty and is not a product card / picture - escalate_to_vendor success fixtures use one of the current texts and do not tell the model to name a human («مدیر غرفه», «همکارم»), which the system prompt forbids """ from __future__ import annotations import json import os import re import sys HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) TOOLS = {"get_product_info", "search_products_in_basalam", "get_similar_products", "google_search", "escalate_to_vendor", "get_customer_order_status"} # synthetic names the anonymizer uses for shops/owners/brands _CN = json.load(open(os.path.join(ROOT, "dataset", "codenames.json"))) NAME_CODENAMES = _CN["shop_and_owner_codenames"] OLD_CODENAMES = _CN["old_codenames"] CODENAMES = NAME_CODENAMES + OLD_CODENAMES NAME_LINE = re.compile(r"(نام|مدیر) غرفه\s*\**\s*:") LETTER = r"[\u0621-\u063A\u0641-\u064A\u0671-\u06D3]" # letters, not ، ؛ ؟ GLUED = re.compile( rf"(?:{LETTER}(?:{'|'.join(map(re.escape, CODENAMES))})" rf"|(?:{'|'.join(map(re.escape, CODENAMES))}){LETTER})") # real words that merely contain a codename ALLOWED = {"بزارین", "جوانکننده", "مهتابی", "مهتابی،فلاسک،", "بلند", "بلندتر", "بلندترین", "بلندمدت", "بلندند", "پلاستیک", "پلاستیکی", "گسترش", "گسترده", "می‌مالند", "سرسیلندر", "سیلندر"} WORD = re.compile(r"[\u0600-\u06FF\u200c]+") ODD = re.compile(r"[ऀ-ॿ぀-ヿ㐀-鿿가-힯" r"Ѐ-ӿ]") HUMAN_TITLE = re.compile(r"عنوان (مدیر غرفه|همکارم)") def norm(text): """Arabic letter forms -> Persian, so «ريبان» matches «ریبان».""" return text.replace("ي", "ی").replace("ك", "ک").replace("ى", "ی") def own_use_key(cid, line, start, end): """codename with one word of context on each side, for the review list.""" before = WORD.findall(line[:start])[-1:] or [""] after = WORD.findall(line[end:])[:1] or [""] return f"{cid}|{before[0]}|{line[start:end]}|{after[0]}" def phrase_free(line, phrases): """The line with the case's full shop/owner names (and «غرفه X» style mentions of them) blanked out.""" for ph in sorted(filter(None, phrases), key=len, reverse=True): line = line.replace(ph, " ") return line def strings(x, path=()): if isinstance(x, str): yield path, norm(x) elif isinstance(x, dict): for k, v in x.items(): yield from strings(v, path + (k,)) elif isinstance(x, list): for i, v in enumerate(x): yield from strings(v, path + (i,)) def main() -> int: path = os.path.join(ROOT, "dataset", "cases.jsonl") problems = [] ids = set() whole = 0 reviewed = set(_CN.get("reviewed_own_uses", [])) unreviewed = [] # «سلام X عزیز», «X جان», «خانم/آقای X» with X not a made-up codename greet = re.compile(r"(?:سلام|ممنون|مرسی)\s+(\S+(?:\s\S+)?)\s+(?:عزیز|جان)" r"|(?:خانم|آقای)\s+(\S+)" r"|(?:^|[\s،,.!؟])(\S+)\s+جان(?![\u0600-\u06FF])") honor = re.compile(r"(?:استاد|جناب|دکتر|حاج|حاجی|مهندس)\s+(\S+)") phone = re.compile(r"(?