release
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# app/utils/category_utils.py (수정된 버전)
|
||||
# app/utils/category_utils.py
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
@@ -98,37 +98,6 @@ def extract_main_category(category_name: str) -> str:
|
||||
|
||||
return ""
|
||||
|
||||
def build_search_query(region: str, food_category: str) -> str:
|
||||
"""
|
||||
검색 쿼리를 구성합니다. (수정된 버전 - 지역 정보 제외)
|
||||
|
||||
Args:
|
||||
region: 지역 (사용하지 않음)
|
||||
food_category: 음식 카테고리
|
||||
|
||||
Returns:
|
||||
검색 쿼리 문자열 (음식 카테고리만 포함)
|
||||
"""
|
||||
# 콤마와 슬래시를 공백으로 변경하여 검색 키워드 생성
|
||||
search_keywords = food_category.replace(',', ' ').replace('/', ' ')
|
||||
|
||||
# 불필요한 단어 제거
|
||||
stop_words = ['음식점', '요리', '전문점', '맛집']
|
||||
keywords = []
|
||||
|
||||
for keyword in search_keywords.split():
|
||||
keyword = keyword.strip()
|
||||
if keyword and keyword not in stop_words:
|
||||
keywords.append(keyword)
|
||||
|
||||
# 키워드가 없으면 기본 검색어 사용
|
||||
if not keywords:
|
||||
keywords = ['음식점']
|
||||
|
||||
# 🔧 지역 정보는 포함하지 않고 음식 키워드만 반환
|
||||
query = ' '.join(keywords)
|
||||
return query.strip()
|
||||
|
||||
def clean_food_category_for_search(food_category: str) -> str:
|
||||
"""
|
||||
음식 카테고리를 검색용 키워드로 정리합니다.
|
||||
@@ -158,4 +127,4 @@ def clean_food_category_for_search(food_category: str) -> str:
|
||||
if not keywords:
|
||||
return "음식점"
|
||||
|
||||
return ' '.join(keywords)
|
||||
return ' '.join(keywords)
|
||||
@@ -52,59 +52,46 @@ def generate_review_summary(reviews: List[Dict[str, Any]]) -> Dict[str, Any]:
|
||||
if not reviews:
|
||||
return {
|
||||
"total_reviews": 0,
|
||||
"average_rating": 0.0,
|
||||
"average_rating": 0,
|
||||
"rating_distribution": {},
|
||||
"common_keywords": [],
|
||||
"sentiment_summary": {
|
||||
"positive": 0,
|
||||
"neutral": 0,
|
||||
"negative": 0
|
||||
}
|
||||
"total_likes": 0,
|
||||
"common_keywords": []
|
||||
}
|
||||
|
||||
# 기본 통계
|
||||
# 기본 통계 계산
|
||||
total_reviews = len(reviews)
|
||||
ratings = [review.get('rating', 0) for review in reviews if review.get('rating', 0) > 0]
|
||||
average_rating = sum(ratings) / len(ratings) if ratings else 0.0
|
||||
total_rating = sum(review.get('rating', 0) for review in reviews)
|
||||
average_rating = total_rating / total_reviews if total_reviews > 0 else 0
|
||||
total_likes = sum(review.get('likes', 0) for review in reviews)
|
||||
|
||||
# 별점 분포
|
||||
# 별점 분포 계산
|
||||
rating_distribution = {}
|
||||
for rating in ratings:
|
||||
rating_distribution[str(rating)] = rating_distribution.get(str(rating), 0) + 1
|
||||
for review in reviews:
|
||||
rating = review.get('rating', 0)
|
||||
rating_distribution[rating] = rating_distribution.get(rating, 0) + 1
|
||||
|
||||
# 키워드 추출 (badges 기반)
|
||||
keyword_counts = {}
|
||||
# 공통 키워드 추출 (배지 기준)
|
||||
keyword_count = {}
|
||||
for review in reviews:
|
||||
badges = review.get('badges', [])
|
||||
for badge in badges:
|
||||
keyword_counts[badge] = keyword_counts.get(badge, 0) + 1
|
||||
keyword_count[badge] = keyword_count.get(badge, 0) + 1
|
||||
|
||||
# 상위 키워드 추출
|
||||
common_keywords = sorted(keyword_counts.items(), key=lambda x: x[1], reverse=True)[:10]
|
||||
# 상위 10개 키워드
|
||||
common_keywords = sorted(keyword_count.items(), key=lambda x: x[1], reverse=True)[:10]
|
||||
common_keywords = [keyword for keyword, count in common_keywords]
|
||||
|
||||
# 감정 분석 (간단한 별점 기반)
|
||||
sentiment_summary = {
|
||||
"positive": len([r for r in ratings if r >= 4]),
|
||||
"neutral": len([r for r in ratings if r == 3]),
|
||||
"negative": len([r for r in ratings if r <= 2])
|
||||
}
|
||||
|
||||
return {
|
||||
"total_reviews": total_reviews,
|
||||
"average_rating": round(average_rating, 2),
|
||||
"rating_distribution": rating_distribution,
|
||||
"common_keywords": common_keywords,
|
||||
"sentiment_summary": sentiment_summary,
|
||||
"has_recent_reviews": any(
|
||||
review.get('date', '') >= datetime.now().strftime('%Y.%m.%d')
|
||||
for review in reviews[-10:] # 최근 10개 리뷰 확인
|
||||
)
|
||||
"total_likes": total_likes,
|
||||
"common_keywords": common_keywords
|
||||
}
|
||||
|
||||
def extract_text_for_embedding(store_info: Dict[str, Any], reviews: List[Dict[str, Any]]) -> str:
|
||||
"""
|
||||
임베딩을 위한 텍스트를 추출합니다.
|
||||
Vector DB 임베딩을 위한 텍스트를 추출합니다.
|
||||
|
||||
Args:
|
||||
store_info: 가게 정보
|
||||
@@ -191,4 +178,4 @@ def is_duplicate_store(metadata1: Dict[str, Any], metadata2: Dict[str, Any]) ->
|
||||
if name1 and name2 and addr1 and addr2:
|
||||
return name1 == name2 and addr1 == addr2
|
||||
|
||||
return False
|
||||
return False
|
||||
Reference in New Issue
Block a user