-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.py
48 lines (35 loc) · 1001 Bytes
/
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
from textblob import TextBlob
_polarity_low=-0.5
_polarity_high=0.5
_subjectivity_low=0.25
#vague data
_subjectivity_high=0.75
#very descriptive data
def analysisInfo(line):
tb=TextBlob(line)
polarity=tb.sentiment.polarity
subjectivity=tb.sentiment.subjectivity
print('polarity =', polarity, end='\t')
if polarity<=_polarity_low:
print('Negative view')
elif polarity<_polarity_high:
print('Neutral view')
else:
print('Positive view')
print('subj =',subjectivity, end='\t')
if subjectivity<=_subjectivity_low:
print('vague data')
elif subjectivity<_subjectivity_high:
print('normal description')
else:
print('descriptive data')
def main():
file=open('news.txt', 'r')
line=file.read()
print(line)
tb=TextBlob(line)
#print(tb.sentiment)
print('polarity =',tb.sentiment.polarity)
print('subj =',tb.sentiment.subjectivity)
if __name__=='__main__':
main()