diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de45645..cae47b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: echo "DB_USERNAME=testuser" >> .env echo "DB_PASSWORD=testpass" >> .env echo "DB_NAME=testdb" >> .env - echo "W2V_MODEL_PATH=./app/assets/word2vec.model" >> .env + echo "W2V_MODEL_PATH=./app/assets/node2vec.model" >> .env echo "MONGO_URL=mongodb://localhost:27017" >> .env echo "DEV_REDIS_HOST=localhost" >> .env echo "DEV_REDIS_PORT=6379" >> .env diff --git a/.gitignore b/.gitignore index f8d60a6..3215ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ __pycache__/ *.log # w2v 모델 -GoogleNews-vectors-negative300.bin.gz \ No newline at end of file +GoogleNews-vectors-negative300.bin.gz +node2vec.model \ No newline at end of file diff --git a/app/models/db_w2v_mapper.py b/app/models/db_w2v_mapper.py index 6ff00d0..0b2d61f 100644 --- a/app/models/db_w2v_mapper.py +++ b/app/models/db_w2v_mapper.py @@ -6,7 +6,7 @@ "가족": "Family", "코미디": "Comedy", "애니메이션": "Animation", - "SF": "SF", + "SF": "Science Fiction", "다큐멘터리": "Documentary", "판타지": "Fantasy", "드라마": "Drama", @@ -24,5 +24,13 @@ } -def translate_genre(korean_genre: str) -> str: - return _genre_mapping.get(korean_genre, korean_genre) +def translate_genre(genre: str) -> str | None: + genre = genre.strip() + + if genre in _genre_mapping: + return _genre_mapping[genre] + + if genre in _genre_mapping.values(): + return genre + + return genre diff --git a/app/models/word2vec_model.py b/app/models/word2vec_model.py index 296cf4b..6bcf831 100644 --- a/app/models/word2vec_model.py +++ b/app/models/word2vec_model.py @@ -1,4 +1,4 @@ -from gensim.models import KeyedVectors +from gensim.models import Word2Vec class Word2VecModel: @@ -8,7 +8,7 @@ class Word2VecModel: def load_model(cls, model_path: str): if cls._model is None: print("모델 로딩 중...") - cls._model = KeyedVectors.load_word2vec_format(model_path, binary=True) + cls._model = Word2Vec.load(model_path) print("모델 로드 완료!") return cls._model @@ -16,7 +16,7 @@ def load_model(cls, model_path: str): def get_vector(cls, word: str): if cls._model is None: raise RuntimeError("모델이 아직 로드되지 않았습니다.") - return cls._model.get_vector(word) + return cls._model.wv.get_vector(word) @classmethod def similarity(cls, word1: str, word2: str) -> float: diff --git a/app/services/weight_strategy.py b/app/services/weight_strategy.py index 4f7ebc1..280d8d1 100644 --- a/app/services/weight_strategy.py +++ b/app/services/weight_strategy.py @@ -1,25 +1,26 @@ from app.enum.action_type import ActionType -def convert_to_weight(type : ActionType, value : float) -> float : - if type == ActionType.CLICK: - return 0.2 - if type == ActionType.LIKE: - return 0.1 - if type == ActionType.WATCH: - if 30 <= value <= 50: - return 0.1 - if 50 <= value <= 70: - return 0.2 - if 70 <= value: - return 0.3 - else: - return 0 - if type == ActionType.RATING: - if value <= 2: - return 0 - if value == 3: - return 0.2 - if value == 4: - return 0.3 - if value == 5: - return 0.4 + +def convert_to_weight(type: ActionType, value: float) -> float: + if type == ActionType.CLICK: + return 0.05 + if type == ActionType.LIKE: + return 0.1 + if type == ActionType.WATCH: + if 30 <= value <= 50: + return 0.1 + if 50 <= value <= 70: + return 0.2 + if 70 <= value: + return 0.3 + else: + return 0 + if type == ActionType.RATING: + if value <= 2: + return 0 + if value == 3: + return 0.2 + if value == 4: + return 0.3 + if value == 5: + return 0.4