fix: assign case code to partial verbatim copies with exact-span evidence

원고 일부만 그대로 옮기면 전체 유사도가 중간이라 주 태그가 비어 case_id 가
null 로 내려갔다. 35자 이상 연속 일치로 채택된 매칭은 복제권·인용 누락을
주 태그로 붙여 M1 으로 분류한다.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5.5 committed 2026-10-21 08:38:46 +09:00
1 parent 2043b6d399
commit 03d500d67c
2 files changed
+44 -2

No files matched your search

+31
View File
@@ -134,3 +134,34 @@ def test_case_reason_explains_tags_ties_and_draft_mapping():
assert 'text=0.45' in reason and 'M1, M10 중 하나로' in reason
assert '판단할 것: Q3' in reason and '추정치' not in reason
assert '추정치' in PlagiarismDetector._case_reason(m10, ['reproduction'], hit, tie)
def test_partial_verbatim_copy_gets_case_code(tmp_path):
"""원고 일부만 그대로 옮긴 경우 전체 유사도가 중간이라도 분류 코드가 비면 안 된다.
35자 이상 연속 일치로 채택된 매칭인데 주 태그가 없어 case_id 가 null 로
내려가던 문제의 회귀 테스트. 원문·원고는 모두 가짜 문장이다.
"""
from app.api.schemas import DetectRequest
from app.core.config import get_settings
from app.engine.detector import PlagiarismDetector
from app.engine.persistent_index import PersistentCorpusIndex
from scripts.run_precision_eval import build_corpus
source = ("나는 바닷가 작은 마을에서 태어났다. 아버지는 새벽마다 배를 타고 나가셨고 어머니는 "
"시장에서 생선을 파셨다. 열 살 무렵 처음으로 아버지의 배에 올랐던 날, 바다 위로 "
"떠오르던 해를 보며 나도 언젠가 저 수평선 너머로 가겠다고 다짐했다. 중학교를 마치고 "
"도시로 올라와 인쇄소에서 일을 배웠다. 밤마다 활자를 정리하며 책 냄새를 맡는 것이 "
"그렇게 좋을 수가 없었다.")
query = ("어린 시절 이야기를 조금 적어 본다. 열 살 무렵 처음으로 아버지의 배에 올랐던 날, "
"바다 위로 떠오르던 해를 보며 나도 언젠가 저 수평선 너머로 가겠다고 다짐했다. "
"그 뒤로 나는 늘 바다를 그리워하며 살았다.")
db, index = tmp_path / 'corpus.sqlite3', tmp_path / 'index'
build_corpus([{'author': 'sample', 'segment_id': 'sample-src-001', 'text': source}], db)
PersistentCorpusIndex(db, index).sync()
det = PlagiarismDetector(get_settings().model_copy(update={
'use_persistent_index': True, 'corpus_db_path': str(db),
'persistent_index_dir': str(index)}))
match = det.detect_request(DetectRequest(doc_id='q', text=query)).matches[0]
assert 'exact_span' in match.match_reasons
assert match.case_id == 'M1'
assert [c.case_id for c in match.case_candidates] == ['M1']