реазилованы функции calculate_sentiment_score, validate_rating, validate_rating
This commit is contained in:
parent
bc4fd28a1d
commit
5bc569a75e
52
main.py
52
main.py
@ -1,17 +1,13 @@
|
||||
# Система анализа и модерации отзывов на товары (E-Commerce Review Engine)
|
||||
|
||||
def clean_text(text: str):
|
||||
black_list = ",?:"
|
||||
if text[3] == ';':
|
||||
text = text[4:]
|
||||
for i in range(len(black_list)):
|
||||
text = text.replace(black_list[i], '')
|
||||
text = text.lower()
|
||||
for i in range(len(text)):
|
||||
text = text.replace(' ', ' ')
|
||||
return text
|
||||
else:
|
||||
print("Некорректный ввод текста отзыва")
|
||||
black_list = ",?:();-+=*%"
|
||||
for i in range(len(black_list)):
|
||||
text = text.replace(black_list[i], '')
|
||||
text = text.lower()
|
||||
for i in range(len(text)):
|
||||
text = text.replace(' ', ' ')
|
||||
return text
|
||||
|
||||
|
||||
def extract_keywords(text: str, keywords_dict: dict):
|
||||
@ -24,15 +20,41 @@ def extract_keywords(text: str, keywords_dict: dict):
|
||||
|
||||
|
||||
def calculate_sentiment_score(text: str, positive_words: set, negative_words: set):
|
||||
return float
|
||||
pos_count = 0
|
||||
neg_count = 0
|
||||
for i in positive_words:
|
||||
if i in text:
|
||||
pos_count += 1
|
||||
for i in negative_words:
|
||||
if i in text:
|
||||
neg_count += 1
|
||||
sentiment = (pos_count - neg_count) / (pos_count + neg_count)
|
||||
return sentiment
|
||||
|
||||
|
||||
def validate_rating(rating: int):
|
||||
return bool
|
||||
if -1 <= rating <= 5:
|
||||
res = True
|
||||
else:
|
||||
res = False
|
||||
return res
|
||||
|
||||
|
||||
def is_spam(text: str, spam_indicators: list):
|
||||
return bool
|
||||
res = False
|
||||
caps_count = 0
|
||||
for i in spam_indicators:
|
||||
print(i)
|
||||
if i in text:
|
||||
res = True
|
||||
if res == False:
|
||||
for i in range(len(text)):
|
||||
if text[i].isupper():
|
||||
caps_count += 1
|
||||
if caps_count > len(text) / 2:
|
||||
res = True
|
||||
break
|
||||
return res
|
||||
|
||||
|
||||
def enrich_review(review: dict, keywords_dict: dict, positive_words: set, negative_words: set):
|
||||
@ -68,7 +90,7 @@ def main():
|
||||
"зазоры", "люфтит", "скрипит", "хрупкий", "одноразовый", "дешевка",
|
||||
"не соответствует заявленному", "отвратительное качество",
|
||||
"ужасное качество", "худшее качество", "мусор", "шлак", "не годится"}
|
||||
spam_markers = [
|
||||
spam_indicators = [
|
||||
"заработок в интернете", "легкие деньги", "пассивный доход",
|
||||
"быстрый заработок", "миллион за неделю", "лотерея",
|
||||
"вы выиграли приз", "ваш приз ждет", "выигрыш",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user