feat: 전체 판례 검색과 판례 탭 추가
This commit is contained in:
1 parent
fa15117df7
commit
5386222f1b
11 files changed
+443
-44
No files matched your search
@@ -181,6 +181,10 @@ class PlagiarismDetector:
|
||||
def precedent_count(self) -> int:
|
||||
return len(self._legal_engine.precedents)
|
||||
|
||||
@property
|
||||
def precedents(self):
|
||||
return tuple(self._legal_engine.precedents)
|
||||
|
||||
@property
|
||||
def ai_model_ready(self) -> bool:
|
||||
return self._ai_detector.mode == "trained"
|
||||
@@ -333,6 +337,7 @@ class PlagiarismDetector:
|
||||
}
|
||||
for m in matches[:5]
|
||||
],
|
||||
query_text=text,
|
||||
)
|
||||
|
||||
# AI 탐지는 전처리 전 raw text에서만 실행한다.
|
||||
|
||||
+85
-21
@@ -8,6 +8,8 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import math
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Iterable, Protocol
|
||||
@@ -92,14 +94,69 @@ class LegalJudge(Protocol):
|
||||
def judge(self, request: LegalJudgeInput) -> LegalJudgeDecision: ...
|
||||
|
||||
|
||||
#: 인용 우선순위. A/B/C는 모두 사람이 판시 본문을 확인해 최종 리스트업한
|
||||
#: 판례다. 등급이 없는 적재본은 리스트업 제외 대상이므로, 등급 데이터가 하나라도
|
||||
#: 있는 운영 코퍼스에서는 인용 후보로 사용하지 않는다.
|
||||
_GRADE_ORDER = {"A": 0, "B": 1, "C": 2}
|
||||
_TOKEN_RE = re.compile(r"[가-힣A-Za-z0-9]{2,}")
|
||||
_TOKEN_STOPWORDS = {
|
||||
"그리고", "그러나", "대한", "관한", "있는", "없는", "으로", "에서",
|
||||
"판결", "사건", "원고", "피고", "저작권", "저작물", "경우", "해당",
|
||||
}
|
||||
_KOREAN_SUFFIXES = ("에서는", "으로", "에서", "에게", "까지", "부터", "처럼", "보다", "은", "는", "이", "가", "을", "를", "과", "와", "의", "에", "로")
|
||||
_GRADE_BOOST = {"A": 0.05, "B": 0.035, "C": 0.015}
|
||||
_SOFTWARE_MARKERS = ("컴퓨터프로그램", "폰트파일", "글꼴파일", "글꼴 파일", "서체프로그램")
|
||||
|
||||
|
||||
def _grade_rank(grade: str | None) -> int:
|
||||
return _GRADE_ORDER.get(grade or "", len(_GRADE_ORDER))
|
||||
def _tokens(text: str) -> set[str]:
|
||||
tokens: set[str] = set()
|
||||
for raw in _TOKEN_RE.findall(text):
|
||||
token = raw.lower()
|
||||
if token in _TOKEN_STOPWORDS:
|
||||
continue
|
||||
tokens.add(token)
|
||||
for suffix in _KOREAN_SUFFIXES:
|
||||
if token.endswith(suffix) and len(token) >= len(suffix) + 2:
|
||||
tokens.add(token[:-len(suffix)])
|
||||
break
|
||||
return tokens
|
||||
|
||||
|
||||
def _normalized_work_types(raw: dict) -> tuple[str, ...]:
|
||||
"""수집 라벨의 명백한 오분류를 판시 제목 기준으로 보정한다.
|
||||
|
||||
폰트 프로그램 사건 3건은 literary/visual로 수집돼 문학 판례 검색에 섞였다.
|
||||
원천 레코드는 보존하되 엔진과 조회 API에서는 software로 취급한다.
|
||||
"""
|
||||
title = str(raw.get("title", "")).replace(" ", "")
|
||||
if any(marker.replace(" ", "") in title for marker in _SOFTWARE_MARKERS):
|
||||
return ("software",)
|
||||
return tuple(raw.get("work_types", []))
|
||||
|
||||
|
||||
def _precedent_score(
|
||||
precedent: Precedent,
|
||||
*,
|
||||
tags: set[str],
|
||||
work_type: str,
|
||||
query_terms: set[str],
|
||||
) -> float:
|
||||
"""유형·법적 쟁점·판시 내용 관련성을 중심으로 한 결정적 검색 점수."""
|
||||
tag_overlap = len(tags.intersection(precedent.legal_tags))
|
||||
tag_score = tag_overlap / max(len(tags), 1)
|
||||
precedent_terms = _tokens(" ".join([
|
||||
precedent.title, *precedent.criteria, precedent.holding_summary,
|
||||
]))
|
||||
# 긴 판시문 때문에 관련 어휘가 희석되지 않도록 질의 쪽 포함률을 사용한다.
|
||||
text_score = len(query_terms.intersection(precedent_terms)) / max(len(query_terms), 1)
|
||||
criteria_terms = _tokens(" ".join(precedent.criteria))
|
||||
criteria_score = len(query_terms.intersection(criteria_terms)) / max(len(query_terms), 1)
|
||||
type_score = 1.0 if work_type in precedent.work_types else 0.5
|
||||
quality_score = min(math.log1p(len(precedent.holding_summary)) / 10.0, 1.0)
|
||||
return (
|
||||
0.55 * tag_score
|
||||
+ 0.20 * text_score
|
||||
+ 0.10 * criteria_score
|
||||
+ 0.08 * type_score
|
||||
+ 0.02 * quality_score
|
||||
+ _GRADE_BOOST.get(precedent.grade or "", 0.0)
|
||||
)
|
||||
|
||||
|
||||
def load_precedents(path: str | Path) -> list[Precedent]:
|
||||
@@ -126,7 +183,7 @@ def load_precedents(path: str | Path) -> list[Precedent]:
|
||||
case_id=case_id,
|
||||
title=str(raw["title"]),
|
||||
source_url=str(raw["source_url"]),
|
||||
work_types=tuple(raw.get("work_types", [])),
|
||||
work_types=_normalized_work_types(raw),
|
||||
legal_tags=tuple(raw.get("legal_tags", [])),
|
||||
criteria=tuple(raw.get("criteria", [])),
|
||||
holding_summary=str(raw["holding_summary"]),
|
||||
@@ -140,9 +197,6 @@ class LegalRiskEngine:
|
||||
def __init__(self, precedents: Iterable[Precedent], judge: LegalJudge | None = None):
|
||||
self.precedents = list(precedents)
|
||||
self.judge = judge
|
||||
# 등급 반영 전의 외부/테스트 코퍼스는 계속 동작시키되, 등급을 반영한 운영
|
||||
# 코퍼스는 최종 리스트업(A/B/C)을 명시적인 allowlist로 취급한다.
|
||||
self._has_reviewed_precedents = any(p.grade in _GRADE_ORDER for p in self.precedents)
|
||||
|
||||
def assess(
|
||||
self,
|
||||
@@ -156,19 +210,29 @@ class LegalRiskEngine:
|
||||
protected_expression_reviewed: bool = False,
|
||||
rights_verified: bool = False,
|
||||
evidence: Iterable[dict] = (),
|
||||
query_text: str = "",
|
||||
) -> LegalRiskAssessment:
|
||||
tags = set(legal_tags)
|
||||
related = sorted([
|
||||
evidence_rows = tuple(evidence)
|
||||
search_text = " ".join([
|
||||
query_text,
|
||||
*(str(excerpt) for row in evidence_rows for excerpt in row.get("excerpts", [])),
|
||||
*(str(row.get("infringement_type", "")) for row in evidence_rows),
|
||||
])
|
||||
query_terms = _tokens(search_text)
|
||||
candidates = [
|
||||
p for p in self.precedents
|
||||
if (not self._has_reviewed_precedents or p.grade in _GRADE_ORDER)
|
||||
and (not p.work_types or work_type in p.work_types)
|
||||
and (not p.legal_tags or tags.intersection(p.legal_tags))
|
||||
], key=lambda p: (
|
||||
_grade_rank(p.grade),
|
||||
-len(tags.intersection(p.legal_tags)),
|
||||
0 if work_type in p.work_types else 1,
|
||||
p.case_id,
|
||||
))[:5]
|
||||
if (not p.work_types or work_type in p.work_types)
|
||||
]
|
||||
related = sorted(
|
||||
candidates,
|
||||
key=lambda p: (
|
||||
-_precedent_score(
|
||||
p, tags=tags, work_type=work_type, query_terms=query_terms,
|
||||
),
|
||||
p.case_id,
|
||||
),
|
||||
)[:5]
|
||||
missing: list[str] = []
|
||||
if not protected_expression_reviewed:
|
||||
missing.append("보호되는 창작적 표현인지에 대한 사람 검토")
|
||||
@@ -217,7 +281,7 @@ class LegalRiskEngine:
|
||||
access_evidence=access_evidence,
|
||||
protected_expression_reviewed=protected_expression_reviewed,
|
||||
rights_verified=rights_verified,
|
||||
evidence=tuple(evidence),
|
||||
evidence=evidence_rows,
|
||||
precedents=tuple(related),
|
||||
deterministic_missing_factors=tuple(missing),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user