dream

Форк
0
/
grounding.py 
116 строк · 3.4 Кб
1
import re
2
import logging
3

4
logger = logging.getLogger(__name__)
5

6
grounding_patterns = [
7
    "what do you mean",
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",
12
    r"^what[\?\.]?$",
13
]
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)))"
20
)
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)
23

24

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
29

30

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
35

36

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?"
48

49

50
def detect_interrupt(text):
51
    if re.search(WHAT_WHO_IS_PATTERN, text) or re.search(END_ARTICLE_PATTERN, text):
52
        return True
53
    elif not re.search(WHAT_WHO_PATTERN, text) and re.search(FAVORITE_INTERRUPT_PATTERN, text):
54
        return True
55
    return False
56

57

58
def detect_end_but(text):
59
    return re.search(BUT_PATTERN, text)
60

61

62
def detect_end_because(text):
63
    return re.search(BECAUSE_PATTERN, text)
64

65

66
def detect_end_when(text):
67
    return re.search(WHEN_PATTERN, text)
68

69

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.",
78
]
79

80
COMPLIMENT_PROPERTIES = [
81
    "Considerate",
82
    "Cooperative",
83
    "Determined",
84
    "Enthusiastic",
85
    "Friendly",
86
    "Funny",
87
    "Generous",
88
    "Helpful",
89
    "Honest",
90
    "Insightful",
91
    "Intelligent",
92
    "Observant",
93
    "Organized",
94
    "Patient",
95
    "Positive",
96
    "Proactive",
97
    "Responsible",
98
    "Sincere",
99
    "Wise",
100
    "Amazing",
101
    "Awesome",
102
    "Brilliant",
103
    "Delightful",
104
    "Excellent",
105
    "Fabulous",
106
    "Fantastic",
107
    "Gorgeous",
108
    "Great",
109
    "Impressive",
110
    "Lovely",
111
    "Marvellous",
112
    "Outstanding",
113
    "Smashing",
114
    "Splendid",
115
    "Wonderful",
116
]
117

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.