-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|