4
logger = logging.getLogger(__name__)
8
"i lost common ground",
9
r"(what|(not|n't) know)(( do| are)( we| you))( talk about| talking about| discuss| discussing)",
10
r"(what|(not|n't) know)(( we| you)( do| are))( talk about| talking about| discuss| discussing)",
11
r"(what|(not|n't) know)(( it is)|( is it)) about",
14
re_grounding_patterns = re.compile(r"(" + "|".join(grounding_patterns) + r")", re.IGNORECASE)
15
RE_RECORDING_TEMPLATE = (
16
r"(((are|do|can|could|will|would|have|had|whether) "
17
r"(you|amazon|echo)|conversation( is| (can|could) be)?) "
18
r"(record|snoop|spy|wiretap|(see(ing)?|watch(ing)?|track(ing)?) "
19
r"me|listen(ing)? (to )?(me|my)))"
21
RE_RECORDING_TEMPLATE2 = r"((keep)? (protect) (the)? (information)? (protect|secret))"
22
re_recording_patterns = re.compile(rf"({RE_RECORDING_TEMPLATE}|{RE_RECORDING_TEMPLATE2})", re.IGNORECASE)
25
def are_we_recorded(utterance):
26
if isinstance(utterance, dict):
27
utterance = utterance["text"]
28
return re.search(re_recording_patterns, utterance) is not None
31
def what_we_talk_about(utterance):
32
if isinstance(utterance, dict):
33
utterance = utterance["text"]
34
return re.search(re_grounding_patterns, utterance) is not None
37
FAVORITE_INTERRUPT_PATTERN = re.compile(r"my favou?rite[a-z0-9 \-]+is\.?$", re.IGNORECASE)
38
WHAT_WHO_PATTERN = re.compile(r"(what|who)", re.IGNORECASE)
39
WHAT_WHO_IS_PATTERN = re.compile(r"(what|who) is[\.\?]?$", re.IGNORECASE)
40
END_ARTICLE_PATTERN = re.compile(r"( a| an| the| and)[\.\?]?$", re.IGNORECASE)
41
BUT_PATTERN = re.compile(r" but[\.\?]?$", re.IGNORECASE)
42
WHEN_PATTERN = re.compile(r" when[\.\?]?$", re.IGNORECASE)
43
BECAUSE_PATTERN = re.compile(r" because[\.\?]?$", re.IGNORECASE)
44
BUT_PHRASE = "But what?"
45
BECAUSE_PHRASE = "Because of what?"
46
WHEN_PHRASE = "When what?"
47
REPEAT_PHRASE = "Could you please repeat what you have just said?"
50
def detect_interrupt(text):
51
if re.search(WHAT_WHO_IS_PATTERN, text) or re.search(END_ARTICLE_PATTERN, text):
53
elif not re.search(WHAT_WHO_PATTERN, text) and re.search(FAVORITE_INTERRUPT_PATTERN, text):
58
def detect_end_but(text):
59
return re.search(BUT_PATTERN, text)
62
def detect_end_because(text):
63
return re.search(BECAUSE_PATTERN, text)
66
def detect_end_when(text):
67
return re.search(WHEN_PATTERN, text)
70
MANY_INTERESTING_QUESTIONS = [
71
"You have so many interesting questions.",
72
"You like to ask interesting questions.",
73
"Aren't you the curious one.",
74
"You ask a lot of questions, my friend.",
75
"You're curious, aren't you?",
76
"You so curious. I like it.",
77
"I like your curiosity.",
80
COMPLIMENT_PROPERTIES = [