Skip to content

[Fix] 공지사항 크롤링 오류#46

Merged
kimssirr merged 2 commits into
devfrom
fix/#45
May 11, 2026
Merged

[Fix] 공지사항 크롤링 오류#46
kimssirr merged 2 commits into
devfrom
fix/#45

Conversation

@kimssirr

Copy link
Copy Markdown
Contributor

작업 내용

공지 수집/요약 과정에서 본문과 요약 정보가 의도와 다르게 저장되는 문제를 수정했습니다.

변경 사항 (있다면)

  • 공지 상세 본문 파싱 시 inline 태그로 쪼개진 텍스트가 불필요하게 줄바꿈 저장되지 않도록 수정
  • 공지 요약의 schedule_info, caution_info가 구조화 키가 아닌 사용자에게 바로 보여줄 수 있는 문자열로 저장되도록 후처리 보완
  • 본문 파싱 및 요약 후처리 재발 방지 테스트 추가

리뷰 포인트

  • 공지 본문 파싱 결과가 기존 메타데이터 제거 로직을 유지하면서도 문장 조각을 자연스럽게 합치는지
  • schedule_info, caution_info가 DB에 문자열 형태로 저장되는 방식이 서비스 응답 요구사항과 맞는지

테스트

  • 로컬 실행 확인
  • /docs 수동 확인
  • pytest 실행

@kimssirr kimssirr added the fix 기능을 수정합니다. label May 11, 2026
@kimssirr kimssirr merged commit 2745cf6 into dev May 11, 2026
1 check passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the notice crawling and summarization logic by refining text extraction from HTML and adding specific formatting rules for LLM-generated summaries. Key changes include a new _extract_detail_text_lines function to preserve block boundaries and updated LLM prompts to ensure consistent string output for schedule and caution information. Review feedback identified a potential data loss issue in the HTML text extraction logic where text nodes in parent elements might be skipped. Additionally, improvements were suggested for the _format_caution_info function to strictly exclude dictionary keys, and a typo in the LLM prompt was noted.

Comment on lines +196 to +215
text_lines: list[str] = []

for element in soup.find_all(DETAIL_TEXT_BLOCK_TAGS):
if element.find(DETAIL_TEXT_BLOCK_TAGS):
continue

text = _normalize_text(element.get_text(" ", strip=True))
if not text:
continue

text_lines.append(text)

if text_lines:
return text_lines

return [
_normalize_text(line)
for line in soup.get_text("\n", strip=True).splitlines()
if _normalize_text(line)
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

현재 구현된 _extract_detail_text_lines 로직은 데이터 유실 위험이 있습니다. element.find(DETAIL_TEXT_BLOCK_TAGS)를 통해 자식 블록 요소가 있는 부모 요소를 건너뛰게 되면, 부모 요소의 직접적인 자식인 텍스트 노드들이 무시됩니다.

예를 들어 <div>본문 시작 <p>중간 내용</p> 본문 끝</div>과 같은 구조에서 "본문 시작"과 "본문 끝"은 유실되고 "중간 내용"만 추출됩니다. 블록 요소들에 명시적으로 개행 문자를 삽입한 뒤 텍스트를 추출하는 방식이 더 안전하고 의도한 대로 인라인 태그들을 합칠 수 있습니다.

    for element in soup.find_all(DETAIL_TEXT_BLOCK_TAGS):
        element.append("\n")

    text = soup.get_text(" ", strip=True)
    return [
        _normalize_text(line)
        for line in text.splitlines()
        if _normalize_text(line)
    ]

Comment on lines +49 to +50
def _format_caution_info(value) -> str:
return _to_text(value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

_format_caution_info가 사용하는 _to_text는 딕셔너리 처리 시 키 이름을 포함합니다 (예: {"caution": "..."} -> "caution: ..."). 이는 72번 라인의 프롬프트 지침("caution, warning 같은 키 이름을 내용에 포함하지 마")과 충돌할 수 있습니다. LLM이 지침을 어기고 객체 형태로 응답할 경우를 대비해, _format_schedule_info처럼 키를 제외하고 값만 추출하도록 개선하는 것이 좋습니다.

def _format_caution_info(value) -> str:
    if value is None:
        return ""

    if isinstance(value, str):
        return value.strip()

    if isinstance(value, list):
        return "\n".join(text for item in value if (text := _format_caution_info(item)))

    if isinstance(value, dict):
        return "\n".join(text for val in value.values() if (text := _format_caution_info(val)))

    return str(value)

- 반드시 문자열 또는 null로 반환해. 객체나 배열로 반환하지 마.
- date, details 같은 키 이름을 내용에 포함하지 마.
- 요일과 시간만 적어. 양식은 ####년 ##월 ##일, 시간은 오전 또는 오후 #시 이렇게.
- 생활관 별로 시간이 다르면 생활간 별 시간으로 적어.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

프롬프트 내에 오타가 있습니다. 생활간생활관으로 수정하는 것이 좋습니다. LLM이 문맥상 이해할 수는 있겠지만, 정확한 용어 전달이 요약 품질 유지에 도움이 됩니다.

Suggested change
- 생활관 별로 시간이 다르면 생활간 시간으로 적어.
- 생활관 별로 시간이 다르면 생활관 시간으로 적어.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 기능을 수정합니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant