Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1550,27 +1550,23 @@ def check_no_time_parasites(message, exceptions=None):
|
|
1550 |
# 16. Несколько существительных подряд
|
1551 |
|
1552 |
def check_no_multiple_nouns(message, exceptions=None):
|
1553 |
-
"""
|
1554 |
-
Проверка на 3+ подряд существительных.
|
1555 |
-
Если конкретная цепочка лемм в exceptions['multiple_nouns'], пропускаем.
|
1556 |
-
"""
|
1557 |
if exceptions is None:
|
1558 |
exceptions = {}
|
1559 |
allowed_chains = exceptions.get("multiple_nouns", set())
|
1560 |
|
1561 |
morph = pymorphy3.MorphAnalyzer()
|
1562 |
-
# Разбиваем
|
1563 |
tokens = re.split(r'[,\s.!?;:\(\)"«»–—]+', message)
|
1564 |
-
|
1565 |
chain = []
|
1566 |
count = 0
|
1567 |
-
|
1568 |
for t in tokens:
|
1569 |
word = t.strip()
|
1570 |
if not word:
|
1571 |
-
#
|
|
|
1572 |
count = 0
|
1573 |
-
chain
|
1574 |
continue
|
1575 |
|
1576 |
p = morph.parse(word)[0]
|
@@ -1579,19 +1575,16 @@ def check_no_multiple_nouns(message, exceptions=None):
|
|
1579 |
count += 1
|
1580 |
chain.append(lemma)
|
1581 |
else:
|
1582 |
-
# Как только встретили
|
1583 |
count = 0
|
1584 |
-
chain
|
1585 |
|
1586 |
-
# Если подряд уже 3 существительных
|
1587 |
if count > 2:
|
1588 |
chain_tuple = tuple(chain)
|
1589 |
if chain_tuple not in allowed_chains:
|
1590 |
return False, f"Несколько существительных подряд: {chain_tuple}"
|
1591 |
-
|
1592 |
return True
|
1593 |
|
1594 |
-
|
1595 |
# 17. Производные предлоги
|
1596 |
|
1597 |
def check_no_derived_prepositions(message, exceptions=None):
|
|
|
1550 |
# 16. Несколько существительных подряд
|
1551 |
|
1552 |
def check_no_multiple_nouns(message, exceptions=None):
|
|
|
|
|
|
|
|
|
1553 |
if exceptions is None:
|
1554 |
exceptions = {}
|
1555 |
allowed_chains = exceptions.get("multiple_nouns", set())
|
1556 |
|
1557 |
morph = pymorphy3.MorphAnalyzer()
|
1558 |
+
# Разбиваем более аккуратно:
|
1559 |
tokens = re.split(r'[,\s.!?;:\(\)"«»–—]+', message)
|
1560 |
+
|
1561 |
chain = []
|
1562 |
count = 0
|
|
|
1563 |
for t in tokens:
|
1564 |
word = t.strip()
|
1565 |
if not word:
|
1566 |
+
# Если токен пустой (двойные пробелы, переносы строк),
|
1567 |
+
# сбрасываем цепочку
|
1568 |
count = 0
|
1569 |
+
chain.clear()
|
1570 |
continue
|
1571 |
|
1572 |
p = morph.parse(word)[0]
|
|
|
1575 |
count += 1
|
1576 |
chain.append(lemma)
|
1577 |
else:
|
1578 |
+
# Как только встретили не-сущ. — сбрасываем
|
1579 |
count = 0
|
1580 |
+
chain.clear()
|
1581 |
|
|
|
1582 |
if count > 2:
|
1583 |
chain_tuple = tuple(chain)
|
1584 |
if chain_tuple not in allowed_chains:
|
1585 |
return False, f"Несколько существительных подряд: {chain_tuple}"
|
|
|
1586 |
return True
|
1587 |
|
|
|
1588 |
# 17. Производные предлоги
|
1589 |
|
1590 |
def check_no_derived_prepositions(message, exceptions=None):
|