-
Notifications
You must be signed in to change notification settings - Fork 1
/
sentiment_analysis.py
68 lines (59 loc) · 2.21 KB
/
sentiment_analysis.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
import nltk
from nltk import *
from nltk.corpus import wordnet
from nltk import PorterStemmer
#from nltk.sentiment import SentimentIntensityAnalyzer
# TODO: Vader Shit
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import config
class sentiment_analysis():
def test_vader(self):
analyzer = SentimentIntensityAnalyzer()
for sentence in sentences:
vs = analyzer.polarity_scores(sentence)
print("{:-<65} {}".format(sentence, str(vs)))
def getSubmissions(self, assignmentID):
assignment = config.COURSE.get_assignment(assignmentID)
users = config.COURSE.get_users(enrollment_type=['student'])
for user in users:
peer_reviews = assignment.get_submission(user).get_submission_peer_reviews(include='submission_comments')
num_reviews = 0
compound_sum = 0
for peer_review in peer_reviews:
if peer_review.workflow_state == 'completed':
comments = peer_review.submission_comments
for comment in comments:
compound_sum = compound_sum + self.analyze(comment['comment'])
num_reviews = num_reviews + 1
else:
print('Peer Review not completed')
if (num_reviews != 0):
average_compound = compound_sum / num_reviews
grade_1 = self.grade(average_compound)
else:
grade_1 = 0
x = assignment.get_submission(user).edit(submission = {
'posted_grade':grade_1})
def analyze(self, text):
sia = SentimentIntensityAnalyzer()
y = text.split('.')
z = 0
w = 0
for sentence in y:
print(sentence)
z = z + 1
x = sia.polarity_scores(sentence)
w = w + x['compound']
print(x)
result = w/z
if (result<-0.05):
print("Someone got a bad review :(")
print(text)
return result
def grade(self, average_compound):
if average_compound > 0.05:
return 10
elif average_compound < -0.05:
return 1
else:
return 4