Skip to content

Commit 2a45c61

Browse files
committed
Merge pull request #1 from aksh93/master
Sentiment analysis using text-processing.com api
2 parents bf8a182 + 547917b commit 2a45c61

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Sentiment analysis/sentiment.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#label: will be either pos if the text is determined to be positive, neg if the text is negative, or neutral if the text is neither pos nor neg.
2+
#probability: an object that contains the probability for each label. neg and pos will add up to 1, while neutral is standalone. If neutral is greater than 0.5 then the label will be neutral. Otherwise, the label will be pos or neg, whichever has the greater probability.
3+
4+
import json
5+
import requests
6+
7+
url = 'http://text-processing.com/api/sentiment/'
8+
9+
string = raw_input()
10+
11+
analysis_string = {'text': string}
12+
13+
result = requests.post(url, data=analysis_string)
14+
15+
negative_val = result.json()['probability']['neg']
16+
print negative_val
17+
18+
positive_val = result.json()['probability']['pos']
19+
print positive_val
20+
21+
neutral_val = result.json()['probability']['neutral']
22+
print neutral_val
23+
24+
label = result.json()['label']
25+
print label

0 commit comments

Comments
 (0)