thangvip commited on
Commit
98fffe5
·
verified ·
1 Parent(s): 8f18533

fix: distinguish reflection questions from factual claims

Browse files

Do not treat past-action wording inside a question as an asserted user biography.

Files changed (1) hide show
  1. src/compliment_forest/quality.py +19 -0
src/compliment_forest/quality.py CHANGED
@@ -242,6 +242,23 @@ def _action_roots(text: str) -> set[str]:
242
  return {root for form, root in _ACTION_LOOKUP.items() if form in tokens}
243
 
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  def unsupported_specificity(text: str, situation: str) -> set[str]:
246
  """Find concrete claims in generated prose that the user did not provide."""
247
 
@@ -266,6 +283,8 @@ def unsupported_specificity(text: str, situation: str) -> set[str]:
266
  )
267
  for pattern, lookup in past_claims:
268
  for match in pattern.finditer(text):
 
 
269
  root = lookup[match.group("verb").casefold()]
270
  if root not in situation_actions:
271
  issues.add("unsupported_past_claim")
 
242
  return {root for form, root in _ACTION_LOOKUP.items() if form in tokens}
243
 
244
 
245
+ def _match_is_in_question(text: str, start: int) -> bool:
246
+ sentence_start = max(
247
+ text.rfind(".", 0, start),
248
+ text.rfind("!", 0, start),
249
+ text.rfind("?", 0, start),
250
+ )
251
+ sentence_end_candidates = [
252
+ position
253
+ for punctuation in ".!?"
254
+ if (position := text.find(punctuation, start)) >= 0
255
+ ]
256
+ if not sentence_end_candidates:
257
+ return False
258
+ sentence_end = min(sentence_end_candidates)
259
+ return text[sentence_start + 1 : sentence_end + 1].strip().endswith("?")
260
+
261
+
262
  def unsupported_specificity(text: str, situation: str) -> set[str]:
263
  """Find concrete claims in generated prose that the user did not provide."""
264
 
 
283
  )
284
  for pattern, lookup in past_claims:
285
  for match in pattern.finditer(text):
286
+ if _match_is_in_question(text, match.start()):
287
+ continue
288
  root = lookup[match.group("verb").casefold()]
289
  if root not in situation_actions:
290
  issues.add("unsupported_past_claim")