dream

Форк
0
/
sport.py 
157 строк · 6.1 Кб
1
import re
2
from common.combined_classes import TOPIC_GROUPS
3
from common import utils
4

5

6
##################################################################################################################
7
# LINK
8
##################################################################################################################
9

10

11
BINARY_QUESTION_ABOUT_SPORT = ["Do you like sports?", "Do you like fitness?", "Would you like to chat about sport?"]
12
BINARY_QUESTION_ABOUT_ATHLETE = ["Would you like to talk about your favorite athletes? ", "Do you have a sports idol?"]
13

14
BINARY_QUESTION_ABOUT_COMP = ["Well, Do you want to talk about sports competitions?"]
15

16

17
def skill_trigger_phrases():
18
    return BINARY_QUESTION_ABOUT_SPORT + BINARY_QUESTION_ABOUT_ATHLETE + BINARY_QUESTION_ABOUT_COMP
19

20

21
##################################################################################################################
22
# TEMPLATE
23
##################################################################################################################
24

25

26
SUPER_CONFIDENCE = 1.0
27
HIGH_CONFIDENCE = 0.99
28
DEFAULT_CONFIDENCE = 0.9
29
LOW_CONFIDENCE = 0.75
30
ZERO_CONFIDENCE = 0.0
31

32
NUMBER_PROBABILITY = 0
33

34

35
SPORTS_NO_ING = (
36
    r"\b(aerobics|archery|badminton|baseball|basketball|beach volleyball|biathlon"
37
    r"|billiards|canoe|car race|chess|climb|coach|cricket"
38
    r"|curling|cycle|darts|dive|draughts"
39
    r"|fence|figure skate|football|golf|gymnastics|handball|hang glide"
40
    r"|high jump|hockey|hurdle race|ice rink|in-line skate|jog|judo|karate"
41
    r"|long jump|martial arts|motorbike sports|mountaineer|orienteer"
42
    r"|parachute|pole-vault|polo|ride|rowing|rugby|ski|snooker"
43
    r"|track-and-field|triathlon|tug of war|volleyball|water polo|waterski"
44
    r"|weight lift|work out|wrestle|run|swim|tennis|fitness|lacrosse|ballet|soccer)\b"
45
)
46
# curling in SPORTS_NO_ING is not a mistake - there is not word to curl
47
ING_FORMS = {
48
    "run": "running",
49
    "swim": "swimming",
50
    "ski": "skiing",
51
    "dive": "diving",
52
    "box": "boxing",
53
    "canoe": "canoeing",
54
    "climb": "climbing",
55
    "cycle": "cycling",
56
    "fence": "fencing",
57
    "figure skate": "figure skating",
58
    "in-line skate": "figure skating",
59
    "hang glide": "hand gliding",
60
    "high jump": "high jumping",
61
    "jog": "jogging",
62
    "ride": "riding",
63
    "row": "rowing",
64
    "weight lift": "weight lifing",
65
    "wrestle": "wrestling",
66
    "work out": "working out",
67
    "mountaineer": "mountaineering",
68
    "dance": "dancing",
69
    "orienteer": "orienteering",
70
    "parachute": "parachuting",
71
    "pole-vault": "pole-vaulting",
72
    "car race": "car racing",
73
    "wakeboard": "wakeboarding",
74
    "long jump": "long jumping",
75
}
76
REVERSE_ING_FORMS = {ING_FORMS[key]: key for key in ING_FORMS}
77
regexp_ing_forms = r"|".join([rf"\b{k}" for k in ING_FORMS.values()])
78
SPORTS = rf"({regexp_ing_forms}|{SPORTS_NO_ING})"
79
KIND_OF_SPORTS_TEMPLATE = re.compile(
80
    SPORTS,
81
    re.IGNORECASE,
82
)
83
PASSIVE_SPORT = ["chess", "checkers"]
84

85
OPINION_ABOUT_PASSIVE_SPORT = [
86
    "KIND_OF_SPORT is cool. But since I live in the cloud, I can only play PASSIVE_SPORT!",
87
    "I would like to play KIND_OF_SPORT. " "But I have no physical incarnation, so I can only play PASSIVE_SPORT!",
88
]
89

90
KIND_OF_COMPETITION_TEMPLATE = re.compile(
91
    r"(FIFA World Cup|Olympic Games|Super Bowl|Grand National"
92
    r"|Masters Tournament|Wimbledon|Kentucky Derby|NBA"
93
    r"|Cricket World Cup|World Series|Tour De France|March Madness"
94
    r"|UEFA|Ryder Cup|Daytona 500|Rugby World Cup"
95
    r"|Boston Marathon|Open Championship|Indianapolis 500|Stanley Cup"
96
    r"|Monaco Grand Prix|Rose Bowl|UFC|NFL)",
97
    re.IGNORECASE,
98
)
99

100
ATHLETE_TEMPLETE = re.compile(
101
    r"(athlete|sportsperson|games player|muscle person|player" r"|footballer|aquanaut|diver|jock|lifter)", re.IGNORECASE
102
)
103
SPORT_TEMPLATE = re.compile(r"(sport|active)", re.IGNORECASE)
104
SUPPORT_TEMPLATE = re.compile(r"(support|a fan of)", re.IGNORECASE)
105

106
QUESTION_TEMPLATE = re.compile(r"(what|did|do|which|who) (team )?(you )?(do|is|are|kind of|know|like)", re.IGNORECASE)
107

108
LIKE_TEMPLATE = re.compile(r"(like|love|support|a fan of|favorite|enjoy|want to talk)?", re.IGNORECASE)
109

110
HATE_TEMPLATE = re.compile(r"(hate)", re.IGNORECASE)
111

112
COMPETITION_TEMPLATE = re.compile(r"(tournament|tourney|competition|championship|derby)", re.IGNORECASE)
113

114
OFFER_FACT_COMPETITION = [
115
    "I recently wandered on the Internet and found an interesting fact about COMPETITION." "Do you want to hear?",
116
    "Cool! Do you want to hear a fact about COMPETITION?",
117
    "I know something interesting about it. Do you want me to share a fact about COMPETITION?",
118
]
119
OPINION_REQUESTS = ["What do you think about it?", "It's interesting, isn't it?", "What is your view on it?"]
120

121
ASK_ABOUT_ATH_IN_KIND_OF_SPORT = [
122
    "Yep, that's cool. I'm really wondering who is your idol in KIND_OF_SPORT?",
123
    "Wow, that's cool. Who is your favorite athlete in KIND_OF_SPORT?",
124
]
125

126
OPINION_ABOUT_ATHLETE_WITH_TEAM_AND_POS = [
127
    "Oh, I know this POSITION from TEAM. He does his job well.",
128
    "Oh, I kind of know him. He is a POSITION and plays in TEAM.",
129
]
130

131
OPINION_ABOUT_ATHLETE_WITH_TEAM = [
132
    "Oh yes, he's cool. I've seen him perform miracles in TEAM.",
133
    "Oh, he's just a wizard. He does his job well in TEAM.",
134
]
135

136
OPINION_ABOUT_ATHLETE_WITHOUT_TEAM = ["I know NAME. He's kind of from COUNTRY. Have you ever been in COUNTRY?"]
137

138
OPINION_ABOUT_TEAM = ["By the way, I support the TEAM. I remember how they won in COMPETITION. It was cool."]
139

140
LAST_CHANCE_TEMPLATE = [
141
    "I'm still too young and I don't know much, but something tells me that It's very interesting. "
142
    "Tell me more about that",
143
    "Oh, this is the first time I hear about this. " "Tell me more about that",
144
    "This is probably very interesting. Tell me more about that.",
145
]
146

147

148
def about_sport(annotated_utterance):
149
    found_topics = utils.get_topics(annotated_utterance, probs=False, which="all")
150
    if any([topic in found_topics for topic in TOPIC_GROUPS["sport"]]):
151
        return True
152
    elif re.findall(KIND_OF_SPORTS_TEMPLATE, annotated_utterance["text"]):
153
        return True
154
    elif re.findall(KIND_OF_COMPETITION_TEMPLATE, annotated_utterance["text"]):
155
        return True
156
    else:
157
        return False
158

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

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

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

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