feat: return exception code F1 for unclassified matches

매칭은 있지만 원고 점검 18항목을 정하지 못하면 case_id 를 null 대신 F1(미분류)로
낸다. case_candidates 에 F1 후보를 넣고, 정하지 못한 이유(분류 체계 미로드 /
주 태그 없음 / 판별 대상 항목과 겹치지 않음)를 지점별 reason 으로 남긴다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaehwangandClaude Opus 5.5 committed 2026-10-29 15:20:28 +09:00
1 parent 03d500d67c
commit 7094d80566
3 files changed
+108 -8

No files matched your search

+51 -6
View File
@@ -57,6 +57,11 @@ from app.engine.taxonomy import CaseDef, Taxonomy, load_taxonomy
logger = logging.getLogger(__name__)
#: 원고 점검 항목을 정하지 못한 매칭에 붙이는 예외 코드. 분류 체계의 항목이
#: 아니므로 /v1/taxonomy 에는 없고, 정하지 못한 이유는 후보의 reason 에 남긴다.
UNCLASSIFIED_CASE_ID = "F1"
UNCLASSIFIED_CASE_TITLE = "미분류"
class PlagiarismDetector:
#: 참조 특징 프로세스 캐시 상한. 초과하면 통째로 비운다(단순 LRU 대용).
@@ -629,14 +634,16 @@ class PlagiarismDetector:
)
for c in cases
]
if not candidates:
candidates = [self._unclassified_candidate(self.taxonomy, primary_tags, hit)]
return MatchResult(
source_doc=hit.doc_id,
source_title=hit.title,
similarity=round(hit.score, 4),
tags=tags,
case_id=cases[0].case_id if cases else None,
case_title=cases[0].title if cases else None,
case_id=candidates[0].case_id,
case_title=candidates[0].title,
case_candidates=candidates,
publication_verdict_status=("review_required" if any(
c.publication_verdict is not None for c in candidates
@@ -658,11 +665,8 @@ class PlagiarismDetector:
tie: tuple[CaseDef, ...]) -> str:
"""관리자 콘솔에 표시할 분류 사유. 엔진 신호 → 겹친 태그 → 항목 판단 기준 순."""
matched = "·".join(TAG_LABEL_KO[t] for t in primary_tags if t in case.primary_tags)
signal = (f"text={hit.text_sim:.2f} / lemma={hit.lemma_sim:.2f} / "
f"char={hit.element_sim.get('characters', 0.0):.2f} / "
f"motif={hit.element_sim.get('motifs', 0.0):.2f}")
reason = (f"엔진 주 태그 {matched}이(가) {case.case_id}({case.title})의 태그와 "
f"일치합니다 [{signal}].")
f"일치합니다 [{_score_signal(hit)}].")
if len(tie) > 1:
ids = ", ".join(c.case_id for c in tie)
reason += (f" 텍스트만으로는 {ids} 중 하나로 좁혀지지 않으므로 작성자 관계"
@@ -673,6 +677,37 @@ class PlagiarismDetector:
reason += " (이 항목의 태그 매핑은 추정치로, 컴북스 확인 전입니다.)"
return reason
@staticmethod
def _unclassified_candidate(taxonomy: Taxonomy | None, primary_tags: list[str],
hit: SimilarityHit) -> CaseCandidate:
"""항목을 정하지 못한 매칭의 F1 후보. 사유는 정하지 못한 지점마다 다르다.
- 분류 체계 미로드 → 설정 확인 필요
- 주 태그 없음(_assign_tags 의 마지막 분기) → 사람이 항목 지정
- 주 태그는 있으나 판별 대상 항목과 겹치지 않음 → 사람이 항목 지정
"""
signal = _score_signal(hit)
if taxonomy is None:
reason = (f"분류 체계를 불러오지 못해 원고 점검 항목을 매기지 못했습니다 "
f"[{signal}]. 서버의 TAXONOMY_DIR 설정을 확인해야 합니다.")
elif not primary_tags:
reason = (f"엔진이 주 태그를 내지 못해 원고 점검 항목 중 대응되는 항목이 "
f"없습니다 [{signal}]. 일치 구간과 원본 종류를 확인해 항목을 "
"사람이 지정해야 합니다.")
else:
matched = "·".join(TAG_LABEL_KO[t] for t in primary_tags)
targets = "·".join(c.case_id for c in taxonomy.cases if c.detectable_internal)
reason = (f"엔진 주 태그 {matched}이(가) 엔진 판별 대상 항목({targets})과 "
f"충분히 겹치지 않습니다 [{signal}]. 일치 구간과 원본 종류를 확인해 "
"항목을 사람이 지정해야 합니다.")
return CaseCandidate(
case_id=UNCLASSIFIED_CASE_ID,
title=UNCLASSIFIED_CASE_TITLE,
handling="terms_or_report",
precedent_note="분류 미확정이라 대표판례를 지정하지 않습니다.",
reason=reason,
)
def _assign_tags(self, hit: SimilarityHit, legacy: InfringementType,
exact_span: bool = False) -> list[InfringementTag]:
"""삼중 유사도 분포 → 10종 법령 태그(주/보조) 매핑.
@@ -768,6 +803,9 @@ class PlagiarismDetector:
ids = ", ".join(c.case_id for c in top.case_candidates)
case_part = (f" 추정 분류 후보 {ids} — 태그만으로는 구별되지 않으므로 "
f"작성자 관계와 원본 종류를 확인해 확정해야 합니다.")
elif top.case_id == UNCLASSIFIED_CASE_ID:
case_part = (f" 분류 미확정({UNCLASSIFIED_CASE_ID}) — 원본 종류와 일치 구간을 "
"확인해 항목을 지정해야 합니다.")
elif top.case_id:
case_part = f" 추정 분류 {top.case_id} ({top.case_title})."
else:
@@ -796,6 +834,13 @@ def _calibrate_similarity(raw: float, threshold: float) -> int:
return max(0, min(100, round(disp)))
def _score_signal(hit: SimilarityHit) -> str:
"""분류 사유에 붙이는 유사도 성분 요약."""
return (f"text={hit.text_sim:.2f} / lemma={hit.lemma_sim:.2f} / "
f"char={hit.element_sim.get('characters', 0.0):.2f} / "
f"motif={hit.element_sim.get('motifs', 0.0):.2f}")
def _classify_legacy(hit: SimilarityHit) -> InfringementType:
"""후방 호환 - 단일 enum 분류 (UI/기존 통합 코드용)."""
elem = hit.element_sim