Skip to content

armgit / laya

Public Imported from GitHub
0

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.

fix(email): closings the case rule does not reach (#245)

Ahmed Abdullah4f2aaf3b5fa2
diff --git a/laya/email.py b/laya/email.py
index b5592e1d..24b9ea90 100644
--- a/laya/email.py
+++ b/laya/email.py
@@ -41,10 +41,13 @@ _SIGNATURE_MARKERS = [
# 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.
+ # `warmest` and `and/& regards` are closings the alternation did not reach, and a name is
+ # capitalised in any script, so the name class excludes the lowercase letters instead of
+ # listing the uppercase ones: `Regards, Łukasz` is a sign-off, `Thanks for the reply` is not.
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}$"
+ r"^\s*(?i:best|kind|warmest|warm|many thanks|thanks|thank you|regards|cheers|sincerely)"
+ r"(?i:\s+(?:and|&)\s+regards|\s+(?:regards|wishes|again|in advance|a lot|so much|very much))?"
+ r"[\s,;:!.]*(?:[^\W\d_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
diff --git a/tests/test_email.py b/tests/test_email.py
index b49de7d3..eab9c612 100644
--- a/tests/test_email.py
+++ b/tests/test_email.py
@@ -345,6 +345,28 @@ for label, tail in [
]:
check("signoff cut/" + label, clean_email_body("%s\n\n%s" % (BODY, tail)), BODY)
+# ------------------------------------------- closings the case rule did not reach (#132 follow-up)
+# These were cut before #132 and are not now: `warmest` is not in the alternation, `and regards`
+# is not one of its continuations, and `[A-Z]` is ASCII, so a name in any other script reads as a
+# sentence. Each leaves the signature block in the body that the sign-off rule exists to remove.
+for label, tail in [
+ ("thanks and regards", "Thanks and regards,\nAnna"),
+ ("thanks & regards", "Thanks & Regards,\nAnna"),
+ ("warmest regards", "Warmest regards,\nAnna"),
+ ("warmest wishes", "Warmest wishes,"),
+ ("non-ascii name", "Regards, Łukasz"),
+ ("non-ascii name, accented", "Thanks, José"),
+ ("cyrillic name", "Regards, Дмитрий"),
+]:
+ check("signoff cut/" + label, clean_email_body("%s\n\n%s" % (BODY, tail)), BODY)
+
+# ...and the wider closing must not swallow a sentence that merely starts the same way
+for label, body in [
+ ("and + sentence", "Hi,\n\nPlease refund 4411.\nThanks and the team will confirm it today."),
+ ("warmest + sentence", "Hi,\n\nThe room is cold.\nWarmest setting still reads 18 degrees."),
+]:
+ check("signoff kept/" + label, clean_email_body(body), body)
+
# ------------------------------------------------- the word, without the disclaimer
# `confidential` was a bare substring of `_DISCLAIMER`, so any sentence that merely