-
Notifications
You must be signed in to change notification settings - Fork 248
/
email_responses.py
146 lines (110 loc) · 6.79 KB
/
email_responses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
Function used to construct an intelligent response to a given input message.
Author: Explore Data Science Academy.
Note:
---------------------------------------------------------------------
The contents of this file should be added to a AWS Lambda function
created as part of the EDSA Cloud-Computing Predict.
For further guidance around this process, see the README instruction
file which sits at the root of this repo.
---------------------------------------------------------------------
Description: This function uses the `find_max_sentiment` and `key_phrase_finder`
functions to firstly extract the overwhelming sentiment of a message reported
by AWS Comprehend, and secondly see if the key phrases determined by the service
match with a supplied list of user phrases. Given the sentiment and the boolean
output of the `key_phrase_finder` function, we can then use conditional logic
to craft an intelligent response.
"""
def email_response(name, critical_phrase_list, list_of_extracted_phrases, AWS_Comprehend_Sentiment_Dump):
# Function Constants
SENDER_NAME = 'Place your name here'
# --- Check for the sentiment of the message and find dominant sentiment score ---
Sentiment_finder = find_max_sentiment(AWS_Comprehend_Sentiment_Dump)
overwhelming_sentiment = Sentiment_finder[0]
overwhelming_sentiment_score = Sentiment_finder[1]
# --- Check for article critical phrases ---
Phrase_Matcher_Article = key_phrase_finder(critical_phrase_list, list_of_extracted_phrases)
Matched_Phrases_Article = Phrase_Matcher_Article[0]
Matched_Phrases_Checker_Article = Phrase_Matcher_Article[1]
# --- Check for project phrases ---
Phrase_Matcher_Project = key_phrase_finder(['github', 'git', 'Git',
'GitHub', 'projects',
'portfolio', 'Portfolio'],
list_of_extracted_phrases)
Matched_Phrases_Project = Phrase_Matcher_Project[0]
Matched_Phrases_Checker_Project = Phrase_Matcher_Project[1]
# --- Check for C.V phrases ---
Phrase_Matcher_CV = key_phrase_finder(['C.V', 'resume', 'Curriculum Vitae',
'Resume', 'CV'],
list_of_extracted_phrases)
Matched_Phrases_CV = Phrase_Matcher_CV[0]
Matched_Phrases_Checker_CV = Phrase_Matcher_CV[1]
# --- Generate standard responses ---
# === DO NOT MODIFY THIS TEXT FOR THE PURPOSE OF PREDICT ASSESSMENT ===
Greetings_text = f'Good day {name},'
CV_text = 'I see that you mentioned my C.V in your message. \
I am happy to forward you my C.V in response. \
If you have any other questions or C.V related queries please do get in touch. '
Project_Text = 'The projects I listed on my site only include \
the ones not running in production. I have \
several other projects that might interest you.'
Article_Text = 'In your message you mentioned my blog posts and data science articles. \
I have several other articles published in academic journals. \
Please do let me know if you are interested - I am happy to forward them to you'
Negative_Text = f'I see that you are unhappy in your response. \
Can we please set up a session to discuss why you are not happy, \
be it with the website, my personal projects or anything else. \
\n\nLooking forward to our discussion. \n\nKind Regards, \n\nMy Name'
Neutral_Text = f'Thank you for your email. Let me know if you need any additional information.\
\n\nKind Regards, \n\n{SENDER_NAME}'
Farewell_Text = f'Thank you for your email.\n\nIf there is anything else I can assist \
you with please let me know and I will set up a meeting for us to meet\
in person.\n\nKind Regards, \n\n{SENDER_NAME}'
# =====================================================================
# --- Email Logic ---
if overwhelming_sentiment == 'POSITIVE':
if ((Matched_Phrases_Checker_CV == True) & \
(Matched_Phrases_Checker_Article == True) & \
(Matched_Phrases_Checker_Project == True)):
mytuple = (Greetings_text, CV_text, Article_Text, Project_Text, Farewell_Text)
Text = "\n \n".join(mytuple)
elif ((Matched_Phrases_Checker_CV == True) & \
(Matched_Phrases_Checker_Article == False) & \
(Matched_Phrases_Checker_Project == True)):
mytuple = (Greetings_text, CV_text, Project_Text, Farewell_Text)
Text = "\n \n".join(mytuple)
elif ((Matched_Phrases_Checker_CV == True) & \
(Matched_Phrases_Checker_Article == False) & \
(Matched_Phrases_Checker_Project == False)):
mytuple = (Greetings_text, CV_text, Farewell_Text)
Text = "\n \n".join(mytuple)
elif ((Matched_Phrases_Checker_CV == False) & \
(Matched_Phrases_Checker_Article == True) & \
(Matched_Phrases_Checker_Project == False)):
mytuple = (Greetings_text, Article_Text, Farewell_Text)
Text = "\n \n".join(mytuple)
elif ((Matched_Phrases_Checker_CV == False) & \
(Matched_Phrases_Checker_Article == False) & \
(Matched_Phrases_Checker_Project == False)):
mytuple = (Greetings_text, Farewell_Text)
Text = "\n \n".join(mytuple)
elif ((Matched_Phrases_Checker_CV == False) & \
(Matched_Phrases_Checker_Article == False) & \
(Matched_Phrases_Checker_Project == True)):
mytuple = (Greetings_text, Project_Text ,Farewell_Text)
Text = "\n \n".join(mytuple)
elif ((Matched_Phrases_Checker_CV == True) & \
(Matched_Phrases_Checker_Article == True) & \
(Matched_Phrases_Checker_Project == False)):
mytuple = (Greetings_text, CV_text, Article_Text, Farewell_Text)
Text = "\n \n".join(mytuple)
else:
mytuple = (Greetings_text, Project_Text, Article_Text, Farewell_Text)
Text = "\n \n".join(mytuple)
elif overwhelming_sentiment == 'NEGATIVE':
mytuple = (Greetings_text, Negative_Text)
Text = "\n \n".join(mytuple)
else:
mytuple = (Greetings_text, Neutral_Text)
Text = "\n \n".join(mytuple)
return Text