#!/usr/bin/env python3
"""Bank batch-264: Rule 222 second insect-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-264"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
PROCESS_LOG = "process_logs/batch-264-second-insect-reference-lexical-expansion-after-rule221-process.md"

TARGET_HEADS = {
    "kira-kira": "black ant",
    "kandal": "maggot",
    "kinga": "caterpillar",
    "mulma": "hornet",
    "biringal": "scorpion",
    "birinjil": "centipede",
    "kurrmbal": "cicada",
    "nganjamu": "worm",
    "kurran": "grub",
    "ngirran": "beetle",
}
SUPPORT = {"yinya", "yaluy", "yinyay"}
DENY_KUKU = {
    # Rule 212 insect targets.
    "balarr", "dijaraban", "kalburiji", "mawal", "munudumbun", "munyurri",
    "nakawarra", "ngalmnbu", "yarrka", "yiljun",
    # Rejected insect/small-creature candidates.
    "dabadaba", "kuran", "kurrmaja", "nyirran", "yangka", "dabu", "wunba",
    "karrkil", "murma", "wurrbu", "kuja", "nyumbil", "walarr", "malal",
    "walbul-walbul", "kuru", "bikarrakal", "ngunyin", "dujandujan", "kalkamal",
    "jiljay", "jingka-jingka", "jawurraji", "mujurr", "jungu-jungu",
    # Recent bird, reptile/amphibian, mammal, and fish targets.
    "bajal", "jiwurrmal", "jangkan", "karunkurr", "jurriyan", "kuludu", "kurrbal",
    "jaka", "kalkuy", "wakuka", "bajuy", "bilngkumu", "binanjal", "bindimu",
    "bubal", "jijirrbay", "kabul", "kalajarr", "kundurr", "yuday", "bala", "darrba",
    "jarrabina", "jayju", "jungarr", "kukur", "mali", "murramu", "ngumbi", "yawa",
    "baban", "bububay", "ngalkun", "walkan", "barrbal", "jalkay", "janbal", "jijirr",
    "kurrubal", "murraja",
}
DENY_ENGLISH = (
    "bite", "biting", "bitten", "sting", "stinging", "stung", "sick", "sickness",
    "vomit", "vomiting", "medicine", "remedy", "treatment", "cure", "cold", "chest",
    "honey", "nest", "nests", "egg", "eggs", "larva", "larvae", "pupa", "pupae",
    "food", "edible", "eat", "eating", "bait", "collect", "collecting", "season",
    "seasonal", "signal", "time", "antbed", "ant bed", "ant hill", "body-part",
    "body", "tree", "wood", "mountain", "mountains", "habitat", "ecology", "pest",
    "totem", "moiety", "story", "life force", "web", "spider web", "spider", "leech",
    "coolibah", "messmate", "mangrove", "stingray", "flying fish", "medicine",
    "support inflection", "plural", "many",
)


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 = {
    "kira-kira": "Dictionary kira-kira noun 'black ant'; commentary notes lexicalized reduplicated headword distinct from kira 'baby girl'. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "kandal": "Dictionary kandal noun 'maggot'. Fly-larva explanation not opened as event/source prose. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "kinga": "Dictionary kinga noun 'caterpillar'. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "mulma": "Dictionary mulma noun 'hornet'. Sting/nest/danger prose not opened. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "biringal": "Dictionary/grammar-backed biringal noun 'scorpion'; commentary cites Patz example 356. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "birinjil": "Dictionary birinjil noun 'centipede'. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "kurrmbal": "Dictionary kurrmbal noun 'cicada' with locust variant; variant not opened. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "nganjamu": "Dictionary nganjamu noun 'worm'. Bait/soil/use prose not opened. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "kurran": "Dictionary kurran noun 'grub' / kind of grub. Food/wood/habitat prose not opened. Patz section 3.1 fauna noun and section 3.7 deictic support.",
    "ngirran": "Dictionary ngirran noun 'beetle'; adult-from-mujurr note stays lexical only. Patz section 3.1 fauna noun and section 3.7 deictic support.",
}


ROWS = [
    row(1, "The black ant is here.", "Kira-kira yaluy.", "kira-kira yaluy | black.ant here", "r222_insect_ref_here_kira_kira", ["kira-kira", "yaluy"], EVIDENCE["kira-kira"]),
    row(2, "The maggot is here.", "Kandal yaluy.", "kandal yaluy | maggot here", "r222_insect_ref_here_kandal", ["kandal", "yaluy"], EVIDENCE["kandal"]),
    row(3, "The caterpillar is here.", "Kinga yaluy.", "kinga yaluy | caterpillar here", "r222_insect_ref_here_kinga", ["kinga", "yaluy"], EVIDENCE["kinga"]),
    row(4, "The hornet is here.", "Mulma yaluy.", "mulma yaluy | hornet here", "r222_insect_ref_here_mulma", ["mulma", "yaluy"], EVIDENCE["mulma"]),
    row(5, "The scorpion is here.", "Biringal yaluy.", "biringal yaluy | scorpion here", "r222_insect_ref_here_biringal", ["biringal", "yaluy"], EVIDENCE["biringal"]),
    row(6, "The centipede is here.", "Birinjil yaluy.", "birinjil yaluy | centipede here", "r222_insect_ref_here_birinjil", ["birinjil", "yaluy"], EVIDENCE["birinjil"]),
    row(7, "The cicada is here.", "Kurrmbal yaluy.", "kurrmbal yaluy | cicada here", "r222_insect_ref_here_kurrmbal", ["kurrmbal", "yaluy"], EVIDENCE["kurrmbal"]),
    row(8, "The worm is here.", "Nganjamu yaluy.", "nganjamu yaluy | worm here", "r222_insect_ref_here_nganjamu", ["nganjamu", "yaluy"], EVIDENCE["nganjamu"]),
    row(9, "The grub is here.", "Kurran yaluy.", "kurran yaluy | grub here", "r222_insect_ref_here_kurran", ["kurran", "yaluy"], EVIDENCE["kurran"]),
    row(10, "The beetle is here.", "Ngirran yaluy.", "ngirran yaluy | beetle here", "r222_insect_ref_here_ngirran", ["ngirran", "yaluy"], EVIDENCE["ngirran"]),
    row(11, "The black ant is there.", "Kira-kira yinyay.", "kira-kira yinyay | black.ant there", "r222_insect_ref_there_kira_kira", ["kira-kira", "yinyay"], EVIDENCE["kira-kira"]),
    row(12, "The maggot is there.", "Kandal yinyay.", "kandal yinyay | maggot there", "r222_insect_ref_there_kandal", ["kandal", "yinyay"], EVIDENCE["kandal"]),
    row(13, "The caterpillar is there.", "Kinga yinyay.", "kinga yinyay | caterpillar there", "r222_insect_ref_there_kinga", ["kinga", "yinyay"], EVIDENCE["kinga"]),
    row(14, "The hornet is there.", "Mulma yinyay.", "mulma yinyay | hornet there", "r222_insect_ref_there_mulma", ["mulma", "yinyay"], EVIDENCE["mulma"]),
    row(15, "The scorpion is there.", "Biringal yinyay.", "biringal yinyay | scorpion there", "r222_insect_ref_there_biringal", ["biringal", "yinyay"], EVIDENCE["biringal"]),
    row(16, "The centipede is there.", "Birinjil yinyay.", "birinjil yinyay | centipede there", "r222_insect_ref_there_birinjil", ["birinjil", "yinyay"], EVIDENCE["birinjil"]),
    row(17, "The cicada is there.", "Kurrmbal yinyay.", "kurrmbal yinyay | cicada there", "r222_insect_ref_there_kurrmbal", ["kurrmbal", "yinyay"], EVIDENCE["kurrmbal"]),
    row(18, "The worm is there.", "Nganjamu yinyay.", "nganjamu yinyay | worm there", "r222_insect_ref_there_nganjamu", ["nganjamu", "yinyay"], EVIDENCE["nganjamu"]),
    row(19, "The grub is there.", "Kurran yinyay.", "kurran yinyay | grub there", "r222_insect_ref_there_kurran", ["kurran", "yinyay"], EVIDENCE["kurran"]),
    row(20, "The beetle is there.", "Ngirran yinyay.", "ngirran yinyay | beetle there", "r222_insect_ref_there_ngirran", ["ngirran", "yinyay"], EVIDENCE["ngirran"]),
    row(21, "That black ant is there.", "Yinya kira-kira yinyay.", "yinya kira-kira yinyay | that black.ant there", "r222_that_insect_ref_there_kira_kira", ["yinya", "kira-kira", "yinyay"], EVIDENCE["kira-kira"]),
    row(22, "That maggot is there.", "Yinya kandal yinyay.", "yinya kandal yinyay | that maggot there", "r222_that_insect_ref_there_kandal", ["yinya", "kandal", "yinyay"], EVIDENCE["kandal"]),
    row(23, "That caterpillar is there.", "Yinya kinga yinyay.", "yinya kinga yinyay | that caterpillar there", "r222_that_insect_ref_there_kinga", ["yinya", "kinga", "yinyay"], EVIDENCE["kinga"]),
    row(24, "That hornet is there.", "Yinya mulma yinyay.", "yinya mulma yinyay | that hornet there", "r222_that_insect_ref_there_mulma", ["yinya", "mulma", "yinyay"], EVIDENCE["mulma"]),
    row(25, "That scorpion is there.", "Yinya biringal yinyay.", "yinya biringal yinyay | that scorpion there", "r222_that_insect_ref_there_biringal", ["yinya", "biringal", "yinyay"], EVIDENCE["biringal"]),
    row(26, "That centipede is there.", "Yinya birinjil yinyay.", "yinya birinjil yinyay | that centipede there", "r222_that_insect_ref_there_birinjil", ["yinya", "birinjil", "yinyay"], EVIDENCE["birinjil"]),
    row(27, "That cicada is there.", "Yinya kurrmbal yinyay.", "yinya kurrmbal yinyay | that cicada there", "r222_that_insect_ref_there_kurrmbal", ["yinya", "kurrmbal", "yinyay"], EVIDENCE["kurrmbal"]),
    row(28, "That worm is there.", "Yinya nganjamu yinyay.", "yinya nganjamu yinyay | that worm there", "r222_that_insect_ref_there_nganjamu", ["yinya", "nganjamu", "yinyay"], EVIDENCE["nganjamu"]),
    row(29, "That grub is there.", "Yinya kurran yinyay.", "yinya kurran yinyay | that grub there", "r222_that_insect_ref_there_kurran", ["yinya", "kurran", "yinyay"], EVIDENCE["kurran"]),
    row(30, "That beetle is there.", "Yinya ngirran yinyay.", "yinya ngirran yinyay | that beetle there", "r222_that_insect_ref_there_ngirran", ["yinya", "ngirran", "yinyay"], EVIDENCE["ngirran"]),
    row(31, "That black ant is there.", "Kira-kira yinya yinyay.", "kira-kira yinya yinyay | that black.ant there", "r222_insect_that_there_kira_kira", ["kira-kira", "yinya", "yinyay"], EVIDENCE["kira-kira"]),
    row(32, "That maggot is there.", "Kandal yinya yinyay.", "kandal yinya yinyay | that maggot there", "r222_insect_that_there_kandal", ["kandal", "yinya", "yinyay"], EVIDENCE["kandal"]),
    row(33, "That caterpillar is there.", "Kinga yinya yinyay.", "kinga yinya yinyay | that caterpillar there", "r222_insect_that_there_kinga", ["kinga", "yinya", "yinyay"], EVIDENCE["kinga"]),
    row(34, "That hornet is there.", "Mulma yinya yinyay.", "mulma yinya yinyay | that hornet there", "r222_insect_that_there_mulma", ["mulma", "yinya", "yinyay"], EVIDENCE["mulma"]),
    row(35, "That scorpion is there.", "Biringal yinya yinyay.", "biringal yinya yinyay | that scorpion there", "r222_insect_that_there_biringal", ["biringal", "yinya", "yinyay"], EVIDENCE["biringal"]),
    row(36, "That centipede is there.", "Birinjil yinya yinyay.", "birinjil yinya yinyay | that centipede there", "r222_insect_that_there_birinjil", ["birinjil", "yinya", "yinyay"], EVIDENCE["birinjil"]),
    row(37, "That cicada is there.", "Kurrmbal yinya yinyay.", "kurrmbal yinya yinyay | that cicada there", "r222_insect_that_there_kurrmbal", ["kurrmbal", "yinya", "yinyay"], EVIDENCE["kurrmbal"]),
    row(38, "That worm is there.", "Nganjamu yinya yinyay.", "nganjamu yinya yinyay | that worm there", "r222_insect_that_there_nganjamu", ["nganjamu", "yinya", "yinyay"], EVIDENCE["nganjamu"]),
    row(39, "That grub is there.", "Kurran yinya yinyay.", "kurran yinya yinyay | that grub there", "r222_insect_that_there_kurran", ["kurran", "yinya", "yinyay"], EVIDENCE["kurran"]),
    row(40, "That beetle is there.", "Ngirran yinya yinyay.", "ngirran yinya yinyay | that beetle there", "r222_insect_that_there_ngirran", ["ngirran", "yinya", "yinyay"], EVIDENCE["ngirran"]),
    row(41, "That black ant is here.", "Yinya kira-kira yaluy.", "yinya kira-kira yaluy | that black.ant here", "r222_that_insect_ref_here_kira_kira", ["yinya", "kira-kira", "yaluy"], EVIDENCE["kira-kira"]),
    row(42, "That maggot is here.", "Yinya kandal yaluy.", "yinya kandal yaluy | that maggot here", "r222_that_insect_ref_here_kandal", ["yinya", "kandal", "yaluy"], EVIDENCE["kandal"]),
    row(43, "That caterpillar is here.", "Yinya kinga yaluy.", "yinya kinga yaluy | that caterpillar here", "r222_that_insect_ref_here_kinga", ["yinya", "kinga", "yaluy"], EVIDENCE["kinga"]),
    row(44, "That hornet is here.", "Yinya mulma yaluy.", "yinya mulma yaluy | that hornet here", "r222_that_insect_ref_here_mulma", ["yinya", "mulma", "yaluy"], EVIDENCE["mulma"]),
    row(45, "That scorpion is here.", "Yinya biringal yaluy.", "yinya biringal yaluy | that scorpion here", "r222_that_insect_ref_here_biringal", ["yinya", "biringal", "yaluy"], EVIDENCE["biringal"]),
    row(46, "That centipede is here.", "Yinya birinjil yaluy.", "yinya birinjil yaluy | that centipede here", "r222_that_insect_ref_here_birinjil", ["yinya", "birinjil", "yaluy"], EVIDENCE["birinjil"]),
    row(47, "That cicada is here.", "Yinya kurrmbal yaluy.", "yinya kurrmbal yaluy | that cicada here", "r222_that_insect_ref_here_kurrmbal", ["yinya", "kurrmbal", "yaluy"], EVIDENCE["kurrmbal"]),
    row(48, "That worm is here.", "Yinya nganjamu yaluy.", "yinya nganjamu yaluy | that worm here", "r222_that_insect_ref_here_nganjamu", ["yinya", "nganjamu", "yaluy"], EVIDENCE["nganjamu"]),
    row(49, "That grub is here.", "Yinya kurran yaluy.", "yinya kurran yaluy | that grub here", "r222_that_insect_ref_here_kurran", ["yinya", "kurran", "yaluy"], EVIDENCE["kurran"]),
    row(50, "That beetle is here.", "Yinya ngirran yaluy.", "yinya ngirran yaluy | that beetle here", "r222_that_insect_ref_here_ngirran", ["yinya", "ngirran", "yaluy"], EVIDENCE["ngirran"]),
]


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"
    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("r222_"):
            issues.append(f"{label}: Rule 222 frame must start with r222_")
        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 222")
        for denied in DENY_KUKU:
            if has_token(low, denied):
                issues.append(f"{label}: denied carry-forward 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 222 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 insect behavior/use/habitat/event/polysemy 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 222 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 noun/fauna basis, Patz section 3.7 yinya/yaluy/yinyay support, earlier Rule 212 insect rows, and dictionary/grammar entries for kira-kira, kandal, kinga, mulma, biringal, birinjil, kurrmbal, nganjamu, kurran, and ngirran. Admitted only selected bare insect-reference labels.",
        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 second insect-reference field after excluding earlier Rule 212 exact target heads, food/egg/honey/medicine-heavy entries, bite/sting/sickness/nest-heavy entries, homograph/material/story/body entries, unhyphenated-reduplication pressure, seasonal/event-signal entries, and all source-prose event semantics.",
        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 222 Kuku surfaces returned no accepted, revised, or under-review collisions.",
        artifact_path="batch_scripts/bank_264.py",
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="preflight",
        event_type="static-guard-pass",
        actor="claude-main",
        detail="bank_264.py static guards passed: 50 explicit hand-authored rows, exactly one insect-reference target noun per row, no loans, no target morphology, no insect behavior/use/habitat/event/polysemy English, and only the five sourced deictic frame bands.",
        artifact_path="batch_scripts/bank_264.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())
