2
from random import choice
4
from common.fact_retrieval import topic_types
5
from common.combined_classes import TOPIC_GROUPS
6
from common import utils
9
MOVIE_SKILL_CHECK_PHRASE = "the recent movie"
12
SWITCH_MOVIE_SKILL_PHRASE = (
13
f"Great idea! " f"I watch a lot of movies online. " f"What is {MOVIE_SKILL_CHECK_PHRASE} you've watched?"
17
MOVIE_COMPILED_PATTERN = re.compile(
18
r"(movie|film|picture|series|tv[ -]?show|reality[ -]?show|netflix|\btv\b|"
19
r"comedy|comedies|thriller|animation|anime|talk[ -]?show|cartoon|drama|"
20
r"fantasy|watch\b|watching\b|watched\b|youtube|\byou tube\b)",
23
RECOMMEND_REQUEST_PATTERN = re.compile(
24
r"(recommend|advice|suggest)( me)?[a-z0-9 ]+"
25
r"(movie|series|\bshow\b|\btv\b|\bcomed|\bthriller|animation|cartoon|drama|\bfantas|\bwatch)",
28
RECOMMEND_OFFER_PATTERN = re.compile(
29
r"(\bi\b|\bme\b)( to)? (recommend|advice) you[a-z0-9 ]+"
30
r"(movie|series|\bshow\b|\btv\b|\bcomed|\bthriller|animation|cartoon|drama|\bfantas|\bwatch)",
33
NOT_LIKE_NOT_WATCH_MOVIES_TEMPLATE = re.compile(
34
r"(don't|do not|not) (watch|watching|like) (movie|film|picture|series|"
35
r"tv[ -]?show|reality[ -]?show|netflix|\btv\b|comedy|comedies|thriller|"
36
r"animation|anime|talk[ -]?show|cartoon)",
40
NOT_WATCHED_TEMPLATE = re.compile(r"(have|'ve|did|was|had|were)? ?(never|not|n't) (seen|watch)", re.IGNORECASE)
42
RECOMMEND_OFFER_RESPONSE = [
43
"Would you like me to recommend you a MOVIE?",
44
"May I recommend you a MOVIE?",
45
"Can I recommend you a MOVIE?",
47
RECOMMENDATION_PHRASES = [
48
"I encourage you to watch MOVIE released in YEAR. It has RATING rating for NUM_VOTES votes. Have you seen it?",
49
"I urge you to go and watch MOVIE released in YEAR. It has RATING rating for NUM_VOTES votes. Have you seen it?",
50
"I highly commend you to watch MOVIE released in YEAR, with RATING rating for NUM_VOTES votes. Have you seen it?",
52
REPEAT_RECOMMENDATION_PHRASES = ["Okay. Then don't forget: MOVIE released in YEAR."]
53
WOULD_YOU_LIKE_TO_CONTINUE_TALK_ABOUT_MOVIES = [
54
"Would you like to continue our conversation about movies?",
55
"Would you like to continue to chat about movies?",
56
"Do you want to continue to talk about movies?",
60
ABOUT_MOVIE_TITLES_PHRASES = [
61
# "What is the name of the last movie you watched?",
62
"What is the best movie you have seen recently?",
63
# "What is the funniest movie you have ever seen?",
64
"What movie you could watch over and over again?",
65
# "What is the most romantic movie you have ever seen?",
66
# "What is the scariest movie you have ever seen?",
67
"What is your favorite TV series?",
68
# "What TV show are you watching these days?",
69
"What TV series did you watch on weekends?",
70
# "What TV show do you watch when you need to escape the real world?",
71
"What movie did you watch on weekends?",
74
WHAT_IS_YOUR_FAVORITE_MOMENT_PHRASES = [
75
"Do you remember how 'MOMENT'? Did you like this movie moment?",
76
"Remember how 'MOMENT'? I suppose, you like this moment?",
77
"Do you think that when 'MOMENT' was one of the most impressive moments?",
80
WHAT_IS_YOUR_FAVORITE_MOMENT_NO_PLOT_FOUND_PHRASES = [
81
"Did you like how characters developed through?",
82
"Do you think the background of the filming made a significant contribution to the picture?",
83
"Did you like the soundtrack?",
86
WHAT_OTHER_MOVIE_TO_DISCUSS = "What other movie you'd like to discuss?"
87
CLARIFY_WHAT_MOVIE_TO_DISCUSS = "Can you say again what movie you'd like to discuss?"
88
CELEB_ACTOR_PHRASES = ["What is your favourite movie with this actor?"]
89
WHAT_MOVIE_RECOMMEND = "What movie can you recommend to your friends?"
92
def skill_trigger_phrases():
93
return [SWITCH_MOVIE_SKILL_PHRASE] + ABOUT_MOVIE_TITLES_PHRASES + [WHAT_MOVIE_RECOMMEND]
96
ABOUT_MOVIE_PERSONS_PHRASES = [
97
"What movie star would you most like to meet?",
98
"Who is your favorite actor or actress?",
99
"Who is your favorite director?",
100
"Which famous person would you like to have for a best friend?",
103
PRAISE_ACTOR_TEMPLATES = [
104
"The performance of {name} was outstanding!",
105
"{name}'s acting was so subtle!",
106
"The acting of {name} was exceptionally good!",
107
"I was so impressed by {name}'s performance!",
111
PRAISE_VOICE_ACTOR_TEMPLATES = [
112
"I love {name}'s voice! Great performance.",
113
"I reckon {name} is great in voicing!",
117
TRY_PRAISE_DIRECTOR_OR_WRITER_OR_VISUALS = {
118
"director": "I think the director {director} achieved a perfect chemistry between characters.",
119
"writer": "In my humble opinion the writer {writer} did a brilliant job creating such an intricate plot.",
120
"visuals": "I was particularly impressed by visual part of the movie.",
123
DIFFERENT_SCRIPT_TEMPLATES = {
124
"never_heard_about_template": [
125
"I've never heard about SUBJECT before.",
126
"I've never heard about SUBJECT previously.",
128
"opinion_request_about_movie": [
129
"What do you think about this TYPE?",
130
"What is your view on this TYPE?",
131
"What is your opinion on this TYPE?",
133
"heard_about_template": [
134
"Yeah, I've heard about SUBJECT,",
135
"Yeah, I know SUBJECT,",
136
"I've got what you are talking about.",
138
"clarification_template": [
139
"Did I get correctly that you are talking about",
140
"Am I right in thinking that you are talking about",
141
"Did I get correctly that you meant",
142
"Am I right in thinking that you meant",
144
"sorry_didnt_get_title": [
145
"Sorry, I could not get what TYPE you are talking about.",
146
"Sorry, I didn't get what TYPE you meant.",
148
"lets_talk_about_other_movie": [
149
"Let's talk about some other movie.",
150
"Maybe you want to talk about some other movie.",
151
"Do you want to discuss some other movie.",
153
"user_opinion_comment": {
154
"positive": ["Cool!", "Great!", "Nice!"],
155
"neutral": ["Okay.", "Well.", "Hmm.."],
156
"negative": ["I see.", "That's okay.", "Okay."],
158
"didnt_get_movie_title_at_all": [
159
"Sorry, I didn't get the title, could you, please, repeat it.",
160
"Sorry, I didn't understand the title, could you, please, repeat it.",
161
"Sorry, I didn't catch the title, could you, please, repeat it.",
162
"Sorry, I didn't get the title, can you, please, repeat it.",
164
"dont_know_movie_title_at_all": [
165
"Sorry, probably I've never heard about this TYPE.",
166
"Sorry, maybe I just have never heard about this TYPE.",
167
"Well, probably I've never heard about this TYPE.",
169
"lets_move_on": ["Let's move on.", "Okay.", "Hmmm.", "Huh.", "Aha.", ""],
170
"can_you_imagine": ["Did you know that", "Can you imagine that", "Have you heard that"],
173
ACKNOWLEDGEMENT_LIKES_MOVIE = [
174
"So cool! I like it too! You have a good eye in movies.",
175
"Great! Seems like you're well versed in movies.",
176
"You've got a pretty sophisticated knowledge of movies.",
177
"I'm glad you like it, it's a really nice film.",
178
"Amazing! Agree with you! You have a excellent eye in movies.",
179
"Wow! I see you're perfectly versed in movies.",
180
"Yeah, it's a really amazing film.",
184
def get_movie_template(category, subcategory=None, movie_type="movie"):
185
if subcategory is not None:
187
choice(DIFFERENT_SCRIPT_TEMPLATES[category].get(subcategory, ""))
188
.replace("TYPE", movie_type)
189
.replace("SUBJECT", choice(["it", f"this {movie_type}"]))
193
choice(DIFFERENT_SCRIPT_TEMPLATES[category])
194
.replace("TYPE", movie_type)
195
.replace("SUBJECT", choice(["it", f"this {movie_type}"]))
199
def praise_actor(name, animation):
200
tmpl = choice(PRAISE_VOICE_ACTOR_TEMPLATES if animation else PRAISE_ACTOR_TEMPLATES)
201
return tmpl.format(name=name)
204
def praise_director_or_writer_or_visuals(director, writer):
207
phrase = TRY_PRAISE_DIRECTOR_OR_WRITER_OR_VISUALS["visuals"]
209
phrase = TRY_PRAISE_DIRECTOR_OR_WRITER_OR_VISUALS["writer"].format(writer=writer)
212
phrase = TRY_PRAISE_DIRECTOR_OR_WRITER_OR_VISUALS["director"].format(director=director)
214
praise_director = choice([True, False])
216
phrase = TRY_PRAISE_DIRECTOR_OR_WRITER_OR_VISUALS["director"].format(director=director)
218
phrase = TRY_PRAISE_DIRECTOR_OR_WRITER_OR_VISUALS["writer"].format(writer=writer)
222
def extract_movies_names_from_annotations(annotated_uttr, check_full_utterance=False):
224
if "entity_detection" in annotated_uttr["annotations"]:
226
entities = utils.get_entities(annotated_uttr, only_named=False, with_labels=True)
228
if ent.get("label", "") == "videoname":
229
movies_titles += [ent["text"]]
231
# for now let's remove full utterance check but add entity_linking usage!
232
if not movies_titles:
233
# either None or empty list
234
if "wiki_parser" in annotated_uttr["annotations"]:
236
for ent_name, ent_dict in annotated_uttr["annotations"]["wiki_parser"].get("entities_info", {}).items():
237
instance_of_types = [el[0] for el in ent_dict.get("instance of", [])]
238
instance_of_types += [el[0] for el in ent_dict.get("types_2hop", [])]
240
len(set(instance_of_types).intersection(set(topic_types["film"]))) > 0
241
and ent_dict.get("token_conf", 0.0) >= 0.5
242
and ent_dict.get("conf", 0.0) >= 0.5
244
movies_titles += [ent_dict.get("entity_label", ent_name).lower()]
246
# if check_full_utterance:
247
# movies_titles += [re.sub(r"[\.\?,!]", "", annotated_uttr["text"]).strip()]
251
def about_movies(annotated_utterance):
252
found_topics = utils.get_topics(annotated_utterance, probs=False, which="all")
253
if any([topic in found_topics for topic in TOPIC_GROUPS["movies"]]):
255
elif re.findall(MOVIE_COMPILED_PATTERN, annotated_utterance["text"]):