#!/usr/bin/env python3
"""Rough tally of a captured answer against ground-truth.md: planted phrases, numbers, owners with their dates.
Prints what it found and what it did not; the sheet is scored by reading, this just keeps the count honest."""
import re, sys
text = open(sys.argv[1], encoding="utf-8").read()
if "\n## " in text: text = text.split("\n## ", 1)[1]  # score the tool's words, not the operator's notes above the first section
text = text.lower()
def has(*pats): return any(re.search(p, text) for p in pats)
phrases = {
 "Olaria Beira": [r"olaria beira"], "fifty then sixty": [r"fifty.{0,25}sixty", r"50.{0,25}60"],
 "14.90 / fourteen ninety": [r"14[.,]90", r"fourteen ninety"], "rejected fifteen": [r"\bfifteen\b", r"€\s?15\b", r"\b15 euros?"],
 "Ginjinha": [r"ginjinha"], "pastel de nata": [r"past(el|éis|eis) de nata"],
}
numbers = {
 "3,395.50": [r"3[,.]?395[.,]5"], "1,538.60": [r"1[,.]?538[.,]6"], "120 orders": [r"\b120\b"], "20 customers": [r"\b20 (customers|people|repeat)", r"twenty customers"],
 "7 bowls left": [r"\b(seven|7) (bowls )?left", r"\b7\b.{0,20}bowls", r"bowls.{0,20}\b7\b"], "40 sold": [r"\b(forty|40)\b.{0,30}(bowls|quarter|sold)", r"sold (forty|40)"],
 "3 weeks": [r"(three|3)[- ]weeks?"], "€80 a month": [r"80\s?(€|euros?)|€\s?80|eighty euros"], "Porto 13 / Braga 31": [r"\b13\b.{0,40}(porto|orders)|porto.{0,40}\b13\b"], "VAT 23%": [r"23\s?(%|percent|per cent)"],
}
actions = {
 "Ana photos 1 July": [r"photo.{0,80}(1|1st|first)( of)? july|july 1\b.{0,80}photo|photo.{0,80}july 1\b"],
 "Rui bowls Fri 26 June": [r"(order|bowl).{0,80}(26|26th|twenty.sixth)( of)? june|june 26.{0,80}(order|bowl)|(order|bowl).{0,60}friday"],
 "Rui export format by July export / 1 Aug": [r"(export|date format).{0,120}(july export|1 august|august 1|1st of august|before august)"],
 "Ana Braga email 6 July": [r"braga.{0,100}(6|6th|sixth)( of)? july|july 6.{0,100}braga|braga.{0,60}launch"],
 "Marta invoice 30 June": [r"invoice.{0,80}(30|30th|thirtieth)( of)? june|june 30.{0,80}invoice"],
 "Marta VAT 10 July": [r"vat.{0,80}(10|10th|tenth)( of)? july|july 10.{0,80}vat"],
}
for title, d in (("planted phrases", phrases), ("numbers", numbers), ("action items (date near the item)", actions)):
    hit = [k for k, v in d.items() if has(*v)]
    print(f"{title}: {len(hit)} of {len(d)} | missing: {[k for k in d if k not in hit]}")
print("christmas mentioned:", bool(re.search(r"christmas", text)), "| speakers named:", sorted({n for n in ("ana","rui","marta") if re.search(rf"\b{n}\b", text)}))
