fix(question_gen): check_verbatim covers question_text + add missing blacklist patterns

- check_verbatim now computes n-gram overlap for BOTH question_text and
  correct_option vs source texts, returning max(question_ratio, option_ratio).
  Extracted _ngram_overlap_ratio helper for reuse.

- Added 4 missing blacklist patterns: 'this segment', 'this frame',
  'the current frame', 'frame summary'.

- Added 5 new test cases covering the above changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-11 23:23:37 -04:00
parent 9525726133
commit 7abe92eb1c
2 changed files with 93 additions and 29 deletions
+40
View File
@@ -122,6 +122,31 @@ class TestReferentBlacklist:
violations = check_referent_blacklist(q)
assert len(violations) >= 1
def test_this_segment_caught(self) -> None:
"""'this segment' 被检测为违规。"""
q = "What action is performed in this segment?"
violations = check_referent_blacklist(q)
assert len(violations) >= 1
assert any("this segment" in v.lower() for v in violations)
def test_this_frame_caught(self) -> None:
"""'this frame' 被检测为违规。"""
q = "What object is visible in this frame?"
violations = check_referent_blacklist(q)
assert len(violations) >= 1
def test_current_frame_caught(self) -> None:
"""'the current frame' 被检测为违规。"""
q = "Based on the current frame, what is happening?"
violations = check_referent_blacklist(q)
assert len(violations) >= 1
def test_frame_summary_caught(self) -> None:
"""'frame summary' 被检测为违规。"""
q = "According to the frame summary, what is the main event?"
violations = check_referent_blacklist(q)
assert len(violations) >= 1
# ---------------------------------------------------------------------------
# TestVerbatim
@@ -186,6 +211,21 @@ class TestVerbatim:
)
assert ratio == 0.0
def test_question_text_overlap_detected(self) -> None:
"""题目文本从来源复制但选项原创时,仍检测到高重叠率。"""
source = "The man walked slowly through the crowded market buying fresh vegetables"
# 题目直接复制来源的大部分内容
question = "The man walked slowly through the crowded market buying what?"
# 选项完全原创
option = "A. Fresh organic produce from the local farm stand"
ratio = check_verbatim(
question_text=question,
correct_option=option,
source_texts=[source],
window=6,
)
assert ratio > 0.0, "题目文本的逐字重叠应被检测到"
# ---------------------------------------------------------------------------
# TestTimeAnchor