fruitpicker01 commited on
Commit
f27f77a
·
verified ·
1 Parent(s): 156988a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -1556,30 +1556,39 @@ def check_no_multiple_nouns(message, exceptions=None):
1556
  """
1557
  if exceptions is None:
1558
  exceptions = {}
1559
- allowed_chains = exceptions.get("multiple_nouns", set()) # set of tuples
1560
 
1561
  morph = pymorphy3.MorphAnalyzer()
1562
- tokens = re.split(r'[,\s.!?;:()]+', message)
 
 
1563
  chain = []
1564
  count = 0
1565
 
1566
  for t in tokens:
1567
- t = t.strip()
1568
- if not t:
 
 
 
1569
  continue
1570
- p = morph.parse(t)[0]
 
1571
  lemma = p.normal_form
1572
  if 'NOUN' in p.tag:
1573
  count += 1
1574
  chain.append(lemma)
1575
  else:
 
1576
  count = 0
1577
  chain = []
1578
 
 
1579
  if count > 2:
1580
- chain_tuple = tuple(chain) # например ('зачисление', 'зарплата', 'сотрудникам')
1581
  if chain_tuple not in allowed_chains:
1582
  return False, f"Несколько существительных подряд: {chain_tuple}"
 
1583
  return True
1584
 
1585
 
 
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]
1577
  lemma = p.normal_form
1578
  if 'NOUN' in p.tag:
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