#!/usr/bin/env python3
"""Bank batch-270: Rule 228 third kin-reference lexical expansion."""

from __future__ import annotations

import datetime as dt
import json
import re
import sqlite3

from process_ledger import ensure_schema, record_event

DB = "/mnt/donto-data/donto-resources/research/translation-training/kuku-yalanji-runpod-2026-06-30/synthetic/claude-synthetic-v1-2026-07-02/synthetic.db"
LABEL = "batch-270"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
PROCESS_LOG = "process_logs/batch-270-third-kin-reference-lexical-expansion-after-rule227-process.md"

TARGET_HEADS = {
    "jinkurr": "younger sister",
    "mukay": "mother's older sister",
    "biwar": "wife",
    "kuban": "wife",
    "manyarr": "wife",
    "ngalayin": "father-in-law",
    "banji": "brother-in-law",
    "warrin": "sister-in-law",
    "bangunji": "cousin",
    "kambanmu": "cross-cousin",
}
SUPPORT = {"yinya", "yaluy", "yinyay"}
DENY_KUKU = {
    # Rule 157 human/kin targets.
    "bama", "dingkar", "jalbu", "karrkay", "ngamu", "nganjan", "jawun", "dunyu",
    "warru", "wulman",
    # Rule 159 extended-kin targets.
    "babi", "kami", "kalnga", "bimakay", "ngaji", "jija", "kaminjarr", "kangkal",
    "yaba", "babarr",
    # Rejected/deferred kin candidates.
    "biwul", "ngalba", "manda", "mandi", "ngujurr", "kubananji", "manyarrinyu",
    "ngaybirr", "mukul",
}
DENY_ENGLISH = (
    "my ", "your ", "his ", "her ", "their ", "owner", "possession", "possessive",
    "plural", "mothers and fathers", "parents", "pair", "dyad", "marry", "married",
    "marriage", "husband and wife", "couple", "avoid", "avoidance", "taboo", "name taboo",
    "dead", "death", "deceased", "moiety", "tribe", "section", "speak", "talk", "call",
    "address", "ask", "teach", "tell", "food", "work", "travel", "go", "came", "conflict",
    "fight", "ceremony", "corroboree", "social law", "custom", "behavior", "behaviour", "actual relationship",
    "old people", "restricted", "speaker sex", "speaker-sex",
)


def js(values: list[str]) -> str:
    return json.dumps(values, ensure_ascii=False)


def row(
    seq: int,
    english: str,
    kuku: str,
    analysis: str,
    frame: str,
    words: list[str],
    evidence: str,
) -> tuple:
    return (seq, english, kuku, analysis, frame, 2, js(words), js([]), evidence, "0.86")


EVIDENCE = {
    "jinkurr": "Dictionary jinkurr noun 'younger sister, relationship term'. Patz section 3.1 includes kinship terms among nouns; section 3.7 supports yinya/yaluy/yinyay.",
    "mukay": "Dictionary mukay noun 'mother's older sister, father's older brother'; batch uses mother's-older-sister reference only. Patz section 3.1 kin noun and section 3.7 deictic support.",
    "biwar": "Dictionary biwar noun 'wife'. Patz section 3.1 kin noun and section 3.7 deictic support; no marriage-event row.",
    "kuban": "Dictionary kuban noun 'wife', synonym manyarr. Patz section 3.1 kin noun and section 3.7 deictic support; no married-man row.",
    "manyarr": "Dictionary manyarr noun 'wife'. Patz section 3.1 kin noun and section 3.7 deictic support; couple noun manyarrinyu stays closed.",
    "ngalayin": "Dictionary ngalayin noun 'father-in-law, son-in-law'; batch uses father-in-law reference only. Patz section 3.1 kin noun and section 3.7 deictic support.",
    "banji": "Dictionary banji noun 'brother-in-law or sister-in-law'; batch uses brother-in-law reference only. Patz section 3.1 kin noun and section 3.7 deictic support.",
    "warrin": "Dictionary warrin noun 'sister-in-law or brother-in-law'; batch uses sister-in-law reference only. Patz section 3.1 kin noun and section 3.7 deictic support.",
    "bangunji": "Dictionary bangunji noun 'cousin, full blood cousin'. Patz section 3.1 kin noun and section 3.7 deictic support.",
    "kambanmu": "Dictionary kambanmu noun 'cross-cousin', children of mother's brother or father's sister. Patz section 3.1 kin noun and section 3.7 deictic support.",
}


ROWS = [
    row(1, "The younger sister is here.", "Jinkurr yaluy.", "jinkurr yaluy | younger.sister here", "r228_kin_ref_here_jinkurr", ["jinkurr", "yaluy"], EVIDENCE["jinkurr"]),
    row(2, "The mother's older sister is here.", "Mukay yaluy.", "mukay yaluy | mother's.older.sister here", "r228_kin_ref_here_mukay", ["mukay", "yaluy"], EVIDENCE["mukay"]),
    row(3, "The wife is here.", "Biwar yaluy.", "biwar yaluy | wife here", "r228_kin_ref_here_biwar", ["biwar", "yaluy"], EVIDENCE["biwar"]),
    row(4, "The wife is here.", "Kuban yaluy.", "kuban yaluy | wife here", "r228_kin_ref_here_kuban", ["kuban", "yaluy"], EVIDENCE["kuban"]),
    row(5, "The wife is here.", "Manyarr yaluy.", "manyarr yaluy | wife here", "r228_kin_ref_here_manyarr", ["manyarr", "yaluy"], EVIDENCE["manyarr"]),
    row(6, "The father-in-law is here.", "Ngalayin yaluy.", "ngalayin yaluy | father.in.law here", "r228_kin_ref_here_ngalayin", ["ngalayin", "yaluy"], EVIDENCE["ngalayin"]),
    row(7, "The brother-in-law is here.", "Banji yaluy.", "banji yaluy | brother.in.law here", "r228_kin_ref_here_banji", ["banji", "yaluy"], EVIDENCE["banji"]),
    row(8, "The sister-in-law is here.", "Warrin yaluy.", "warrin yaluy | sister.in.law here", "r228_kin_ref_here_warrin", ["warrin", "yaluy"], EVIDENCE["warrin"]),
    row(9, "The cousin is here.", "Bangunji yaluy.", "bangunji yaluy | cousin here", "r228_kin_ref_here_bangunji", ["bangunji", "yaluy"], EVIDENCE["bangunji"]),
    row(10, "The cross-cousin is here.", "Kambanmu yaluy.", "kambanmu yaluy | cross.cousin here", "r228_kin_ref_here_kambanmu", ["kambanmu", "yaluy"], EVIDENCE["kambanmu"]),
    row(11, "The younger sister is there.", "Jinkurr yinyay.", "jinkurr yinyay | younger.sister there", "r228_kin_ref_there_jinkurr", ["jinkurr", "yinyay"], EVIDENCE["jinkurr"]),
    row(12, "The mother's older sister is there.", "Mukay yinyay.", "mukay yinyay | mother's.older.sister there", "r228_kin_ref_there_mukay", ["mukay", "yinyay"], EVIDENCE["mukay"]),
    row(13, "The wife is there.", "Biwar yinyay.", "biwar yinyay | wife there", "r228_kin_ref_there_biwar", ["biwar", "yinyay"], EVIDENCE["biwar"]),
    row(14, "The wife is there.", "Kuban yinyay.", "kuban yinyay | wife there", "r228_kin_ref_there_kuban", ["kuban", "yinyay"], EVIDENCE["kuban"]),
    row(15, "The wife is there.", "Manyarr yinyay.", "manyarr yinyay | wife there", "r228_kin_ref_there_manyarr", ["manyarr", "yinyay"], EVIDENCE["manyarr"]),
    row(16, "The father-in-law is there.", "Ngalayin yinyay.", "ngalayin yinyay | father.in.law there", "r228_kin_ref_there_ngalayin", ["ngalayin", "yinyay"], EVIDENCE["ngalayin"]),
    row(17, "The brother-in-law is there.", "Banji yinyay.", "banji yinyay | brother.in.law there", "r228_kin_ref_there_banji", ["banji", "yinyay"], EVIDENCE["banji"]),
    row(18, "The sister-in-law is there.", "Warrin yinyay.", "warrin yinyay | sister.in.law there", "r228_kin_ref_there_warrin", ["warrin", "yinyay"], EVIDENCE["warrin"]),
    row(19, "The cousin is there.", "Bangunji yinyay.", "bangunji yinyay | cousin there", "r228_kin_ref_there_bangunji", ["bangunji", "yinyay"], EVIDENCE["bangunji"]),
    row(20, "The cross-cousin is there.", "Kambanmu yinyay.", "kambanmu yinyay | cross.cousin there", "r228_kin_ref_there_kambanmu", ["kambanmu", "yinyay"], EVIDENCE["kambanmu"]),
    row(21, "That younger sister is there.", "Yinya jinkurr yinyay.", "yinya jinkurr yinyay | that younger.sister there", "r228_that_kin_ref_there_jinkurr", ["yinya", "jinkurr", "yinyay"], EVIDENCE["jinkurr"]),
    row(22, "That mother's older sister is there.", "Yinya mukay yinyay.", "yinya mukay yinyay | that mother's.older.sister there", "r228_that_kin_ref_there_mukay", ["yinya", "mukay", "yinyay"], EVIDENCE["mukay"]),
    row(23, "That wife is there.", "Yinya biwar yinyay.", "yinya biwar yinyay | that wife there", "r228_that_kin_ref_there_biwar", ["yinya", "biwar", "yinyay"], EVIDENCE["biwar"]),
    row(24, "That wife is there.", "Yinya kuban yinyay.", "yinya kuban yinyay | that wife there", "r228_that_kin_ref_there_kuban", ["yinya", "kuban", "yinyay"], EVIDENCE["kuban"]),
    row(25, "That wife is there.", "Yinya manyarr yinyay.", "yinya manyarr yinyay | that wife there", "r228_that_kin_ref_there_manyarr", ["yinya", "manyarr", "yinyay"], EVIDENCE["manyarr"]),
    row(26, "That father-in-law is there.", "Yinya ngalayin yinyay.", "yinya ngalayin yinyay | that father.in.law there", "r228_that_kin_ref_there_ngalayin", ["yinya", "ngalayin", "yinyay"], EVIDENCE["ngalayin"]),
    row(27, "That brother-in-law is there.", "Yinya banji yinyay.", "yinya banji yinyay | that brother.in.law there", "r228_that_kin_ref_there_banji", ["yinya", "banji", "yinyay"], EVIDENCE["banji"]),
    row(28, "That sister-in-law is there.", "Yinya warrin yinyay.", "yinya warrin yinyay | that sister.in.law there", "r228_that_kin_ref_there_warrin", ["yinya", "warrin", "yinyay"], EVIDENCE["warrin"]),
    row(29, "That cousin is there.", "Yinya bangunji yinyay.", "yinya bangunji yinyay | that cousin there", "r228_that_kin_ref_there_bangunji", ["yinya", "bangunji", "yinyay"], EVIDENCE["bangunji"]),
    row(30, "That cross-cousin is there.", "Yinya kambanmu yinyay.", "yinya kambanmu yinyay | that cross.cousin there", "r228_that_kin_ref_there_kambanmu", ["yinya", "kambanmu", "yinyay"], EVIDENCE["kambanmu"]),
    row(31, "That younger sister is there.", "Jinkurr yinya yinyay.", "jinkurr yinya yinyay | that younger.sister there", "r228_kin_that_there_jinkurr", ["jinkurr", "yinya", "yinyay"], EVIDENCE["jinkurr"]),
    row(32, "That mother's older sister is there.", "Mukay yinya yinyay.", "mukay yinya yinyay | that mother's.older.sister there", "r228_kin_that_there_mukay", ["mukay", "yinya", "yinyay"], EVIDENCE["mukay"]),
    row(33, "That wife is there.", "Biwar yinya yinyay.", "biwar yinya yinyay | that wife there", "r228_kin_that_there_biwar", ["biwar", "yinya", "yinyay"], EVIDENCE["biwar"]),
    row(34, "That wife is there.", "Kuban yinya yinyay.", "kuban yinya yinyay | that wife there", "r228_kin_that_there_kuban", ["kuban", "yinya", "yinyay"], EVIDENCE["kuban"]),
    row(35, "That wife is there.", "Manyarr yinya yinyay.", "manyarr yinya yinyay | that wife there", "r228_kin_that_there_manyarr", ["manyarr", "yinya", "yinyay"], EVIDENCE["manyarr"]),
    row(36, "That father-in-law is there.", "Ngalayin yinya yinyay.", "ngalayin yinya yinyay | that father.in.law there", "r228_kin_that_there_ngalayin", ["ngalayin", "yinya", "yinyay"], EVIDENCE["ngalayin"]),
    row(37, "That brother-in-law is there.", "Banji yinya yinyay.", "banji yinya yinyay | that brother.in.law there", "r228_kin_that_there_banji", ["banji", "yinya", "yinyay"], EVIDENCE["banji"]),
    row(38, "That sister-in-law is there.", "Warrin yinya yinyay.", "warrin yinya yinyay | that sister.in.law there", "r228_kin_that_there_warrin", ["warrin", "yinya", "yinyay"], EVIDENCE["warrin"]),
    row(39, "That cousin is there.", "Bangunji yinya yinyay.", "bangunji yinya yinyay | that cousin there", "r228_kin_that_there_bangunji", ["bangunji", "yinya", "yinyay"], EVIDENCE["bangunji"]),
    row(40, "That cross-cousin is there.", "Kambanmu yinya yinyay.", "kambanmu yinya yinyay | that cross.cousin there", "r228_kin_that_there_kambanmu", ["kambanmu", "yinya", "yinyay"], EVIDENCE["kambanmu"]),
    row(41, "That younger sister is here.", "Yinya jinkurr yaluy.", "yinya jinkurr yaluy | that younger.sister here", "r228_that_kin_ref_here_jinkurr", ["yinya", "jinkurr", "yaluy"], EVIDENCE["jinkurr"]),
    row(42, "That mother's older sister is here.", "Yinya mukay yaluy.", "yinya mukay yaluy | that mother's.older.sister here", "r228_that_kin_ref_here_mukay", ["yinya", "mukay", "yaluy"], EVIDENCE["mukay"]),
    row(43, "That wife is here.", "Yinya biwar yaluy.", "yinya biwar yaluy | that wife here", "r228_that_kin_ref_here_biwar", ["yinya", "biwar", "yaluy"], EVIDENCE["biwar"]),
    row(44, "That wife is here.", "Yinya kuban yaluy.", "yinya kuban yaluy | that wife here", "r228_that_kin_ref_here_kuban", ["yinya", "kuban", "yaluy"], EVIDENCE["kuban"]),
    row(45, "That wife is here.", "Yinya manyarr yaluy.", "yinya manyarr yaluy | that wife here", "r228_that_kin_ref_here_manyarr", ["yinya", "manyarr", "yaluy"], EVIDENCE["manyarr"]),
    row(46, "That father-in-law is here.", "Yinya ngalayin yaluy.", "yinya ngalayin yaluy | that father.in.law here", "r228_that_kin_ref_here_ngalayin", ["yinya", "ngalayin", "yaluy"], EVIDENCE["ngalayin"]),
    row(47, "That brother-in-law is here.", "Yinya banji yaluy.", "yinya banji yaluy | that brother.in.law here", "r228_that_kin_ref_here_banji", ["yinya", "banji", "yaluy"], EVIDENCE["banji"]),
    row(48, "That sister-in-law is here.", "Yinya warrin yaluy.", "yinya warrin yaluy | that sister.in.law here", "r228_that_kin_ref_here_warrin", ["yinya", "warrin", "yaluy"], EVIDENCE["warrin"]),
    row(49, "That cousin is here.", "Yinya bangunji yaluy.", "yinya bangunji yaluy | that cousin here", "r228_that_kin_ref_here_bangunji", ["yinya", "bangunji", "yaluy"], EVIDENCE["bangunji"]),
    row(50, "That cross-cousin is here.", "Yinya kambanmu yaluy.", "yinya kambanmu yaluy | that cross.cousin here", "r228_that_kin_ref_here_kambanmu", ["yinya", "kambanmu", "yaluy"], EVIDENCE["kambanmu"]),
]


def has_token(low: str, token: str) -> bool:
    return re.search(rf"(?<![a-z-]){re.escape(token)}(?![a-z-])", low) is not None


def has_target_morphology(low: str, head: str) -> bool:
    suffixes = "ngka|ngku|angka|nga|ngu|ba|mba|mbu|muny|darr|burr|bu|ka|nka|nku|ji|jirr|ku|mundu|amu|mu|iji|nda|ndu|anda|undu|unji|nji|kari|baka|baja|bungal|bungan|mal|man|rriny|karra|manda|bulal"
    return re.search(rf"(?<![a-z-]){re.escape(head)}-(?:{suffixes})\b", low) is not None


def english_has_denied(english_low: str, denied: str) -> bool:
    return denied in english_low if " " in denied else re.search(rf"\b{re.escape(denied.strip())}\b", english_low) is not None


def scan_static() -> list[str]:
    issues: list[str] = []
    if len(ROWS) != 50:
        issues.append(f"{LABEL}: expected 50 rows, found {len(ROWS)}")
    seen_ku: set[str] = set()
    for expected, row_data in enumerate(ROWS, start=1):
        seq, english, kuku, analysis, frame, _tier, words_used, loans_used, evidence, confidence = row_data
        label = f"{LABEL}.{seq:02d}"
        low = kuku.lower()
        english_low = english.lower()
        words = json.loads(words_used)
        if seq != expected:
            issues.append(f"{label}: sequence mismatch; expected {expected}")
        if not english[:1].isupper() or english[-1:] not in ".!?":
            issues.append(f"{label}: English punctuation/capitalization failure")
        if " | " not in analysis:
            issues.append(f"{label}: analysis missing gloss separator")
        if not frame.startswith("r228_"):
            issues.append(f"{label}: Rule 228 frame must start with r228_")
        if low in seen_ku:
            issues.append(f"{label}: duplicate Kuku surface within batch")
        seen_ku.add(low)
        if json.loads(loans_used):
            issues.append(f"{label}: no loans are admitted in Rule 228")
        for denied in DENY_KUKU:
            if has_token(low, denied):
                issues.append(f"{label}: denied carry-forward kin token {denied!r}")
        targets = [head for head in TARGET_HEADS if has_token(low, head)]
        if len(targets) != 1:
            issues.append(f"{label}: expected exactly one Rule 228 target noun, found {targets}")
        for head in targets:
            selected = TARGET_HEADS[head]
            dotted = selected.replace("-", ".").replace(" ", ".")
            if head not in words:
                issues.append(f"{label}: target head {head} missing from words_used")
            if selected not in english_low:
                issues.append(f"{label}: English must include selected sense {selected!r}")
            if selected not in analysis and dotted not in analysis:
                issues.append(f"{label}: analysis must gloss {head} as {selected}")
            if has_target_morphology(low, head):
                issues.append(f"{label}: target head {head} has forbidden morphology")
        for support in SUPPORT:
            if has_token(low, support) and support not in words:
                issues.append(f"{label}: support {support} missing from words_used")
        if 1 <= seq <= 10 and (has_token(low, "yinya") or has_token(low, "yinyay") or not low.endswith(" yaluy.") or len(low.split()) != 2):
            issues.append(f"{label}: rows 1-10 require TARGET yaluy")
        if 11 <= seq <= 20 and (has_token(low, "yinya") or has_token(low, "yaluy") or not low.endswith(" yinyay.") or len(low.split()) != 2):
            issues.append(f"{label}: rows 11-20 require TARGET yinyay")
        if 21 <= seq <= 30 and (not low.startswith("yinya ") or has_token(low, "yaluy") or not low.endswith(" yinyay.") or len(low.split()) != 3):
            issues.append(f"{label}: rows 21-30 require Yinya TARGET yinyay")
        if 31 <= seq <= 40 and (not has_token(low, "yinya") or has_token(low, "yaluy") or not low.endswith(" yinyay.") or len(low.split()) != 3 or low.startswith("yinya ")):
            issues.append(f"{label}: rows 31-40 require TARGET yinya yinyay")
        if 41 <= seq <= 50 and (not low.startswith("yinya ") or has_token(low, "yinyay") or not low.endswith(" yaluy.") or len(low.split()) != 3):
            issues.append(f"{label}: rows 41-50 require Yinya TARGET yaluy")
        if any(english_has_denied(english_low, bad) for bad in DENY_ENGLISH):
            issues.append(f"{label}: denied kin-event/possession/social-law field in English")
        if not evidence or not confidence:
            issues.append(f"{label}: missing evidence/confidence")
    return issues


def main() -> int:
    issues = scan_static()
    if issues:
        print("pre-bank scan failed:")
        for issue in issues:
            print(f"  - {issue}")
        return 1

    db = sqlite3.connect(DB)
    db.execute("PRAGMA foreign_keys = ON")
    db.execute("BEGIN")
    ensure_schema(db)
    existing = db.execute("SELECT id FROM batches WHERE label=?", (LABEL,)).fetchone()
    if existing:
        batch_id = existing[0]
        accepted = db.execute(
            "SELECT COUNT(*) FROM sentences WHERE batch_id=? AND status IN ('accepted','revised')",
            (batch_id,),
        ).fetchone()[0]
        if accepted:
            raise SystemExit(f"{LABEL} already has accepted/revised rows; refusing to overwrite")
        db.execute("DELETE FROM reviews WHERE sentence_id IN (SELECT id FROM sentences WHERE batch_id=?)", (batch_id,))
        db.execute("DELETE FROM sentences WHERE batch_id=?", (batch_id,))
    else:
        db.execute(
            "INSERT INTO batches(label, cheatsheet_version, guide_version, notes, created_at) VALUES(?,?,?,?,?)",
            (LABEL, "Rule 228 draft", "operator-guide-2026-07-08", "draft under review", NOW),
        )
        batch_id = db.execute("SELECT id FROM batches WHERE label=?", (LABEL,)).fetchone()[0]

    collisions: list[str] = []
    for seq, _english, kuku, *_rest in ROWS:
        found = db.execute(
            """
            SELECT b.label, s.seq, s.status
            FROM sentences s JOIN batches b ON b.id=s.batch_id
            WHERE lower(s.kuku)=lower(?) AND s.status IN ('accepted','revised','under_review')
            """,
            (kuku,),
        ).fetchall()
        if found:
            collisions.append(f"{seq:02d} {kuku}: {found}")
    if collisions:
        raise SystemExit("duplicate preflight failed:\n" + "\n".join(collisions))

    record_event(
        db,
        batch_label=LABEL,
        phase="source",
        event_type="source-pass",
        actor="claude-main",
        detail="Checked Patz section 3.1 kinship-term noun basis, Patz section 3.7 yinya/yaluy/yinyay support, Rules 157-160 human/kin reference law, and dictionary entries for jinkurr, mukay, biwar, kuban, manyarr, ngalayin, banji, warrin, bangunji, and kambanmu.",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="scope",
        event_type="candidate-rejection",
        actor="claude-main",
        detail="Selected a third bounded kin-reference field after excluding Rule 157/159 exact targets, mother-in-law avoidance and black-snake homograph biwul, name-taboo ngalba, moiety mandi, speaker-sex niece/nephew terms manda/ngujurr, couple/married-person terms, restricted spouse register, and adjective mukul.",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="preflight",
        event_type="duplicate-preflight",
        actor="claude-main",
        detail="Exact duplicate preflight over all 50 planned Rule 228 Kuku surfaces returned no accepted, revised, or under-review collisions.",
        command="sqlite3 exact lower(kuku) collision scan for 50 planned surfaces",
        output_excerpt="collisions=0",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="preflight",
        event_type="static-guard-pass",
        actor="claude-main",
        detail="bank_270.py static guards passed: 50 explicit hand-authored rows, exactly one third-kin-reference target noun per row, no loans, no target morphology, no kin possession/plural/dyad/event/social-law English, and only five sourced deictic frame bands.",
        artifact_path="batch_scripts/bank_270.py",
        created_at=NOW,
    )

    db.executemany(
        """
        INSERT INTO sentences(
          batch_id, seq, english, kuku, analysis, frame, tier, words_used,
          loans_used, evidence, status, confidence, created_at, updated_at
        )
        VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
        """,
        [
            (batch_id, seq, english, kuku, analysis, frame, tier, words_used, loans_used, evidence, "under_review", confidence, NOW, NOW)
            for seq, english, kuku, analysis, frame, tier, words_used, loans_used, evidence, confidence in ROWS
        ],
    )
    db.commit()

    n = db.execute("SELECT COUNT(*) FROM sentences WHERE batch_id=? AND status='under_review'", (batch_id,)).fetchone()[0]
    print(f"banked {LABEL}: {n} under_review rows")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
