1 # -*- coding: utf-8 -*-
4 from flask import request
5 from flask_restful import Resource, abort
6 from textblob import TextBlob
8 input_error_409 = 'Input must be a list of JSON objects. JSON objects must contain contain key text.'
10 class Offline_Analysis(Resource):
12 return "POST a list of JSON objects as content-type: application/json. JSON objects must contain key 'text'.", 405
15 if not request.json or not isinstance(request.json, (list,)):
16 return abort(409, message=input_error_409)
20 if 'text' not in text:
21 return abort(409, message=input_error_409)
22 analysis = TextBlob(text['text'])
23 value += (analysis.sentiment.polarity/2) + 0.5
24 sentiment = value/len(texts)
25 data = {'sentiment': sentiment}