diff --git a/python/AnalyseNLTKBySentences.py b/python/AnalyseNLTKBySentences.py new file mode 100644 index 0000000..a36a680 --- /dev/null +++ b/python/AnalyseNLTKBySentences.py @@ -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) \ No newline at end of file diff --git a/python/desktop.py b/python/desktop.py new file mode 100644 index 0000000..6d89475 --- /dev/null +++ b/python/desktop.py @@ -0,0 +1,34 @@ +from nltk.sentiment.vader import SentimentIntensityAnalyzer +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +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('//') +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) + +