Skip to content

Commit

Permalink
NLTK code for sentiments analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalber committed Jun 7, 2017
1 parent 9d70412 commit e388067
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
36 changes: 36 additions & 0 deletions python/AnalyseNLTKBySentences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask import request
from flask import Flask, jsonify
from nltk.sentiment.vader import SentimentIntensityAnalyzer

app = Flask(__name__)

'''array = '{"sentences": ["apple", "banana", "orange"]}'''

@app.route('/sentiments', methods=['POST'])
def create_task():
tasks = []
for sentence in request.json['sentences'] :
sid = SentimentIntensityAnalyzer()
polarity ="none"
ss = sid.polarity_scores(sentence)
sent=max(ss['neg'],ss['pos'],ss['neu'])

if sent==ss['neg']:
polarity ="negative";

elif sent==ss['pos']:
polarity ="positive";

else :
polarity ="neutral";

task = {'sentence': sentence,'polarity':polarity }




tasks.append(task)
return jsonify({'tasks': tasks}), 200

if __name__ == '__main__':
app.run(debug=True)
34 changes: 34 additions & 0 deletions python/desktop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from flask import Flask

app = Flask(__name__)

@app.route('/<content>')
def getAnalyseByNltk( content ):
sid = SentimentIntensityAnalyzer()


ss = sid.polarity_scores(content)
sent=max(ss['neg'],ss['pos'],ss['neu'])

if sent==ss['neg']:
return "negative";

elif sent==ss['pos']:
return "positive";

else :
return "neutral";


'''@app.route('/<user_id>/<username>')
def show(user_id, username='Anonymous'):
return user_id + ':' + username'''
# Now you can call getAnalyseByNltk function
#getAnalyseByNltk(content="I want to travel")


if __name__ == '__main__':
app.run(debug=True,port=8000)


0 comments on commit e388067

Please sign in to comment.