HassamGani commited on
Commit
0e286e0
·
unverified ·
1 Parent(s): d14eea8

Notice grading: 'disregard the earlier figure' takes back the old figure, not the one the same reply states

Browse files
reorgbench/gen/units.py CHANGED
@@ -228,6 +228,9 @@ _SPECIFIC = re.compile(r"\b(?:duplicate|copy|twice|repeat\w*|automated|auto-gene
228
  _GENERIC = re.compile(rf"^\W*(?:(?:all of\s+)?(?:that|this|it|everything|the above)\b|(?:(?:my|our|the|that|this|any|"
229
  rf"these|those)\s+)?(?:\S+\s+){{0,2}}?{_NOTE}|what (?:i|we)\b|(?:my|our|the)?\s*(?:previous|"
230
  rf"earlier|last|prior|first|original|initial)\b)")
 
 
 
231
  _ANCHOR = re.compile(rf"{_CHANGE}|\b(?:plan|price|pricing|region|figure|amount|total|reference|fig)\b")
232
  _ABORT = re.compile(rf"(?<!\bthe )(?<!\ba )\b(?:cancel+(?:ed|ing)?|call(?:ed|ing)? off|postpon(?:e|ed|ing)|"
233
  rf"paus(?:e|ed|ing)|delay(?:ed|ing)|defer(?:red|ring)?|shelv(?:e|ed|ing)|scrapp(?:ed|ing)|"
@@ -384,7 +387,7 @@ def _cue(c: str) -> tuple[str | None, bool]:
384
  hit = bool(_GENERIC.search(obj) or _ANCHOR.search(obj)) or (
385
  not obj.strip(" .!,") and not c[:m.start()].rstrip().endswith(" to"))
386
  if hit and not _SPECIFIC.search(obj):
387
- return "retract", bool(re.search(r"\bfig\b", obj))
388
  for p in (_WITHDRAW, _ABORT):
389
  for m in p.finditer(c):
390
  if not re.search(rf"{_NEG}\s+(?:\S+\s+)?$|\b(?:no need to|please|kindly|avoid|you (?:should|may|might|can|"
@@ -466,7 +469,9 @@ def told_value(texts: list[str], values: list[Any], account: str | None = None)
466
  for kind, pos, neg, aimed, _ in _events([text], values, account):
467
  if kind == "stay" and not pos and here & told:
468
  continue
469
- if kind == "retract" or (kind == "stay" and not pos):
 
 
470
  undone, told = told or undone, told - pos - neg if aimed else set()
471
  elif kind == "affirm":
472
  told |= undone
 
228
  _GENERIC = re.compile(rf"^\W*(?:(?:all of\s+)?(?:that|this|it|everything|the above)\b|(?:(?:my|our|the|that|this|any|"
229
  rf"these|those)\s+)?(?:\S+\s+){{0,2}}?{_NOTE}|what (?:i|we)\b|(?:my|our|the)?\s*(?:previous|"
230
  rf"earlier|last|prior|first|original|initial)\b)")
231
+ # "disregard the earlier figure" takes back what was said before, not the figure this reply states
232
+ _EARLIER_FIG = re.compile(rf"\b(?:earlier|previous|prior|old|original|first|initial|last|incorrect|wrong)\s+(?:monthly\s+)?"
233
+ rf"(?:figures?|prices?|amounts?|totals?|quotes?|numbers?)\b(?!\s+{_NOTE})")
234
  _ANCHOR = re.compile(rf"{_CHANGE}|\b(?:plan|price|pricing|region|figure|amount|total|reference|fig)\b")
235
  _ABORT = re.compile(rf"(?<!\bthe )(?<!\ba )\b(?:cancel+(?:ed|ing)?|call(?:ed|ing)? off|postpon(?:e|ed|ing)|"
236
  rf"paus(?:e|ed|ing)|delay(?:ed|ing)|defer(?:red|ring)?|shelv(?:e|ed|ing)|scrapp(?:ed|ing)|"
 
387
  hit = bool(_GENERIC.search(obj) or _ANCHOR.search(obj)) or (
388
  not obj.strip(" .!,") and not c[:m.start()].rstrip().endswith(" to"))
389
  if hit and not _SPECIFIC.search(obj):
390
+ return "retract", "earlier" if _EARLIER_FIG.search(obj) else bool(re.search(r"\bfig\b", obj))
391
  for p in (_WITHDRAW, _ABORT):
392
  for m in p.finditer(c):
393
  if not re.search(rf"{_NEG}\s+(?:\S+\s+)?$|\b(?:no need to|please|kindly|avoid|you (?:should|may|might|can|"
 
469
  for kind, pos, neg, aimed, _ in _events([text], values, account):
470
  if kind == "stay" and not pos and here & told:
471
  continue
472
+ if kind == "retract" and aimed == "earlier": # what this reply states stands
473
+ undone, told = told or undone, (told & here) | pos
474
+ elif kind == "retract" or (kind == "stay" and not pos):
475
  undone, told = told or undone, told - pos - neg if aimed else set()
476
  elif kind == "affirm":
477
  told |= undone
tests/test_notice_grading.py CHANGED
@@ -1212,3 +1212,18 @@ def test_held_out_round_h1_patterns():
1212
  # controls: the customer's own account named, or a figure 'for' their own account, still tells
1213
  assert told_value(["The refund for account C-3030 was processed. The total refunded is $760."], [760.0], "C-3030")
1214
  assert told_value(["That $760 refund is for account C-3030, yours."], [760.0], "C-3030")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1212
  # controls: the customer's own account named, or a figure 'for' their own account, still tells
1213
  assert told_value(["The refund for account C-3030 was processed. The total refunded is $760."], [760.0], "C-3030")
1214
  assert told_value(["That $760 refund is for account C-3030, yours."], [760.0], "C-3030")
1215
+
1216
+
1217
+ def test_disregard_the_earlier_figure_keeps_the_one_this_reply_states():
1218
+ # probe AQ: every Essentials correction ended "Please disregard the earlier figure." and was read as taking all back
1219
+ first = "Based on your 12 seats at $45 per seat, your new monthly price will be $540.00. Account: C-2842."
1220
+ fix = ("A quick correction to our earlier message: the new Essentials price is lower than we said. Based on your 12 "
1221
+ "seats at $44 per seat, your new monthly price will be $528.00. Please disregard the earlier figure. "
1222
+ "Account: C-2842.")
1223
+ assert told_value([first, fix], [528.0], "C-2842") and current_says([first, fix], 528.0, [540.0], "C-2842")
1224
+ assert not told_value([first, fix], [540.0], "C-2842")
1225
+ assert told_value([first, "Please disregard the earlier figure. Your new total is $528.00."], [528.0], "C-2842")
1226
+ # on its own it takes the earlier figure back; a whole message or notice disregarded still takes everything back
1227
+ assert not told_value([first, "Please disregard the earlier figure."], [540.0], "C-2842")
1228
+ assert not told_value([first, "Please disregard our earlier message."], [540.0], "C-2842")
1229
+ assert not told_value([first, "Please disregard the previous price notice."], [540.0], "C-2842")