#!/usr/bin/env python3
"""Bank batch-124: antipassive construction.

Rows are hand-authored in the main loop from Patz §4.2.4.4 and checked
against the current grammar cheatsheet/dictionary errata. The script only
validates and banks the rows as under_review.
"""

from __future__ import annotations

import datetime as dt
import json
import re
import sqlite3
import sys

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-124"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")

DENY = {
    "nyawa", "jinbi", "jibin", "walba", "julmbu", "wanan", "ngampula",
    "yalama", "ngana-jinji", "jubuny", "wural", "bigan", "jiwuny",
    "warngkul", "wanaba", "jarrkunji", "munjal", "murku", "buni",
    "kunya", "milkan", "kulur-jambul", "janyji", "buburr", "jarrmba",
    "jinji", "daga", "wanka", "yumbul", "kuku-yumbul", "jubi",
    "yilbay", "jarrakay", "janka-yukil", "jukarr", "kunkul",
    "bubu-jandu", "bubu-warral", "jani-warra", "dungkarr", "jimba",
    "bujal", "wanyjarr", "ngudan", "jimirr", "jangan", "ganggal",
    "bukul", "jalany", "nyunun", "yinkar", "jiba", "bibi",
}


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


ROWS = [
    (1, "The old man had a good feed of meat, and then he slept in the shade.",
     "Mukul-dingkar minya-nga nuka-jin, wabarr-ba wunan.",
     "mukul-dingkar minya-nga nuka-ji-ny, wabarr-ba wuna-ny | old-man meat-LOC eat-APASS-PAST, shade-LOC lie-PAST",
     "antipassive_total_effect", 4, js(["mukul-dingkar", "minya", "nukal", "wabarr", "wunay"]),
     "Patz §4.2.4.4 ex.365b/385: A as S, object in LOC, simple nuka-ji-ny = full/good feed.", "0.86"),
    (2, "Mother shared out all the food at the camp.",
     "Ngamu mayi-nga wambi-jin bayan-ba.",
     "ngamu mayi-nga wambi-ji-ny bayan-ba | mother food-LOC share.out-APASS-PAST camp-LOC",
     "antipassive_total_effect", 4, js(["ngamu", "mayi", "wambil", "bayan"]),
     "Patz ex.374: Ngamu mayi-nga wambi-ji-ny 'Mother shared out all the food'.", "0.87"),
    (3, "Grandmother shared out the yams, and the children ate.",
     "Babi wukay-mba wambi-jin, karrkay-karrkay nukan.",
     "babi wukay-mba wambi-ji-ny, karrkay-karrkay nuka-ny | grandmother yam-LOC share.out-APASS-PAST, child-REDUP eat-PAST",
     "antipassive_total_effect", 4, js(["babi", "wukay", "wambil", "karrkay", "nukal"]),
     "Antipassive object in LOC; wukay y-final LOC = -mba (Rule 21d).", "0.84"),
    (4, "The woman took over my house completely.",
     "Jalbu ngayku-wun-bu bayan-ba ngunja-jin.",
     "jalbu ngayku-wun-bu bayan-ba ngunja-ji-ny | woman I-POSS-LOC house-LOC take.over-APASS-PAST",
     "antipassive_total_effect", 4, js(["jalbu", "ngayu", "bayan", "ngunjal"]),
     "Patz ex.375: jalbu ngayku-wun-bu bayan-ba ngunja-ji-ny 'took over my house lock stock and barrel'.", "0.86"),
    (5, "The dog was foraging through the food near the fire.",
     "Kaya mayi-burr ngunja-n-ngunja-ji baya ngundu-ba.",
     "kaya mayi-burr ngunja-n-ngunja-ji-y baya ngundu-ba | dog food-PERL forage-REDUP-APASS-NONPAST fire near-LOC",
     "antipassive_generalized_perlative", 4, js(["kaya", "mayi", "ngunjal", "baya", "ngundu"]),
     "Patz ex.372: mayi-burr ngunja-n-ngunja-ji-y; PERL expresses 'through' in Nyungkul.", "0.84"),
    (6, "The children keep eating at the food all day.",
     "Karrkay-karrkay mayi-nga nuka-n-nuka-ji wungar wubulku.",
     "karrkay-karrkay mayi-nga nuka-n-nuka-ji-y wungar wubul-ku | child-REDUP food-LOC eat-REDUP-APASS-NONPAST day all-EMPH",
     "antipassive_generalized", 4, js(["karrkay", "mayi", "nukal", "wungar", "wubul"]),
     "Patz l.971 and text line 39/48: reduplicated nuka-ji for ongoing/generalized eating.", "0.84"),
    (7, "The men keep spearing around for fish at the river.",
     "Dingkar-dingkar kuyu-ngu dama-n-dama-ji wawubaja-nga.",
     "dingkar-dingkar kuyu-ngu dama-n-dama-ji-y wawubaja-nga | man-REDUP fish-LOC spear-REDUP-APASS-NONPAST river-LOC",
     "antipassive_generalized", 4, js(["dingkar", "kuyu", "damal", "wawubaja"]),
     "Generalized antipassive modelled on Patz ex.366-368; kuyu u-final LOC = -ngu.", "0.84"),
    (8, "The old woman is looking around for yams on the sandy ground.",
     "Mukul-jalbu wukay-mba nubi-nubi-ji bubu jukar-a.",
     "mukul-jalbu wukay-mba nubi-nubi-ji-y bubu jukar-a | old-woman yam-LOC search.for-REDUP-APASS-NONPAST ground sandy-LOC",
     "antipassive_generalized", 4, js(["mukul-jalbu", "wukay", "nubil", "bubu", "jukar"]),
     "Patz ex.368: Jalbu wukay-mba nubi-nubi-ji-y 'looking around for yam'.", "0.87"),
    (9, "The woman peeped around in the house but did not enter.",
     "Jalbu bayan-ba nuri-nuri-ji, kari walan.",
     "jalbu bayan-ba nuri-nuri-ji-y, kari wala-ny | woman house-LOC peep-REDUP-APASS-NONPAST, NEG enter-PAST",
     "antipassive_generalized", 4, js(["jalbu", "bayan", "nuril", "kari", "walal"]),
     "Patz ex.369: nuri-nuri-ji-y in houses; ordinary negation for second clause.", "0.84"),
    (10, "That child keeps hitting at the dogs around here.",
     "Yinya karrkay kaya-nda kuni-n-kuni-ji.",
     "yinya karrkay kaya-nda kuni-n-kuni-ji-y | that child dog-LOC:pt hit-REDUP-APASS-NONPAST",
     "antipassive_generalized", 4, js(["yinya", "karrkay", "kaya", "kunil"]),
     "Patz ex.366 exactly: kaya-nda kuni-n-kuni-ji-y, generalized hitting at dogs.", "0.87"),
    (11, "The young men keep hitting at the log with sticks.",
     "Warru-warru juku-ngu kuni-n-kuni-ji jaba-bu.",
     "warru-warru juku-ngu kuni-n-kuni-ji-y jaba-bu | young.man-REDUP log-LOC hit-REDUP-APASS-NONPAST stick-INST",
     "antipassive_generalized", 4, js(["warru", "juku", "kunil", "jaba"]),
     "Generalized antipassive; inanimate instrument remains instrumental, object is LOC.", "0.83"),
    (12, "The man went and threw curses everywhere.",
     "Bama dungan bunjurri-jin.",
     "bama dunga-ny bunjurri-ji-ny | person go-PAST throw.curse-APASS-PAST",
     "antipassive_generalized", 4, js(["bama", "dungay", "bunjurri"]),
     "Patz ex.367: dunga-ny bunjurri-ji-ny, target omitted and generalized.", "0.85"),
    (13, "The child had a good feed of fish and then sat quietly.",
     "Karrkay kuyu-ngu nuka-jin, janka bundan.",
     "karrkay kuyu-ngu nuka-ji-ny, janka bunda-ny | child fish-LOC eat-APASS-PAST, quiet sit-PAST",
     "antipassive_total_effect", 4, js(["karrkay", "kuyu", "nukal", "janka", "bundal"]),
     "Simple nuka-ji-ny total-effect antipassive; kuyu u-final LOC = -ngu.", "0.84"),
    (14, "The two boys keep eating at the yams near the fire.",
     "Karrkay-bulal wukay-mba nuka-n-nuka-ji baya ngundu-ba.",
     "karrkay-bulal wukay-mba nuka-n-nuka-ji-y baya ngundu-ba | child-pair yam-LOC eat-REDUP-APASS-NONPAST fire near-LOC",
     "antipassive_generalized", 4, js(["karrkay", "bulal", "wukay", "nukal", "baya", "ngundu"]),
     "Reduplicated antipassive for ongoing eating; object demoted to LOC.", "0.84"),
    (15, "The old people shared out all the meat.",
     "Mukul-bama minya-nga wambi-jin.",
     "mukul-bama minya-nga wambi-ji-ny | old-person meat-LOC share.out-APASS-PAST",
     "antipassive_total_effect", 4, js(["mukul-bama", "minya", "wambil"]),
     "Patz ex.374 pattern transferred from mayi to minya; total distribution of the patient.", "0.84"),
    (16, "Mother shared out the fish to the children.",
     "Ngamu kuyu-ngu wambi-jin karrkay-karrkay-nka.",
     "ngamu kuyu-ngu wambi-ji-ny karrkay-karrkay-nka | mother fish-LOC share.out-APASS-PAST child-REDUP-DAT",
     "antipassive_total_effect", 4, js(["ngamu", "kuyu", "wambil", "karrkay"]),
     "Object demoted to LOC; recipient remains DAT.", "0.83"),
    (17, "The young man had a feed of food and then kept eating more.",
     "Warru mayi-nga nuka-jin, baja nuka-n-nuka-ji.",
     "warru mayi-nga nuka-ji-ny, baja nuka-n-nuka-ji-y | young.man food-LOC eat-APASS-PAST, again eat-REDUP-APASS-NONPAST",
     "antipassive_total_plus_generalized", 4, js(["warru", "mayi", "nukal", "baja"]),
     "Contrasts simple total-effect nuka-ji-ny with reduplicated ongoing nuka-n-nuka-ji-y.", "0.83"),
    (18, "The dog was foraging around in the camp food.",
     "Kaya mayi-nga ngunja-n-ngunja-ji bayan-ba.",
     "kaya mayi-nga ngunja-n-ngunja-ji-y bayan-ba | dog food-LOC forage-REDUP-APASS-NONPAST camp-LOC",
     "antipassive_generalized", 4, js(["kaya", "mayi", "ngunjal", "bayan"]),
     "Patz ex.372 pattern with LOC rather than PERL.", "0.83"),
    (19, "The woman searched around for yams but got nothing.",
     "Jalbu wukay-mba nubi-nubi-ji, kari mani.",
     "jalbu wukay-mba nubi-nubi-ji-y, kari mani | woman yam-LOC search.for-REDUP-APASS-NONPAST, NEG get",
     "antipassive_generalized", 4, js(["jalbu", "wukay", "nubil", "kari", "manil"]),
     "Patz ex.368; negated result uses attested kari mani pattern.", "0.84"),
    (20, "The children searched around for the dog in the grass.",
     "Karrkay-karrkay kaya-nda nubi-nubi-ji jikan-ba.",
     "karrkay-karrkay kaya-nda nubi-nubi-ji-y jikan-ba | child-REDUP dog-LOC:pt search.for-REDUP-APASS-NONPAST grass-LOC",
     "antipassive_generalized", 4, js(["karrkay", "kaya", "nubil", "jikan"]),
     "Animate searched-for NP in potent LOC; generalized searching modelled on ex.368.", "0.83"),
    (21, "The old woman peeped around in the house and did not go inside.",
     "Mukul-jalbu bayan-ba nuri-nuri-ji, kari walan.",
     "mukul-jalbu bayan-ba nuri-nuri-ji-y, kari wala-ny | old-woman house-LOC peep-REDUP-APASS-NONPAST, NEG enter-PAST",
     "antipassive_generalized", 4, js(["mukul-jalbu", "bayan", "nuril", "kari", "walal"]),
     "Patz ex.369 nuri-nuri-ji-y in houses.", "0.84"),
    (22, "Grandmother searched around in the bag for yams.",
     "Babi wukay-mba nubi-nubi-ji balji-nga.",
     "babi wukay-mba nubi-nubi-ji-y balji-nga | grandmother yam-LOC search.for-REDUP-APASS-NONPAST bag-LOC",
     "antipassive_generalized", 4, js(["babi", "wukay", "nubil", "balji"]),
     "Object demoted to LOC; separate location also LOC.", "0.82"),
    (23, "The men kept spearing around for fish but caught nothing.",
     "Dingkar-dingkar kuyu-ngu dama-n-dama-ji, yamba kari mani.",
     "dingkar-dingkar kuyu-ngu dama-n-dama-ji-y, yamba kari mani | man-REDUP fish-LOC spear-REDUP-APASS-NONPAST, but NEG get",
     "antipassive_generalized", 4, js(["dingkar", "kuyu", "damal", "yamba", "kari", "manil"]),
     "Generalized action on non-individuated fish; negative result overt.", "0.84"),
    (24, "The boy kept spearing around for fish from the edge of the water.",
     "Karrkay kuyu-ngu dama-n-dama-ji kalka-bu bana karangkal.",
     "karrkay kuyu-ngu dama-n-dama-ji-y kalka-bu bana karangkal | child fish-LOC spear-REDUP-APASS-NONPAST spear-INST water alongside",
     "antipassive_generalized", 4, js(["karrkay", "kuyu", "damal", "kalka", "bana", "karangkal"]),
     "Object demoted to LOC; instrument retained as INST.", "0.83"),
    (25, "The man kept spearing around for wallabies all day.",
     "Dingkar kadar-a dama-n-dama-ji wungar wubulku.",
     "dingkar kadar-a dama-n-dama-ji-y wungar wubul-ku | man wallaby-LOC spear-REDUP-APASS-NONPAST day all-EMPH",
     "antipassive_generalized", 4, js(["dingkar", "kadar", "damal", "wungar", "wubul"]),
     "Generalized/non-individuated hunting; kadar single-r LOC = -a.", "0.83"),
    (26, "The children keep laughing about the dog.",
     "Karrkay-karrkay kaya-nka yajarri-n-yajarri-ji.",
     "karrkay-karrkay kaya-nka yajarri-n-yajarri-ji-y | child-REDUP dog-DAT laugh-REDUP-APASS-NONPAST",
     "antipassive_communication_like", 4, js(["karrkay", "kaya", "yajarril"]),
     "Existing corpus/Patz note includes yajarri-n-yajarri-ji with dog-DAT as friendly laugh-about.", "0.82"),
    (27, "The two old women keep laughing about the young men in a friendly way.",
     "Mukul-jalbu-bulal warru-warru-nka yajarri-n-yajarri-ji.",
     "mukul-jalbu-bulal warru-warru-nka yajarri-n-yajarri-ji-y | old-woman-pair young.man-REDUP-DAT laugh-REDUP-APASS-NONPAST",
     "antipassive_communication_like", 4, js(["mukul-jalbu", "bulal", "warru", "yajarril"]),
     "Communication-like intransitivized laugh-about pattern; goal/target as DAT.", "0.82"),
    (28, "The child pestered his mother for food.",
     "Karrkay ngamu-ndu mayi-ka walngkurrijin.",
     "karrkay ngamu-ndu mayi-ka walngkurriji-ny | child mother-LOC:pt food-DAT pester.for-PAST",
     "fixed_intransitive_communication", 4, js(["karrkay", "ngamu", "mayi", "walngkurriji"]),
     "Patz ex.377: person pestered LOC, thing requested DAT.", "0.86"),
    (29, "The little dog pestered the old woman for meat.",
     "Kaya buban mukul-jalbu-nda minya-ka walngkurrijin.",
     "kaya buban mukul-jalbu-nda minya-ka walngkurriji-ny | dog small old-woman-LOC:pt meat-DAT pester.for-PAST",
     "fixed_intransitive_communication", 4, js(["kaya", "buban", "mukul-jalbu", "minya", "walngkurriji"]),
     "Fixed walngkurriji-y frame from Patz §4.2.4.4; target LOC, requested thing DAT.", "0.83"),
    (30, "The man asked me for food.",
     "Dingkar ngayku-ndu mayi-ka kunjajin.",
     "dingkar ngayku-ndu mayi-ka kunjaji-ny | man I-LOC:pt food-DAT ask.for-PAST",
     "fixed_intransitive_communication", 4, js(["dingkar", "ngayu", "mayi", "kunjaji"]),
     "Patz ex.376b: Dingkar ngayku-ndu mayi-ka kunjaji-ny.", "0.87"),
    (31, "The old woman asked father for fish.",
     "Mukul-jalbu nganjan-nda kuyu-ku kunjajin.",
     "mukul-jalbu nganjan-nda kuyu-ku kunjaji-ny | old-woman father-LOC:pt fish-DAT ask.for-PAST",
     "fixed_intransitive_communication", 4, js(["mukul-jalbu", "nganjan", "kuyu", "kunjaji"]),
     "kunjaji-y fixed intransitive frame: person asked LOC, thing requested DAT.", "0.84"),
    (32, "The boss asked the young man about the meat.",
     "Maja warru-nda minya-ka babajin.",
     "maja warru-nda minya-ka babaji-ny | boss young.man-LOC:pt meat-DAT ask.about-PAST",
     "fixed_intransitive_communication", 4, js(["maja", "warru", "minya", "babaji"]),
     "Patz ex.378 / Rule 59: person asked LOC, topic DAT.", "0.85"),
    (33, "Mother asked the child about the fire.",
     "Ngamu karrkay-anda baya-ka babajin.",
     "ngamu karrkay-anda baya-ka babaji-ny | mother child-LOC:pt fire-DAT ask.about-PAST",
     "fixed_intransitive_communication", 4, js(["ngamu", "karrkay", "baya", "babaji"]),
     "babaji-y fixed intransitive speech frame; person LOC, topic DAT.", "0.85"),
    (34, "The child asked grandmother about the old song.",
     "Karrkay babi-nda wulngku mukul-ku babajin.",
     "karrkay babi-nda wulngku mukul-ku babaji-ny | child grandmother-LOC:pt song old-DAT ask.about-PAST",
     "fixed_intransitive_communication", 4, js(["karrkay", "babi", "wulngku", "mukul", "babaji"]),
     "Rule 59: topic NP carries DAT on the final modifier.", "0.84"),
    (35, "The woman shared out the food, and everyone ate.",
     "Jalbu mayi-nga wambi-jin, bama wubulku nukan.",
     "jalbu mayi-nga wambi-ji-ny, bama wubul-ku nuka-ny | woman food-LOC share.out-APASS-PAST, person all-EMPH eat-PAST",
     "antipassive_total_effect", 4, js(["jalbu", "mayi", "wambil", "bama", "wubul", "nukal"]),
     "Total-effect wambi-ji-ny; result clause shows complete distribution.", "0.84"),
    (36, "People kept eating at meat in the shade while the rain fell.",
     "Bama minya-nga nuka-n-nuka-ji wabarr-ba, kaba daran.",
     "bama minya-nga nuka-n-nuka-ji-y wabarr-ba, kaba dara-ny | person meat-LOC eat-REDUP-APASS-NONPAST shade-LOC, rain fall-PAST",
     "antipassive_generalized", 4, js(["bama", "minya", "nukal", "wabarr", "kaba", "daray"]),
     "Reduplicated antipassive; object LOC and A as S.", "0.83"),
    (37, "The dog kept foraging around in the food near the fire.",
     "Kaya mayi-nga ngunja-n-ngunja-ji baya ngundu-ba.",
     "kaya mayi-nga ngunja-n-ngunja-ji-y baya ngundu-ba | dog food-LOC forage-REDUP-APASS-NONPAST fire near-LOC",
     "antipassive_generalized", 4, js(["kaya", "mayi", "ngunjal", "baya", "ngundu"]),
     "Same Patz ex.372 generalized-forage pattern; LOC rather than PERL.", "0.83"),
    (38, "The old woman peeped around in the house, and the children did not see her.",
     "Mukul-jalbu bayan-ba nuri-nuri-ji, karrkay-karrkay kari nyajin.",
     "mukul-jalbu bayan-ba nuri-nuri-ji-y, karrkay-karrkay kari nyaji-ny | old-woman house-LOC peep-REDUP-APASS-NONPAST, child-REDUP NEG see-PAST",
     "antipassive_generalized", 4, js(["mukul-jalbu", "bayan", "nuril", "karrkay", "kari", "nyajil"]),
     "Patz ex.369 pattern; second clause uses attested negated perception.", "0.84"),
    (39, "The men searched around for the net in the scrub.",
     "Dingkar-dingkar makarr-ba nubi-nubi-ji madja-nga.",
     "dingkar-dingkar makarr-ba nubi-nubi-ji-y madja-nga | man-REDUP net-LOC search.for-REDUP-APASS-NONPAST scrub-LOC",
     "antipassive_generalized", 4, js(["dingkar", "makarr", "nubil", "madja"]),
     "Object demoted to LOC; makarr has rr so LOC = -ba.", "0.83"),
    (40, "The boy searched around for the spear at the creek.",
     "Karrkay kalka-nga nubi-nubi-ji yilki-nga.",
     "karrkay kalka-nga nubi-nubi-ji-y yilki-nga | child spear-LOC search.for-REDUP-APASS-NONPAST creek-LOC",
     "antipassive_generalized", 4, js(["karrkay", "kalka", "nubil", "yilki"]),
     "Object demoted to LOC; kalka/yilki a/i-final LOC = -nga.", "0.83"),
    (41, "The old woman searched around for yams at the creek.",
     "Mukul-jalbu wukay-mba nubi-nubi-ji yilki-nga.",
     "mukul-jalbu wukay-mba nubi-nubi-ji-y yilki-nga | old-woman yam-LOC search.for-REDUP-APASS-NONPAST creek-LOC",
     "antipassive_generalized", 4, js(["mukul-jalbu", "wukay", "nubil", "yilki"]),
     "Patz ex.368 pattern with explicit place LOC.", "0.84"),
    (42, "The children kept hitting at the grass with sticks.",
     "Karrkay-karrkay jikan-ba kuni-n-kuni-ji jaba-bu.",
     "karrkay-karrkay jikan-ba kuni-n-kuni-ji-y jaba-bu | child-REDUP grass-LOC hit-REDUP-APASS-NONPAST stick-INST",
     "antipassive_generalized", 4, js(["karrkay", "jikan", "kunil", "jaba"]),
     "Generalized hit-at action; inanimate instrument remains INST.", "0.82"),
    (43, "The young man took over the house completely.",
     "Warru bayan-ba ngunja-jin.",
     "warru bayan-ba ngunja-ji-ny | young.man house-LOC take.over-APASS-PAST",
     "antipassive_total_effect", 4, js(["warru", "bayan", "ngunjal"]),
     "Patz ex.375 total-effect ngunja-ji-ny.", "0.85"),
    (44, "The two women took over the ground oven completely.",
     "Jalbu-bulal kurrma-nga ngunja-jin.",
     "jalbu-bulal kurrma-nga ngunja-ji-ny | woman-pair ground.oven-LOC take.over-APASS-PAST",
     "antipassive_total_effect", 4, js(["jalbu", "bulal", "kurrma", "ngunjal"]),
     "Simple antipassive total-effect with object LOC.", "0.82"),
    (45, "Mother shared out all the yams.",
     "Ngamu wukay-mba wambi-jin.",
     "ngamu wukay-mba wambi-ji-ny | mother yam-LOC share.out-APASS-PAST",
     "antipassive_total_effect", 4, js(["ngamu", "wukay", "wambil"]),
     "Patz ex.374 wambi-ji-ny transferred to another food noun; LOC allomorph checked.", "0.84"),
    (46, "The children kept eating at the yams after the rain.",
     "Karrkay-karrkay wukay-mba nuka-n-nuka-ji kaba-muny.",
     "karrkay-karrkay wukay-mba nuka-n-nuka-ji-y kaba-muny | child-REDUP yam-LOC eat-REDUP-APASS-NONPAST rain-ABL",
     "antipassive_generalized", 4, js(["karrkay", "wukay", "nukal", "kaba"]),
     "Reduplicated antipassive; wukay as non-individuated object in LOC.", "0.84"),
    (47, "The men kept spearing around for fish while the tide was rising.",
     "Dingkar-dingkar kuyu-ngu dama-n-dama-ji, yira daka-l.",
     "dingkar-dingkar kuyu-ngu dama-n-dama-ji-y, yira daka-l | man-REDUP fish-LOC spear-REDUP-APASS-NONPAST, tide rise-NONPAST",
     "antipassive_generalized", 4, js(["dingkar", "kuyu", "damal", "yira", "dakal"]),
     "Generalized antipassive hunting with temporal setting.", "0.84"),
    (48, "The people kept eating at the food all day.",
     "Bama mayi-nga nuka-n-nuka-jin wungar wubulku.",
     "bama mayi-nga nuka-n-nuka-ji-ny wungar wubul-ku | person food-LOC eat-REDUP-APASS-PAST day all-EMPH",
     "antipassive_generalized_past", 4, js(["bama", "mayi", "nukal", "wungar", "wubul"]),
     "Text line 39/48 has past nuka-nuka-ji-ny; generalized past action.", "0.84"),
    (49, "The old people shared out the food and gave it to the children.",
     "Mukul-bama mayi-nga wambi-jin, karrkay-karrkay-nka dajin.",
     "mukul-bama mayi-nga wambi-ji-ny, karrkay-karrkay-nka daji-ny | old-person food-LOC share.out-APASS-PAST, child-REDUP-DAT give-PAST",
     "antipassive_total_effect", 4, js(["mukul-bama", "mayi", "wambil", "karrkay", "dajil"]),
     "wambi-ji-ny total distribution plus ordinary dative recipient clause.", "0.84"),
    (50, "The old man said, people eat around at food, but a person eats one piece of food directly.",
     "Mukul-dingkar balkan, bama mayi-nga nuka-n-nuka-ji, yamba bama-ngku mayi nyubun nuka-l.",
     "mukul-dingkar balka-ny, bama mayi-nga nuka-n-nuka-ji-y, yamba bama-ngku mayi nyubun nuka-l | old-man say-PAST, person food-LOC eat-REDUP-APASS-NONPAST, but person-ERG food one eat-NONPAST",
     "antipassive_transitive_contrast", 4, js(["mukul-dingkar", "balkal", "bama", "mayi", "nukal", "nyubun"]),
     "Explicit contrast: antipassive A=S/O=LOC vs transitive A=ERG/O=ABS.", "0.83"),
]


def scan() -> list[str]:
    issues: list[str] = []
    if len(ROWS) != 50:
        issues.append(f"expected 50 rows, got {len(ROWS)}")
    seqs = [r[0] for r in ROWS]
    if seqs != list(range(1, 51)):
        issues.append(f"seqs must be 1..50, got {seqs[:5]}...{seqs[-5:]}")
    seen_ku: set[str] = set()
    for row in ROWS:
        seq, english, kuku, analysis, frame, tier, words_used, evidence, confidence = row
        label = f"{LABEL}.{seq:02d}"
        if not english[:1].isupper() or english.rstrip("'\"").rstrip()[-1:] not in ".!?":
            issues.append(f"{label}: English must be capitalized and final-punctuated")
        if " | " not in analysis:
            issues.append(f"{label}: analysis missing gloss separator")
        if not kuku[:1].isupper():
            issues.append(f"{label}: Kuku surface must start uppercase")
        try:
            json.loads(words_used)
        except Exception as exc:
            issues.append(f"{label}: words_used is not JSON: {exc}")
        low = f" {kuku.lower()} {analysis.lower()} "
        for word in DENY:
            if re.search(rf"(?<![a-z]){re.escape(word)}(?![a-z])", low):
                issues.append(f"{label}: denied phantom/wrong-sense token {word!r}")
        if kuku.lower() in seen_ku:
            issues.append(f"{label}: duplicate Kuku surface within batch")
        seen_ku.add(kuku.lower())
    return issues


def main() -> int:
    issues = scan()
    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")
    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,))
        db.execute("UPDATE batches SET notes=?, created_at=? WHERE id=?", ("rebanked under_review", NOW, batch_id))
    else:
        cur = db.execute(
            "INSERT INTO batches(label, cheatsheet_version, guide_version, notes, created_at) VALUES(?,?,?,?,?)",
            (LABEL, "Rule 82 draft: antipassive from Patz 4.2.4.4", "operator-guide-2026-07-07", "under_review", NOW),
        )
        batch_id = cur.lastrowid

    db.executemany(
        """
        INSERT INTO sentences(
            batch_id, seq, english, kuku, analysis, frame, tier, words_used,
            loans_used, evidence, status, confidence, rights_status, author,
            created_at, updated_at
        ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
        """,
        [
            (
                batch_id, seq, english, kuku, analysis, frame, tier, words_used,
                "[]", evidence, "under_review", confidence,
                "project_approved_synthetic_pending_elder_verification",
                "claude-main", NOW, NOW,
            )
            for seq, english, kuku, analysis, frame, tier, words_used, evidence, confidence in ROWS
        ],
    )
    db.commit()
    count = db.execute("SELECT COUNT(*) FROM sentences WHERE batch_id=?", (batch_id,)).fetchone()[0]
    avg_words = db.execute(
        "SELECT AVG(LENGTH(kuku)-LENGTH(REPLACE(kuku,' ',''))+1.0) FROM sentences WHERE batch_id=?",
        (batch_id,),
    ).fetchone()[0]
    print(f"banked {LABEL}: {count} rows under_review; avg Kuku words/row={avg_words:.2f}")
    return 0


if __name__ == "__main__":
    sys.exit(main())
