From 5bc569a75ecadfac1cbfdcbb9fa8feb41c4364d8 Mon Sep 17 00:00:00 2001 From: stud203799 Date: Thu, 23 Apr 2026 01:05:59 +0300 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=B7=D0=B8=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20calculate=5Fsentiment=5Fscore,=20validate=5Frating,=20?= =?UTF-8?q?validate=5Frating?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index c1da907..f3f0fd7 100644 --- a/main.py +++ b/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 = [ "заработок в интернете", "легкие деньги", "пассивный доход", "быстрый заработок", "миллион за неделю", "лотерея", "вы выиграли приз", "ваш приз ждет", "выигрыш",