feat(jamie-journal): implement StructureValidator (5-step body, opening, CTA, disclaimer)
This commit is contained in:
@@ -43,8 +43,130 @@ class ValidationIssue:
|
|||||||
class StructureValidator:
|
class StructureValidator:
|
||||||
"""Validates document structure (headings, sections, word count, etc.)."""
|
"""Validates document structure (headings, sections, word count, etc.)."""
|
||||||
|
|
||||||
|
OPENING = "안녕하세요. 제이미성형외과 정기호 원장입니다."
|
||||||
|
|
||||||
|
STEP_KEYWORDS = {
|
||||||
|
'problem': ['고민', '증상', '불편', '걱정', '힘드', '어려움'],
|
||||||
|
'cause': ['원인', '발생', '때문에', '이유', '구조적', '해부학적'],
|
||||||
|
'solution': ['시술', '수술', '방법', '제이미', '교정', '개선법'],
|
||||||
|
'advantages': ['장점', '회복', '흉터', '통증', '마취', '보장', 'AS'],
|
||||||
|
'results': ['결과', '효과', '기대', '개선', '자연스러', '만족'],
|
||||||
|
}
|
||||||
|
|
||||||
|
STEP_NAMES = {
|
||||||
|
'problem': '문제 제기 (공감)',
|
||||||
|
'cause': '원인 설명 (교육)',
|
||||||
|
'solution': '해결책 제시 (제이미의 방법)',
|
||||||
|
'advantages': '장점 나열 (차별점)',
|
||||||
|
'results': '기대 효과 (비전)',
|
||||||
|
}
|
||||||
|
|
||||||
|
MEDICAL_NOUNS = ['안검하수', '내시경', '거상술', '눈매교정', '매몰법', '절개법']
|
||||||
|
MEDICAL_TERM_PATTERN = re.compile(r'[가-힣]+\([一-龥々〇]+,\s*[A-Za-z\s\-]+\)')
|
||||||
|
|
||||||
|
CTA_PATTERNS = [
|
||||||
|
re.compile(r'상담을?\s*(추천|받아|예약)'),
|
||||||
|
re.compile(r'제이미성형외과.{0,20}(상담|문의)'),
|
||||||
|
re.compile(r'편안한\s*마음으로\s*상담'),
|
||||||
|
]
|
||||||
|
|
||||||
|
DISCLAIMER_FRAGMENTS = ['부작용', '출혈', '감염', '의료진과 상담']
|
||||||
|
|
||||||
def check(self, content: str) -> List[ValidationIssue]:
|
def check(self, content: str) -> List[ValidationIssue]:
|
||||||
return []
|
issues: List[ValidationIssue] = []
|
||||||
|
|
||||||
|
# 1. Opening format
|
||||||
|
if self.OPENING not in content:
|
||||||
|
issues.append(ValidationIssue(
|
||||||
|
checker='StructureValidator',
|
||||||
|
issue_type='missing_opening',
|
||||||
|
severity='high',
|
||||||
|
line_number=1,
|
||||||
|
matched_text='',
|
||||||
|
message=f'표준 인사말이 없습니다: "{self.OPENING}"',
|
||||||
|
suggestion=f'글 첫 줄을 "{self.OPENING}"으로 시작하세요.',
|
||||||
|
))
|
||||||
|
|
||||||
|
# 2. 5-step body structure
|
||||||
|
detected_steps = []
|
||||||
|
for step_key, keywords in self.STEP_KEYWORDS.items():
|
||||||
|
for kw in keywords:
|
||||||
|
if kw in content:
|
||||||
|
detected_steps.append(step_key)
|
||||||
|
break
|
||||||
|
|
||||||
|
missing_steps = [s for s in self.STEP_KEYWORDS if s not in detected_steps]
|
||||||
|
num_missing = len(missing_steps)
|
||||||
|
|
||||||
|
if num_missing >= 2:
|
||||||
|
missing_names = ', '.join(self.STEP_NAMES[s] for s in missing_steps)
|
||||||
|
issues.append(ValidationIssue(
|
||||||
|
checker='StructureValidator',
|
||||||
|
issue_type='incomplete_body_structure',
|
||||||
|
severity='high',
|
||||||
|
line_number=1,
|
||||||
|
matched_text='',
|
||||||
|
message=f'5단계 본문 구조에서 {num_missing}개 단계가 감지되지 않았습니다: {missing_names}',
|
||||||
|
suggestion='본문에 문제 제기, 원인 설명, 해결책 제시, 장점 나열, 기대 효과 섹션을 모두 포함하세요.',
|
||||||
|
))
|
||||||
|
elif num_missing == 1:
|
||||||
|
missing_names = self.STEP_NAMES[missing_steps[0]]
|
||||||
|
issues.append(ValidationIssue(
|
||||||
|
checker='StructureValidator',
|
||||||
|
issue_type='incomplete_body_structure',
|
||||||
|
severity='medium',
|
||||||
|
line_number=1,
|
||||||
|
matched_text='',
|
||||||
|
message=f'5단계 본문 구조에서 1개 단계가 감지되지 않았습니다: {missing_names}',
|
||||||
|
suggestion=f'"{missing_names}" 섹션에 해당하는 내용을 추가하세요.',
|
||||||
|
))
|
||||||
|
|
||||||
|
# 3. Medical term format
|
||||||
|
has_medical_noun = any(noun in content for noun in self.MEDICAL_NOUNS)
|
||||||
|
if has_medical_noun and not self.MEDICAL_TERM_PATTERN.search(content):
|
||||||
|
issues.append(ValidationIssue(
|
||||||
|
checker='StructureValidator',
|
||||||
|
issue_type='missing_medical_term_format',
|
||||||
|
severity='medium',
|
||||||
|
line_number=1,
|
||||||
|
matched_text='',
|
||||||
|
message='의학 용어가 포함되어 있으나 한자/영문 병기 형식이 없습니다.',
|
||||||
|
suggestion='예: "안검하수(眼瞼下垂, Ptosis)는 ..." 형식으로 첫 의학 용어를 병기하세요.',
|
||||||
|
))
|
||||||
|
|
||||||
|
# 4. Closing CTA (last 20% of content)
|
||||||
|
tail_start = max(0, int(len(content) * 0.8))
|
||||||
|
tail_content = content[tail_start:]
|
||||||
|
has_cta = any(p.search(tail_content) for p in self.CTA_PATTERNS)
|
||||||
|
if not has_cta:
|
||||||
|
total_lines = content.count('\n') + 1
|
||||||
|
issues.append(ValidationIssue(
|
||||||
|
checker='StructureValidator',
|
||||||
|
issue_type='missing_closing_cta',
|
||||||
|
severity='medium',
|
||||||
|
line_number=total_lines,
|
||||||
|
matched_text='',
|
||||||
|
message='글 마지막 20% 구간에 상담 유도(CTA) 문구가 없습니다.',
|
||||||
|
suggestion='"지금 바로 제이미성형외과의 [시술명] 상담을 추천드립니다." 형식의 CTA를 추가하세요.',
|
||||||
|
))
|
||||||
|
|
||||||
|
# 5. Required disclaimer (last 30% of content)
|
||||||
|
disclaimer_start = max(0, int(len(content) * 0.7))
|
||||||
|
disclaimer_content = content[disclaimer_start:]
|
||||||
|
found_fragments = [f for f in self.DISCLAIMER_FRAGMENTS if f in disclaimer_content]
|
||||||
|
if len(found_fragments) < 2:
|
||||||
|
total_lines = content.count('\n') + 1
|
||||||
|
issues.append(ValidationIssue(
|
||||||
|
checker='StructureValidator',
|
||||||
|
issue_type='missing_disclaimer',
|
||||||
|
severity='high',
|
||||||
|
line_number=total_lines,
|
||||||
|
matched_text='',
|
||||||
|
message='글 하단에 부작용 고지 면책 문구가 불충분합니다 (부작용, 출혈, 감염, 의료진과 상담 중 2개 이상 필요).',
|
||||||
|
suggestion='"개인에 따라 부작용(출혈, 감염, 염증 등)이 있을 수 있으니 사전에 의료진과 상담 후 결정하시기 바랍니다." 문구를 추가하세요.',
|
||||||
|
))
|
||||||
|
|
||||||
|
return issues
|
||||||
|
|
||||||
|
|
||||||
class ComplianceChecker:
|
class ComplianceChecker:
|
||||||
|
|||||||
Reference in New Issue
Block a user