fruitpicker01 commited on
Commit
454dc4b
·
verified ·
1 Parent(s): fb85683

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -2
app.py CHANGED
@@ -2017,6 +2017,40 @@ def check_no_dates_written_out(message):
2017
 
2018
  return True
2019
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2020
  # ФУНКЦИИ ПРОВЕРОК (КОНЕЦ)
2021
 
2022
  def safe_check(func, message):
@@ -2045,7 +2079,8 @@ def perform_checks(message):
2045
  "multiple_nouns": safe_check(check_no_multiple_nouns, message),
2046
  "derived_prepositions": safe_check(check_no_derived_prepositions, message),
2047
  "compound_sentences": safe_check(check_no_compound_sentences, message),
2048
- "dates_written_out": safe_check(check_no_dates_written_out, message)
 
2049
  }
2050
  return checks
2051
 
@@ -2069,7 +2104,8 @@ def format_checks(checks):
2069
  "multiple_nouns": "Несколько существительных подряд",
2070
  "derived_prepositions": "Производные предлоги",
2071
  "compound_sentences": "Сложноподчиненные предложения",
2072
- "dates_written_out": "Даты прописью"
 
2073
  }
2074
  formatted_results = []
2075
  for rule, result in checks.items():
 
2017
 
2018
  return True
2019
 
2020
+ # Доп правило. Повторы слов
2021
+
2022
+ def check_no_word_repetitions(message):
2023
+ morph = pymorphy2.MorphAnalyzer()
2024
+
2025
+ # Список союзов и предлогов, которые мы будем игнорировать
2026
+ ignore_words = set([
2027
+ 'и', 'а', 'но', 'или', 'да', 'ни', 'как', 'так',
2028
+ 'в', 'на', 'под', 'над', 'за', 'к', 'до', 'по', 'из', 'у', 'о', 'про', 'для',
2029
+ 'не', 'вот', 'это', 'тот', 'тем', 'при', 'чем',
2030
+ 'же', 'ли', 'бы', 'то',
2031
+ ])
2032
+
2033
+ # Разбиваем текст на слова, удаляя знаки препинания
2034
+ words = re.findall(r'\b\w+\b', message.lower())
2035
+
2036
+ # Словарь для хранения нормализованных форм слов
2037
+ normalized_words = {}
2038
+
2039
+ for word in words:
2040
+ if word not in ignore_words:
2041
+ # Получаем нормальную форму слова
2042
+ normal_form = morph.parse(word)[0].normal_form
2043
+
2044
+ # Если слово уже встречалось, возвращаем False
2045
+ if normal_form in normalized_words:
2046
+ return False
2047
+
2048
+ # Добавляем слово в словарь
2049
+ normalized_words[normal_form] = True
2050
+
2051
+ # Если мы дошли до этой точки, повторов не было
2052
+ return True
2053
+
2054
  # ФУНКЦИИ ПРОВЕРОК (КОНЕЦ)
2055
 
2056
  def safe_check(func, message):
 
2079
  "multiple_nouns": safe_check(check_no_multiple_nouns, message),
2080
  "derived_prepositions": safe_check(check_no_derived_prepositions, message),
2081
  "compound_sentences": safe_check(check_no_compound_sentences, message),
2082
+ "dates_written_out": safe_check(check_no_dates_written_out, message),
2083
+ "no_word_repetitions": safe_check(check_no_word_repetitions, message)
2084
  }
2085
  return checks
2086
 
 
2104
  "multiple_nouns": "Несколько существительных подряд",
2105
  "derived_prepositions": "Производные предлоги",
2106
  "compound_sentences": "Сложноподчиненные предложения",
2107
+ "dates_written_out": "Даты прописью",
2108
+ "no_word_repetitions": "Повторы слов"
2109
  }
2110
  formatted_results = []
2111
  for rule, result in checks.items():