[feat] solution/backend: 발행 때 온톨로지 키워드 생성을 켠다 — 호텔 판정 · 업종별 유형어 게이트

generate:false 로 불러 새 숙소가 사전 밖 단어를 받지 못했다. 생성을 켜면 호텔이 펜션 사전의
`군산 독채펜션` 을 받는데, 메타 게이트가 '펜션' 을 업종어로 보고 자료 없이 통과시켰다.

- site_ontology: generate+sync — 처음 보는 숙소만 저쪽이 기다리게 하고 publish 상한 60초
- seo_keywords: 외부 분류(없으면 상호)에 '호텔' 이면 stay.hotel, 자기 유형어만 자료 없이 통과
- snapshot: place.external_category 를 실음 — 호텔 판정 근거
- .env.example · ARCHITECTURE · DEVLOG: ONTOLOGY_LLM_PROVIDER, 발행 흐름, 실측

test_seo_keywords 20 passed(호텔 4건 추가). 전체 1041 passed / 47 failed —
47건은 이 변경 전 main 과 같은 목록

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5.5 committed 2026-10-01 13:49:37 +09:00
1 parent 847943a8bc
commit 94c4116689
7 files changed
+86 -20

No files matched your search

+23 -12
View File
@@ -9,6 +9,9 @@ from services.external import site_ontology
from services.site_payload import _parse_address_parts
LODGING_INDUSTRY = "stay.pension"
HOTEL_INDUSTRY = "stay.hotel"
# 업종별 숙박 유형어. 자기 유형어만 자료 없이 통과한다 — 호텔에 `군산 독채펜션` 이 붙지 않게.
_TYPE_WORDS = {LODGING_INDUSTRY: "펜션", HOTEL_INDUSTRY: "호텔"}
MAX_KEYWORDS = 10
MAX_NEARBY = 8
@@ -57,9 +60,9 @@ _REGION_KEYS = {
}
# 자료에 없어도 되는 낱말 — 업종어와 "근처" 류.
_GENERIC_WORDS = frozenset({"펜션", "숙소", "숙박", "스테이", "근처", "가까운", "주변", "인근", "예약", "추천"})
_GENERIC_WORDS = frozenset({"숙소", "숙박", "스테이", "근처", "가까운", "주변", "인근", "예약", "추천"})
# "독채펜션"·"감성숙소" 처럼 붙여 쓴 업종어는 떼고 앞부분만 자료와 대조한다.
_GENERIC_SUFFIXES = ("펜션", "숙소", "스테이")
_GENERIC_SUFFIXES = ("숙소", "스테이")
# 제목에는 싣지 않는 낱말.
_TITLE_BLOCKED_WORDS = frozenset({"예약", "추천"})
# 한 글자 낱말("봄"·"뷰")은 소개문 어딘가에 우연히 들어 있어 대조가 무의미하다 — 통과시키지 않는다.
@@ -102,6 +105,12 @@ def _locality_word(*addresses: str | None) -> str:
return word[:-1] if len(word) > 2 and word.endswith(("시", "군", "구")) else word
def industry_of(place: dict) -> str:
"""외부 분류(없으면 상호)에 '호텔' 이 있으면 호텔, 아니면 펜션."""
text = f"{_text(place.get('external_category'))} {_text(place.get('name'))}"
return HOTEL_INDUSTRY if "호텔" in text else LODGING_INDUSTRY
def build_merchant(place_id: str, snapshot: dict) -> dict | None:
"""스냅샷 → SiteOntology publish 요청 본문."""
place = (snapshot or {}).get("place") or {}
@@ -157,7 +166,7 @@ def build_merchant(place_id: str, snapshot: dict) -> dict | None:
return {
"externalId": place_id,
"name": name,
"industryId": LODGING_INDUSTRY,
"industryId": industry_of(place),
"regionId": region_key(road_address, address),
"description": description,
"profile": {key: value for key, value in profile.items() if value},
@@ -174,13 +183,14 @@ def _evidence(merchant: dict) -> str:
return _compact(" ".join(_text(p) for p in parts if p))
def _supported(keyword: str, evidence: str) -> bool:
def _supported(keyword: str, evidence: str, type_word: str = "펜션") -> bool:
"""모든 낱말이 자료에 있고, **자료로 확인한 낱말이 하나는 있어야** 한다."""
suffixes = (*_GENERIC_SUFFIXES, type_word)
specific = False
for word in keyword.split():
if word in _GENERIC_WORDS:
if word in _GENERIC_WORDS or word == type_word:
continue
core = next((word[: -len(s)] for s in _GENERIC_SUFFIXES if word.endswith(s) and len(word) > len(s)), word)
core = next((word[: -len(s)] for s in suffixes if word.endswith(s) and len(word) > len(s)), word)
core = _compact(core)
if len(core) < _MIN_CORE_LEN or core not in evidence:
return False
@@ -193,15 +203,15 @@ def _is_question(item: dict) -> bool:
return item.get("category") == "질문형" or "?" in canonical or canonical.endswith(("요", "까"))
def _usable(item, evidence: str) -> str | None:
def _usable(item, evidence: str, type_word: str) -> str | None:
"""메타 태그에 실어도 되는 추천이면 그 표기를, 아니면 None."""
if not isinstance(item, dict) or item.get("status") != "ok" or _is_question(item):
return None
canonical = _text(item.get("canonical"))
return canonical if canonical and _supported(canonical, evidence) else None
return canonical if canonical and _supported(canonical, evidence, type_word) else None
def _title_keyword(result: dict, evidence: str, locality: str) -> str | None:
def _title_keyword(result: dict, evidence: str, locality: str, type_word: str) -> str | None:
"""제목 업종어 자리에 넣을 대표 키워드 — 유형 레인에서 고른다."""
lane = next(
(l for l in result.get("byLane") or [] if isinstance(l, dict) and l.get("key") == "type"),
@@ -209,7 +219,7 @@ def _title_keyword(result: dict, evidence: str, locality: str) -> str | None:
)
items = [i for i in lane.get("items") or [] if isinstance(i, dict)]
for item in sorted(items, key=lambda i: i.get("category") != "코어"):
canonical = _usable(item, evidence)
canonical = _usable(item, evidence, type_word)
if not canonical or _TITLE_BLOCKED_WORDS.intersection(canonical.split()):
continue
if locality and locality not in canonical:
@@ -221,10 +231,11 @@ def _title_keyword(result: dict, evidence: str, locality: str) -> str | None:
def select(result: dict, merchant: dict) -> dict:
"""/v1/match 응답 → {keywords, titleKeyword?}."""
evidence = _evidence(merchant)
type_word = _TYPE_WORDS.get(merchant.get("industryId"), _TYPE_WORDS[LODGING_INDUSTRY])
keywords: list[str] = []
seen: set[str] = set()
for item in result.get("matches") or []:
canonical = _usable(item, evidence)
canonical = _usable(item, evidence, type_word)
if not canonical or _compact(canonical) in seen:
continue
seen.add(_compact(canonical))
@@ -233,7 +244,7 @@ def select(result: dict, merchant: dict) -> dict:
break
seo: dict = {"keywords": keywords}
title = _title_keyword(result, evidence, _locality_word((merchant.get("profile") or {}).get("address")))
title = _title_keyword(result, evidence, _locality_word((merchant.get("profile") or {}).get("address")), type_word)
if title:
seo["titleKeyword"] = title
return seo