Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ __pycache__/
*.log

# w2v 모델
GoogleNews-vectors-negative300.bin.gz
GoogleNews-vectors-negative300.bin.gz
node2vec.model
14 changes: 11 additions & 3 deletions app/models/db_w2v_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"가족": "Family",
"코미디": "Comedy",
"애니메이션": "Animation",
"SF": "SF",
"SF": "Science Fiction",
"다큐멘터리": "Documentary",
"판타지": "Fantasy",
"드라마": "Drama",
Expand All @@ -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
6 changes: 3 additions & 3 deletions app/models/word2vec_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gensim.models import KeyedVectors
from gensim.models import Word2Vec


class Word2VecModel:
Expand All @@ -8,15 +8,15 @@ 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

@classmethod
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:
Expand Down
47 changes: 24 additions & 23 deletions app/services/weight_strategy.py
Original file line number Diff line number Diff line change
@@ -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