2
from common import utils, universal_templates
3
from common.combined_classes import TOPIC_GROUPS
5
LIKE_ANIMALS_REQUESTS = ["Do you like animals?"]
6
HAVE_PETS_REQUESTS = ["Do you have pets?"]
8
OFFER_TALK_ABOUT_ANIMALS = [
9
"Would you like to talk about animals?",
10
"Let's chat about animals. Do you agree?",
11
"I'd like to talk about animals, would you?",
12
"I think that pets are a great source of entertainment. Do you have pets at home?",
13
"We all know that pets are remarkable for their capacity to love. Do you have pets " "at home?",
16
TRIGGER_PHRASES = LIKE_ANIMALS_REQUESTS + HAVE_PETS_REQUESTS + OFFER_TALK_ABOUT_ANIMALS
19
def skill_trigger_phrases():
20
return TRIGGER_PHRASES
23
def animals_skill_was_proposed(prev_bot_utt):
24
return any([phrase.lower() in prev_bot_utt.get("text", "").lower() for phrase in TRIGGER_PHRASES])
27
ANIMALS_TEMPLATE = re.compile(r"(animal|\bpet\b|\bpets\b)", re.IGNORECASE)
28
ANIMAL_MENTION_TEMPLATE = re.compile(r"animal", re.IGNORECASE)
29
PETS_TEMPLATE = re.compile(
30
r"(\bcat\b|\bcats\b|\bdog\b|\bdogs\b|horse|puppy|puppies|kitty|kitties|kitten|parrot|"
31
r"\brat\b|\brats\b|mouse|hamster|fish\b)",
34
PETS_TEMPLATE_EXT = re.compile(
35
r"(\bcat\b|\bcats\b|\bdog\b|\bdogs\b|horse|puppy|puppies|kitty|kitties|kitten|parrot|"
36
r"\brat\b|\brats\b|mouse|hamster|fish\b|bird)",
39
ANIMALS_FIND_TEMPLATE = re.compile(
40
r"(animal|\bpet\b|\bpets|\bcat\b|\bcats\b|\bdog\b|\bdogs\b|horse|puppy|puppies|"
41
r"kitty|kitties|kitten|parrot|\brat\b|\brats\b|mouse|hamster|fish(es)?\b)",
44
HAVE_LIKE_PETS_TEMPLATE = re.compile(
45
r"(do|did|have) you (have |had |like )?(any |a )?(pets|pet|animals|animal)", re.IGNORECASE
47
HAVE_PETS_TEMPLATE = re.compile(r"(do|did|have) you (have |had )?(any |a )?(pets|pet|animals|animal)", re.IGNORECASE)
48
LIKE_PETS_TEMPLATE = re.compile(r"(do|did|have) you (like |love )?(any |a )?(pets|pet|animals|animal)", re.IGNORECASE)
49
DONT_LIKE = re.compile(r"(do not like|don't like|dont like|hate)", re.IGNORECASE)
50
DO_YOU_HAVE_TEMPLATE = re.compile(
51
r"do you have (a |an |the |any |some )?(cat|dog|puppy|kitty|kitten|rat|fish|parrot" r"|hamster|\bpet|\bpets)",
54
NOT_SWITCH_TEMPLATE = re.compile(r"(hot dog|doja cat)", re.IGNORECASE)
55
ANIMAL_BADLIST = {"animal", "animals"}
57
breed_replace_dict = {"lab": "labrador"}
58
pet_games = {"dog": ["frisbee", "hide and seek"], "cat": ["run and fetch"]}
59
nounphr_from_questions = [
82
"Sorry, I have forgot about this, I have a bad memory. Let's continue our chat about pets.",
83
"Sorry, I forgot the answer, but I would like to tell you more about pets.",
84
"Oh, it's not my lucky day, I can't come up with the answer.",
85
"Yesterday my neighbour was playing soccer and the ball hit my head, so today i'm a little dumb.",
88
re_tokenizer = re.compile(r"[\w']+|[^\w ]")
91
def check_about_animals(user_uttr):
92
found_topics = utils.get_topics(user_uttr, probs=False, which="all")
93
if any([animal_topic in found_topics for animal_topic in TOPIC_GROUPS["animals"]]):
95
elif re.findall(ANIMALS_FIND_TEMPLATE, user_uttr["text"]):
101
def mentioned_animal(annotations):
103
conceptnet = utils.get_comet_conceptnet_annotations({"annotations": annotations})
104
for elem, triplets in conceptnet.items():
105
if "SymbolOf" in triplets:
106
objects = triplets["SymbolOf"]
107
if "animal" in objects:
112
def find_entity_by_types(annotations, types_to_find):
114
wp_output = annotations.get("wiki_parser", {})
115
types_to_find = set(types_to_find)
116
if isinstance(wp_output, dict):
117
entities_info = wp_output.get("animals_skill_entities_info", {})
118
for entity, triplets in entities_info.items():
120
triplets.get("types", [])
121
+ triplets.get("instance of", [])
122
+ triplets.get("subclass of", [])
123
+ triplets.get("types_2_hop", [])
125
type_ids = [elem for elem, label in types]
126
inters = set(type_ids).intersection(types_to_find)
128
found_entity_wp = entity
130
return found_entity_wp
133
def find_entity_conceptnet(annotations, types_to_find):
134
conceptnet = utils.get_comet_conceptnet_annotations({"annotations": annotations})
135
for elem, triplets in conceptnet.items():
136
if "SymbolOf" in triplets:
137
objects = triplets["SymbolOf"]
138
if set(types_to_find).intersection(objects):
144
def stop_about_animals(user_uttr, shared_memory):
146
annotations = user_uttr["annotations"]
147
cobot_entities = annotations.get("cobot_entities", {}).get("entities", [])
148
found_nounphr_for_questions = False
149
for entity in cobot_entities:
150
entity_tokens = set(re.findall(re_tokenizer, entity))
151
for nounphr in nounphr_from_questions:
152
nounphr_tokens = set(re.findall(re_tokenizer, nounphr))
153
if entity_tokens.intersection(nounphr_tokens):
154
found_nounphr_for_questions = True
156
if found_nounphr_for_questions:
158
my_pet_name = shared_memory.get("my_pet_name", "").lower()
159
user_pet_name = shared_memory.get("users_pet_name", "").lower()
160
name_in_entities = my_pet_name in cobot_entities or user_pet_name in cobot_entities
161
found_animal_substr = re.findall(ANIMALS_FIND_TEMPLATE, user_uttr["text"])
162
is_stop = re.findall(r"(stop|shut|something else|change|don't want)", user_uttr["text"])
163
found_animal_wp = find_entity_by_types(annotations, {"Q55983715", "Q16521", "Q43577", "Q39367", "Q38547"})
164
isq = universal_templates.is_any_question_sentence_in_utterance(user_uttr)
165
user_ask = re.findall(r"ask (you )?(a )?question", user_uttr["text"], re.IGNORECASE)
166
dont_like = re.findall(universal_templates.NOT_LIKE_PATTERN, user_uttr["text"])
171
and not name_in_entities
172
and not found_animal_substr
173
and not found_animal_wp
174
and not found_nounphr_for_questions
184
COLORS_TEMPLATE = re.compile(r"(black|white|yellow|blue|green|brown|orange|spotted|striped)", re.IGNORECASE)
187
"I like squirrels. I admire how skillfully they can climb up trees. "
188
"When I walk in the park, sometimes I feed squirrels.",
189
"I like mountain goats. "
190
"I saw a video on Youtube where a goat was climbing up a sheer cliff and they did not fall down.",
191
"I like elephants. When I was in India, I rode an elephant.",
192
"I like foxes. Foxes are intriguing animals, known for their intelligence, playfulness, and lithe athleticism.",
193
"I like wolves. They are related to dogs. I love how they vary in fur color. I love how packs work together.",
194
"I like eagles. Bald eagle is the symbol of America. A bald eagle has Superman-like vision.",
201
"breed": "German Shepherd",
202
"sentence": "I have a dog named Jack. He is a German Shepherd. He is very cute.",
208
"sentence": "I have a dog named Charlie. He is a Husky. He is very cute.",
214
"sentence": "I have a dog named Archie. He is a Labrador. He is very cute.",
219
"breed": "Norwegian Forest cat",
220
"sentence": "I have a cat named Thomas. He is a big fluffy Norwegian Forest cat.",
222
{"pet": "cat", "name": "Jackie", "breed": "Persian", "sentence": "I have a cat named Jackie. He is a Persian."},
223
{"pet": "cat", "name": "Prince", "breed": "Siamese", "sentence": "I have a cat named Prince. He is a Siamese."},
228
"Cats are a great choice of pet.",
229
"Cats have long been one of the more popular companion animals, constantly battling dogs "
230
"for the number one spot.",
232
"dog": ["Dogs are a great choice of pet.", "It is almost impossible to feel lonely when your dog is by your side."],
239
"statement": "Sometimes when I'm working on my laptop, my cat sits on my keyboard.",
240
"question": "Do you think it's annoying or maybe funny?",
244
"statement": "My cat meows only when he is hungry but my dog barks very often.",
245
"question": "Do you agree that cats are quiet pets?",
249
"statement": "My cat and my dog are good friends but my dog does not like other cats.",
250
"question": "What is your opinion, should a dog like all cats?",
254
"statement": "My cat also likes playing on my tablet pc. You know, there are games for "
255
"Android or Ipad with catching fish on screen and my cat slides his paws on the "
256
"screen to catch fish.",
257
"question": "Do you think that pets can use gadgets the same way as humans?",
259
{"ack": "", "statement": "", "question": "Do you think I should create an Instagram account for my cat?"},
262
"statement": "My cat does not let mice and rats go into my home.",
263
"question": "Did you know that mice feel the smell of a cat and are afraid to approach the cat?",
267
"statement": "Yesterday I played with my cat a game, i placed treat in hard-to-reach spot "
268
"in my home and my cat retrieved it using his smell.",
269
"question": "Do you think that cats have a good smell?",
275
"statement": "I walk with my dog every morning.",
276
"question": "Do you think that having a dog help to stay active?",
280
"statement": "My dog knows many tricks, for example a high five. I hold my palm out and as "
281
"the dog hits my palm, give the command high five. My dog raises his paw and "
282
"touches my open palm.",
283
"question": "Do you think my dog is very smart?",
287
"statement": "When I go swimming in the lake, my dog swims with me.",
288
"question": "Do you like swimming?",
292
"statement": "When an unfamiliar man comes into my house, my dog barks at him, and when I "
293
"tell him stop he stops barking.",
294
"question": "Do you think that a dog should bark at strangers or maybe bite them?",
298
"statement": "When I look at my dog and yawn, sometimes my dog yawns too.",
299
"question": "Is it funny?",
303
"statement": "My dog likes to eat meat bones.",
304
"question": "What do you think is better for feeding a dog — royal canin food or natural food?",
308
"statement": "My dog likes to play with my robot vacuum cleaner.",
309
"question": "Do you agree that a robot cleaner is also a pet?",
313
"statement": "Playing with my dog is a lot of fun, I throw a tennis ball and he bounces off "
321
{"what": "name", "keywords": ["name", "call"], "attr": "users_pet_name"},
322
{"what": "breed", "keywords": ["breed"], "attr": "users_pet_breed"},
323
{"what": "play", "keywords": ["play"], "attr": ""},
324
{"what": "like", "keywords": ["like", "love"], "attr": ""},
325
{"what": "videos", "keywords": ["videos"], "attr": ""},
326
{"what": "pandemic", "keywords": ["pandemic", "virus"], "attr": ""},
330
{"ack": "", "statement": "I like {} very much.", "question": "Have you seen {} in wildlife?"},
331
{"ack": "", "statement": "I like watching {} in the zoo.", "question": "Would you like to have pet {}?"},
334
"statement": "I saw interesting TV programs about {} on the channel Animal Planet.",
335
"question": "Do you like to watch Discovery Channel?",
340
"distribution": "Would you like to know where {} live?",
341
"behavior": "I would like to tell you about behavior of {}, okay?",
342
"behaviour": "I would like to tell you about behavior of {}, okay?",
343
"cultural": "Do you want to hear about {} in popular culture?",
344
"culture": "Do you want to hear about {} in popular culture?",
345
"relationship with humans": "Would you like to hear about relationship of {} with humans?",
349
"Would you like to know more about {}?",
350
"Do you want to hear more about {}?",
351
"Should I continue?",
352
"Do you want more details?",
353
"What is your opinion?",