1 """Util for Conversation."""
3 from __future__
import annotations
9 """Create a regex that matches the utterance."""
12 parts = re.split(
r"({\w+}|\[[\w\s]+\] *)", utterance)
14 group_matcher = re.compile(
r"{(\w+)}")
16 optional_matcher = re.compile(
r"\[([\w ]+)\] *")
20 group_match = group_matcher.match(part)
21 optional_match = optional_matcher.match(part)
24 if group_match
is None and optional_match
is None:
29 if group_match
is not None:
30 pattern.append(rf
"(?P<{group_match.groups()[0]}>[\w ]+?)\s*")
33 elif optional_match
is not None:
34 pattern.append(rf
"(?:{optional_match.groups()[0]} *)?")
37 return re.compile(
"".join(pattern), re.IGNORECASE)
re.Pattern[str] create_matcher(str utterance)