From 8a15148b7b9003cfc93658b34a105846d0c21cad Mon Sep 17 00:00:00 2001 From: JOUNGWOOK KWON Date: Mon, 30 Mar 2026 18:32:43 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=95=9C=EA=B5=AD=EC=96=B4=20=EC=A1=B0?= =?UTF-8?q?=EC=82=AC=20=EC=A0=9C=EA=B1=B0=EB=A1=9C=20Google=20News=20RSS?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=20=EC=A0=95=ED=99=95=EB=8F=84=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _extract_search_keywords()에서 한국어 조사/어미(을, 에서, 에서만 등)를 regex로 제거하고 키워드를 3개로 축소하여 검색 적중률 향상. Co-Authored-By: Claude Opus 4.6 --- bots/scheduler.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/bots/scheduler.py b/bots/scheduler.py index eb10edc..3908e9d 100644 --- a/bots/scheduler.py +++ b/bots/scheduler.py @@ -922,16 +922,29 @@ async def cmd_idea(update: Update, context: ContextTypes.DEFAULT_TYPE): def _extract_search_keywords(text: str) -> str: - """긴 문장에서 검색용 핵심 키워드 추출 (3~5개 명사/키워드)""" - # 불용어 제거 - stopwords = {'을', '를', '이', '가', '은', '는', '에', '의', '로', '으로', '에서', '와', '과', - '대한', '위한', '대해', '관한', '통한', '있는', '없는', '하는', '되는', '하고', - '그', '이런', '저런', '어떤', '모든', '같은', '다른', '라는', '라고', - '글', '글을', '내용', '정보', '상황', '경우', '부분', '반대'} - # 단어 분리 후 불용어 제거, 1글자 제외 - words = [w for w in text.split() if w not in stopwords and len(w) > 1] - # 최대 5개 키워드 - return ' '.join(words[:5]) + """긴 문장에서 검색용 핵심 키워드 추출 (2~3개 핵심 명사)""" + import re as _re + # 한국어 조사/어미 패턴 제거 (단어 끝에서) + particle_pattern = _re.compile( + r'(에서만|에서는|에서도|으로는|에서|에게|부터|까지|처럼|보다|만큼|이라|이고|이며|에는|으로|에도|하는|되는|있는|없는|해야|봐야|' + r'이란|라는|라고|에서|하고|해서|지만|는데|인데|이나|거나|든지|이든|에의|과의|와의|' + r'을|를|이|가|은|는|에|의|로|와|과|도|만|요|죠|건|한|된|할|인)$' + ) + # 불용어 (조사 제거 후 남는 단어 기준) + stopwords = {'대한', '위한', '대해', '관한', '통한', '그', '이런', '저런', '어떤', '모든', + '같은', '다른', '글', '내용', '정보', '상황', '경우', '부분', '반대', '의견', + '특정', '모두', '우리', '어떻게', '왜'} + words = [] + for w in text.split(): + # 조사 제거 + clean = particle_pattern.sub('', w) + if not clean or len(clean) < 2: + continue + if clean in stopwords: + continue + words.append(clean) + # 최대 3개 핵심 키워드 (짧을수록 검색 결과 多) + return ' '.join(words[:3]) def _search_and_build_topic(keyword: str, corner: str = '') -> dict: