저작권 탭 UI 매핑(review_summary) + AI 생성 의심도 스텁 추가

나누구 앱 저작권 탭 연동을 위해 detect 응답에 두 블록 추가:
- review_summary: 독창성%/유사도%/유사문장 건수/대조 건수/의심 유무/AI 의심도
  (독창성 환산 캘리브레이션 포함 — 무관한 글은 유사도 0~5%로 눌러 표시)
- ai_generation: AI 생성 의심도 스텁(요청마다 더미, is_stub=true).
  워터마킹+언어특징 분류 정식 구현 전까지 계약 확정용.

바이칼 연동용 API 양식서(docs/API_SPEC_BAIKAL.md) 추가.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 4.8 committed 2026-08-04 13:15:07 +09:00
1 parent e522fae7eb
commit fefb393234
3 files changed
+291

No files matched your search

+47
View File
@@ -18,6 +18,7 @@ from datetime import datetime, timezone
from app.api.schemas import (
TAG_LABEL_KO,
AiGenerationSignal,
DetectOptions,
DetectRequest,
DetectResponse,
@@ -26,6 +27,7 @@ from app.api.schemas import (
InfringementType,
MatchResult,
PartialPlagiarismSignal,
ReviewSummary,
ScoreBreakdown,
)
from app.core.config import Settings, get_settings
@@ -163,6 +165,18 @@ class PlagiarismDetector:
is_infringement = bool(matches)
ccl_basis = self._build_ccl_basis(matches) if is_infringement else None
# 저작권 탭 UI 매핑 (나누구 앱). 독창성=100-유사도, AI 의심도는 현재 스텁.
ai_signal = _dummy_ai_generation_signal(text)
sim_pct = _calibrate_similarity(confidence, threshold)
review = ReviewSummary(
originality_percent=100 - sim_pct,
similarity_percent=sim_pct,
similar_sentence_count=len(matches),
compared_count=self.corpus_size,
has_suspicion=is_infringement,
ai_suspicion_level=ai_signal.suspicion_level,
)
return DetectResponse(
doc_id=doc_id,
is_infringement=is_infringement,
@@ -170,6 +184,8 @@ class PlagiarismDetector:
extracted_elements=elements,
matches=matches,
ccl_basis=ccl_basis,
review_summary=review,
ai_generation=ai_signal,
autobiography_mode=autobio_mode,
candidates_before_filter=candidates_count,
engine_version=self.settings.engine_version,
@@ -297,6 +313,37 @@ class PlagiarismDetector:
)
def _calibrate_similarity(raw: float, threshold: float) -> int:
"""결합 유사도(0~1) → 사용자 표시용 '유사도 %' 캘리브레이션.
임베딩 성분 때문에 무관한 글도 raw 0.5 전후가 나오므로, 그대로 %로 쓰면
깨끗한 글이 '유사도 50%'로 보인다. 아래 구간 변환으로 무관한 글은 0~5%,
임계 초과(실제 표절)만 40% 이상으로 눌러준다.
"""
floor = 0.55 # 무관한 글의 전형적 결합 유사도 상한
if raw <= floor:
disp = (raw / floor) * 5.0 if floor else 0.0
elif raw <= threshold:
disp = 5.0 + (raw - floor) / max(1e-6, threshold - floor) * 35.0
else:
disp = 40.0 + (raw - threshold) / max(1e-6, 1.0 - threshold) * 60.0
return max(0, min(100, round(disp)))
def _dummy_ai_generation_signal(text: str) -> AiGenerationSignal:
"""AI 생성 의심도 스텁 — 실제 판별이 아니라 텍스트 기반 결정적 더미 값.
바이칼 UI(낮음/중간/높음 배지) 연동용 계약 확정 목적. 정식 구현(워터마킹+
언어특징 분류) 전까지 is_stub=True 로 반환한다.
"""
h = sum(ord(c) for c in text[:300]) % 100
if h < 70:
return AiGenerationSignal(suspicion_level="low", score=round(0.05 + h / 500, 3))
if h < 90:
return AiGenerationSignal(suspicion_level="medium", score=round(0.45 + (h - 70) / 200, 3))
return AiGenerationSignal(suspicion_level="high", score=round(0.72 + (h - 90) / 200, 3))
def _classify_legacy(hit: SimilarityHit) -> InfringementType:
"""후방 호환 - 단일 enum 분류 (UI/기존 통합 코드용)."""
elem = hit.element_sim