Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(email): a sign-off word inside the body is not a signature (#132)
Ludwig J. Marxe20cdf91a308
diff --git a/laya/email.py b/laya/email.pyindex 8770e184..958f98a1 100644--- a/laya/email.py+++ b/laya/email.py@@ -33,7 +33,15 @@ _HEADER_FROM_NAME = re.compile(r"^\s*De:\s+\S", re.I)_HEADER_NEXT = re.compile(r"^\s*(Enviad[oa]( em| el)?:\s|(Data|Fecha):\s.*\d{4})", re.I)_SIGNATURE_MARKERS = [re.compile(r"^\s*--\s*$"),- re.compile(r"^\s*(best|kind|warm|many thanks|thanks|thank you|regards|cheers|sincerely)[\w ,!.]*$", re.I),+ # A closing line is the closing word plus punctuation and at most a name. Anything else on+ # the line is a sentence, and the case of the next word is what separates the two: a name is+ # capitalised, "for" in "Thanks for the quick reply." is not. The closing words are matched+ # case-insensitively, the name is not, so the flag is scoped instead of global.+ re.compile(+ r"^\s*(?i:best|kind|warm|many thanks|thanks|thank you|regards|cheers|sincerely)"+ r"(?i:\s+(?:regards|wishes|again|in advance|a lot|so much|very much))?"+ r"[\s,;:!.]*(?:[A-Z][\w'-]*[\s,.]*){0,3}$"+ ),re.compile(r"^\s*sent from my (iphone|android|mobile|ipad)", re.I),# Portuguese/Spanish sign-offs match only on their own: "Obrigado pelo retorno, mas ..." is a# request, not a signature, so unlike the English marker no trailing words are alloweddiff --git a/tests/test_email.py b/tests/test_email.pyindex 266381c1..e64c7993 100644--- a/tests/test_email.py+++ b/tests/test_email.py@@ -10,6 +10,13 @@ footer ran on without a blank line, the request went with it:Dropping the request is silent and severe; leaving one boilerplate line behind is neither, so thecleaning errs towards keeping text.++The same asymmetry drives the sign-off tests below. `_SIGNATURE_MARKERS` allowed a whole+sentence behind the closing word, so an ordinary body line beginning with one of them was read+as the start of a signature and everything after it was cut:++ clean_email_body("Hi,\\n\\nThanks for the quick reply.\\nCould you refund invoice 4411?")+ # before: 'Hi,' <- the request was cut away"""import osimport sys@@ -286,6 +293,50 @@ for label, body in []:check("pt/kept: " + label, clean_email_body(body), body)+# ------------------------------------------- a sign-off word inside the body is not a sign-off+SHORT = "Hi,\n\nThanks for the quick reply.\nCould you refund invoice 4411 as well?"+check("signoff word/short mail keeps the request", clean_email_body(SHORT), SHORT)+check(+ "signoff word/thanks mid-body keeps what follows",+ clean_email_body(+ "Hello,\n\nWe were billed twice in March.\nThanks for looking into it.\n"+ "The duplicate is 49 EUR on invoice 4411."+ ),+ "Hello,\n\nWe were billed twice in March.\nThanks for looking into it.\n"+ "The duplicate is 49 EUR on invoice 4411.",+)+check(+ "signoff word/best mid-body keeps what follows",+ clean_email_body(+ "Hi team,\n\nOur account is locked.\nBest practice would be a manual unlock.\n"+ "Please unlock account 88213 today."+ ),+ "Hi team,\n\nOur account is locked.\nBest practice would be a manual unlock.\n"+ "Please unlock account 88213 today.",+)+check(+ "signoff word/email_state keeps the request",+ email_state("Duplicate charge", SHORT)["body"],+ SHORT,+)++# ------------------------------------------- real sign-offs are still cut (positive controls)+BODY = "Hi,\n\nPlease refund invoice 4411."+for label, tail in [+ ("thanks comma", "Thanks,\nAnna"),+ ("thanks bang", "Thanks!"),+ ("best regards", "Best regards,\nAnna"),+ ("kind regards", "Kind regards"),+ ("cheers name", "Cheers, Anna"),+ ("many thanks", "Many thanks,\nAnna Meier"),+ ("thank you", "Thank you,"),+ ("thanks in advance", "Thanks in advance,"),+ ("sincerely", "Sincerely,\nA. Meier"),+ ("sent from phone", "Sent from my iPhone"),+ ("dash delimiter", "--\nAnna Meier\nSupport"),+]:+ check("signoff cut/" + label, clean_email_body("%s\n\n%s" % (BODY, tail)), BODY)+# ------------------------------------------------- the word, without the disclaimer# `confidential` was a bare substring of `_DISCLAIMER`, so any sentence that merely