-
Notifications
You must be signed in to change notification settings - Fork 1
/
polarity_textblob.py
53 lines (47 loc) · 1.63 KB
/
polarity_textblob.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
#!/usr/bin/python3
# Polarity Detection of Normalised Text
# Created by Team Axenhammer, https://github.com/Axenhammer
# Licensed as MIT
import re, os, shutil, sys
from textblob import TextBlob
def main(Input_String):
num = 0
# For Splitting Paragraphs into List of Sentences
output = []
products = Input_String.split(".")
postive = 0
negative = 0
#print("Polarity ranges from (-1 -> 1)")
for product in products:
arr = []
product = product.strip()
if (product != ""):
blob = TextBlob(product)
Polarity = float(blob.sentiment.polarity)
arr.append(Polarity)
#print("\"" + product + "\" -> ", Polarity)
if (Polarity > 0):
if (Polarity < 0.5):
# print("Emotion: Mildly Positive")
emo = "Emotion: Mildly Positive"
else:
# print("Emotion: Strongly Positive")
emo = "Emotion: Strongly Positive"
elif (Polarity < 0):
Polarity = (-1)*Polarity
if (Polarity < 0.5):
# print("Emotion: Mildly Negative")
emo = "Emotion: Mildly Negative"
else:
# print("Emotion: Strongly Negative")
emo = "Emotion: Strongly Negative"
else:
#print("Emotion: Impassive")
emo = "Emotion: Impassive"
arr.append(emo)
output.append(arr)
num += 1
return output
if __name__ == '__main__':
Input_String = sys.argv[1]
main(Input_String)