Beispiel #1
0
def get_sentiment_info(text):
    flag, confidence = classify2(text)
    if confidence > 0.5:
        sentiment = "Positive" if flag else "Negative"
    else:
        sentiment = "Neutral"
    conf = "%.4f" % percentage_confidence(confidence)
    return (sentiment, conf)
def get_sentiment_info(text):
    flag, confidence = classify2(text, pos, neg, totals)
    if confidence > 0.5:
        sentiment = "positive" if flag else "negative"
    else:
        sentiment = "neutral"
    conf = "%.4f" % percentage_confidence(confidence)
    return sentiment, conf
Beispiel #3
0
def get_sentiment_info(text):
	flag, confidence = classify2(text)
	if confidence > 0.5:
		sentiment = "Positive" if flag else "Negative"
	else:
		sentiment = "Neutral"
	conf = "%.4f" % percentage_confidence(confidence)
	return (sentiment, conf)
Beispiel #4
0
def get_sentiment_info(text):
	flag, confidence, pos_score, neg_score = classify2(text)
	print "positive score: = %.9f" % pos_score
	print "negative score: = %.9f" % neg_score

	sentiment = "Empty"
	score = 0
	if confidence > 0.5:
		if flag: 
			sentiment = "Positive" 
			score = e**pos_score / (1+e**pos_score)
		else: 
			sentiment = "Negative"
			score = e**neg_score / -(1+e**neg_score)
	else:
		sentiment = "Neutral"
		score = 0
  
	conf = "%.4f" % percentage_confidence(confidence)
	return (sentiment, conf, score)
Beispiel #5
0
	except requests.exceptions.ConnectionError as e:
		response = False
	print "fakhir2", response
	if response and response.status_code == 200:
		res_dict = json.loads(response.content)
		print res_dict
		try:
			print res_dict['probability']
			print res_dict['probability'][res_dict['label']]
			conf = "%.4f" % percentage_confidence(res_dict['probability'][res_dict['label']])
			sentiment = sentiment_dict[res_dict['label']]
		except Exception, e:
			print e
	else:
		#  If the api do not respond 200, this part will work
		flag, confidence = classify2(text)
		if confidence > 0.5:
			sentiment = "Positive" if flag else "Negative"
		else:
			sentiment = "Neutral"
		conf = "%.4f" % percentage_confidence(confidence)
	return (sentiment, conf)

@app.route('/')
def home():
	#conn.incr(STATS_KEY + "_hits")
	return render_template("index.html")

@app.route('/api/text/', methods=["POST"])
@crossdomain(origin='*')
def read_api():
        response = False
    print "fakhir2", response
    if response and response.status_code == 200:
        res_dict = json.loads(response.content)
        print res_dict
        try:
            print res_dict['probability']
            print res_dict['probability'][res_dict['label']]
            conf = "%.4f" % percentage_confidence(
                res_dict['probability'][res_dict['label']])
            sentiment = sentiment_dict[res_dict['label']]
        except Exception, e:
            print e
    else:
        #  If the api do not respond 200, this part will work
        flag, confidence = classify2(text)
        if confidence > 0.5:
            sentiment = "Positive" if flag else "Negative"
        else:
            sentiment = "Neutral"
        conf = "%.4f" % percentage_confidence(confidence)
    return (sentiment, conf)


@app.route('/')
def home():
    #conn.incr(STATS_KEY + "_hits")
    return render_template("index.html")


@app.route('/api/text/', methods=["POST"])