-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailSentiment.py
85 lines (66 loc) · 2.13 KB
/
emailSentiment.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
import datetime
class EmailSentiment:
def __init__(self, email_db = None):
if email_db is not None:
self._sender = email_db.sender
self._subject = email_db.subject
self._received = email_db.received_date
self._score = email_db.score
self._language = email_db.language
self._magnitude = email_db.magnitude
self._sentences = []
sorted_sentences = sorted(email_db.sentences, key=lambda sentence: sentence.position)
for sentence in sorted_sentences:
self._sentences.append(Sentence(sentence.text, sentence.sentiment, sentence.magnitude, sentence.id))
@property
def sender(self):
return self._sender
@sender.setter
def sender(self, value):
self._sender = value
@property
def subject(self):
return self._subject
@subject.setter
def subject(self, value):
self._subject = value
@property
def received(self):
return self._received
@received.setter
def received(self, value):
self._received = value
@property
def score(self):
return self._score
@score.setter
def score(self, value):
self._score = value
@property
def language(self):
return self._language
@language.setter
def language(self, value):
self._language = value
@property
def magnitude(self):
return self._magnitude
@score.setter
def magnitude(self, value):
self._magnitude = value
@property
def sentences(self):
return self._sentences
@sentences.setter
def sentences(self, value):
self._sentences = value
def sentences_from_google_nlp(self, google_sentences):
self._sentences = []
for sentence in google_sentences:
self._sentences.append(Sentence(sentence.text.content, sentence.sentiment.score, sentence.sentiment.magnitude))
class Sentence():
def __init__(self, text, sentiment, magnitude, id = None):
self.text = text
self.sentiment = sentiment
self.magnitude = magnitude
self.id = id