fix: parse names and ids in bulk input
This commit is contained in:
1 parent
ba844c5e4e
commit
a2aacf4503
2 files changed
+23
-4
No files matched your search
+10
-4
@@ -245,7 +245,7 @@ def parse_natural_bulk(text: str) -> tuple[dict[str, Any], list[str]] | None:
|
|||||||
lowered = text.lower()
|
lowered = text.lower()
|
||||||
if re.search(r"\b(урок|тренировк)\w*\b", lowered):
|
if re.search(r"\b(урок|тренировк)\w*\b", lowered):
|
||||||
people_text = re.sub(r"(?i)^\s*(?:урок|тренировк\w*)\s*", "", text)
|
people_text = re.sub(r"(?i)^\s*(?:урок|тренировк\w*)\s*", "", text)
|
||||||
people = [(match.group("name").strip(" |,–-"), int(match.group("id")))
|
people = [(match.group("name").strip(" |,–-[]"), int(match.group("id")))
|
||||||
for match in _NATURAL_PERSON_RE.finditer(people_text)]
|
for match in _NATURAL_PERSON_RE.finditer(people_text)]
|
||||||
fields: dict[str, Any] = {"mode": "training"}
|
fields: dict[str, Any] = {"mode": "training"}
|
||||||
questions: list[str] = []
|
questions: list[str] = []
|
||||||
@@ -295,9 +295,15 @@ def parse_natural_bulk(text: str) -> tuple[dict[str, Any], list[str]] | None:
|
|||||||
return fields, questions
|
return fields, questions
|
||||||
date_match = _DATE_RE.search(text)
|
date_match = _DATE_RE.search(text)
|
||||||
times = _TIME_RE.findall(text)
|
times = _TIME_RE.findall(text)
|
||||||
person_tail = text[max((match.end() for match in _TIME_RE.finditer(text)), default=0):]
|
person_source = _DATE_RE.sub(" ", text)
|
||||||
people = [(match.group("name").strip(" |,–-"), int(match.group("id")))
|
person_source = _TIME_RE.sub(" ", person_source)
|
||||||
for match in _NATURAL_PERSON_RE.finditer(person_tail)]
|
person_source = re.sub(
|
||||||
|
r"(?i)\b(?:лу|лазание|зу|зоркость|самостоятельно|самостоятельный|несамостоятельно|несамостоятельный|сам|несам)\b",
|
||||||
|
" ",
|
||||||
|
person_source,
|
||||||
|
)
|
||||||
|
people = [(match.group("name").strip(" |,–-[]"), int(match.group("id")))
|
||||||
|
for match in _NATURAL_PERSON_RE.finditer(person_source)]
|
||||||
if not date_match and len(times) < 2 and len(people) < 1:
|
if not date_match and len(times) < 2 and len(people) < 1:
|
||||||
return None
|
return None
|
||||||
skill_match = re.search(r"(?i)\b(лу|лазание|зу|зоркость)\b", text)
|
skill_match = re.search(r"(?i)\b(лу|лазание|зу|зоркость)\b", text)
|
||||||
|
|||||||
@@ -116,6 +116,19 @@ class VkConversationTests(unittest.TestCase):
|
|||||||
response = dialog.handle(101, "самостоятельно")
|
response = dialog.handle(101, "самостоятельно")
|
||||||
self.assertIn("скриншот", response.lower())
|
self.assertIn("скриншот", response.lower())
|
||||||
|
|
||||||
|
def test_natural_bulk_input_extracts_people_before_time_range(self):
|
||||||
|
for text in (
|
||||||
|
"24.08 ЛУ Дикая Вишня 1604614 Серопопик 1346767 21:00-22:00 сам",
|
||||||
|
"24.08 ЛУ Дикая Вишня [1604614], Серопопик [1346767] 21:00-22:00 сам",
|
||||||
|
):
|
||||||
|
inspected = inspect_bulk_text(text)
|
||||||
|
self.assertEqual(inspected["fields"]["escort_name"], "Дикая Вишня")
|
||||||
|
self.assertEqual(inspected["fields"]["escort_id"], 1604614)
|
||||||
|
self.assertEqual(inspected["fields"]["kitten_name"], "Серопопик")
|
||||||
|
self.assertEqual(inspected["fields"]["kitten_id"], 1346767)
|
||||||
|
self.assertEqual(inspected["fields"]["start"], "21:00")
|
||||||
|
self.assertEqual(inspected["fields"]["end"], "22:00")
|
||||||
|
|
||||||
def test_training_supports_stepwise_and_natural_bulk(self):
|
def test_training_supports_stepwise_and_natural_bulk(self):
|
||||||
dialog = BelkiDialog()
|
dialog = BelkiDialog()
|
||||||
self.assertIn("сопровождающ", dialog.handle(102, "/урок").lower())
|
self.assertIn("сопровождающ", dialog.handle(102, "/урок").lower())
|
||||||
|
|||||||
Reference in new issue
Block a user