lsdf commited on
Commit
ab50f44
·
1 Parent(s): 61b5c14

Fix count_words: isolated logic, total includes stop-words and digits

Browse files
Files changed (2) hide show
  1. 2026-02-08_00-16-10.png +0 -0
  2. logic.py +21 -15
2026-02-08_00-16-10.png ADDED
logic.py CHANGED
@@ -169,36 +169,42 @@ def generate_ngrams_safe(text: str, lang: str, n: int) -> List[str]:
169
 
170
  def count_words(text: str, lang: str) -> Dict[str, int]:
171
  """
172
- Считает статистику слов.
173
- Возвращает словарь:
174
- {
175
- "total": Общее кол-во слов (включая стоп-слова и цифры, как в Word).
176
- "significant": Кол-во слов без стоп-слов и цифр (SEO-вес).
177
- }
178
  """
179
  if not text.strip():
180
  return {"total": 0, "significant": 0}
181
 
 
 
182
  clean_text = " ".join(text.split())
183
  doc = get_doc(clean_text, lang)
184
 
185
- total = 0
186
- significant = 0
187
 
188
  for t in doc:
189
- if t.is_punct or t.is_space or t.pos_ == "SYM":
 
 
190
  continue
191
 
192
- # 1. Считаем в ОБЩИЙ зачет (Все слова + цифры)
193
- total += 1
194
 
195
- # 2. Проверяем на значимость (для второго счетчика)
196
- if t.is_stop or t.is_digit or t.like_num:
 
 
 
 
 
 
 
197
  continue
198
 
199
- significant += 1
200
 
201
- return {"total": total, "significant": significant}
202
 
203
  # --- ANALYTICS (N-grams & BM25) ---
204
 
 
169
 
170
  def count_words(text: str, lang: str) -> Dict[str, int]:
171
  """
172
+ Считает слова. ПОЛНОСТЬЮ ИЗОЛИРОВАННАЯ ЛОГИКА.
173
+ Не зависит от N-грамм или BM25.
 
 
 
 
174
  """
175
  if not text.strip():
176
  return {"total": 0, "significant": 0}
177
 
178
+ # 1. Получаем чистый объект spaCy (без всяких re.sub и вырезаний)
179
+ # Просто убираем лишние пробелы/энтеры
180
  clean_text = " ".join(text.split())
181
  doc = get_doc(clean_text, lang)
182
 
183
+ total_count = 0
184
+ significant_count = 0
185
 
186
  for t in doc:
187
+ # --- ФИЛЬТР ДЛЯ ОБЩЕГО КОЛИЧЕСТВА ---
188
+ # Считаем всё, кроме пунктуации и пробелов
189
+ if t.is_punct or t.is_space:
190
  continue
191
 
192
+ total_count += 1
 
193
 
194
+ # --- ФИЛЬТР ДЛЯ ЗНАЧИМЫХ СЛОВ ---
195
+ # Если это стоп-слово (der, die, das...) - не считаем в значимые
196
+ if t.is_stop:
197
+ continue
198
+ # Если это цифра - не считаем
199
+ if t.is_digit or t.like_num:
200
+ continue
201
+ # Если это спецсимвол - не считаем
202
+ if t.pos_ == "SYM":
203
  continue
204
 
205
+ significant_count += 1
206
 
207
+ return {"total": total_count, "significant": significant_count}
208
 
209
  # --- ANALYTICS (N-grams & BM25) ---
210