mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Black
This commit is contained in:
@@ -6,13 +6,13 @@ def create_matcher(utterance):
|
||||
"""Create a regex that matches the utterance."""
|
||||
# Split utterance into parts that are type: NORMAL, GROUP or OPTIONAL
|
||||
# Pattern matches (GROUP|OPTIONAL): Change light to [the color] {name}
|
||||
parts = re.split(r'({\w+}|\[[\w\s]+\] *)', utterance)
|
||||
parts = re.split(r"({\w+}|\[[\w\s]+\] *)", utterance)
|
||||
# Pattern to extract name from GROUP part. Matches {name}
|
||||
group_matcher = re.compile(r'{(\w+)}')
|
||||
group_matcher = re.compile(r"{(\w+)}")
|
||||
# Pattern to extract text from OPTIONAL part. Matches [the color]
|
||||
optional_matcher = re.compile(r'\[([\w ]+)\] *')
|
||||
optional_matcher = re.compile(r"\[([\w ]+)\] *")
|
||||
|
||||
pattern = ['^']
|
||||
pattern = ["^"]
|
||||
for part in parts:
|
||||
group_match = group_matcher.match(part)
|
||||
optional_match = optional_matcher.match(part)
|
||||
@@ -24,12 +24,11 @@ def create_matcher(utterance):
|
||||
|
||||
# Group part
|
||||
if group_match is not None:
|
||||
pattern.append(
|
||||
r'(?P<{}>[\w ]+?)\s*'.format(group_match.groups()[0]))
|
||||
pattern.append(r"(?P<{}>[\w ]+?)\s*".format(group_match.groups()[0]))
|
||||
|
||||
# Optional part
|
||||
elif optional_match is not None:
|
||||
pattern.append(r'(?:{} *)?'.format(optional_match.groups()[0]))
|
||||
pattern.append(r"(?:{} *)?".format(optional_match.groups()[0]))
|
||||
|
||||
pattern.append('$')
|
||||
return re.compile(''.join(pattern), re.I)
|
||||
pattern.append("$")
|
||||
return re.compile("".join(pattern), re.I)
|
||||
|
||||
Reference in New Issue
Block a user